From 2539b5852ce5b5a42ee25b52ce69b6395b7f436f Mon Sep 17 00:00:00 2001 From: Alvaro Date: Thu, 25 May 2023 22:40:44 +0200 Subject: [PATCH] Socket: better doc readLine() and fix op>>(String) in case of error --- include/asl/Socket.h | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/include/asl/Socket.h b/include/asl/Socket.h index c5bda32..95266cf 100644 --- a/include/asl/Socket.h +++ b/include/asl/Socket.h @@ -211,7 +211,7 @@ class ASL_API Socket : public SmartObject */ void close() { _()->close(); } /** - Reads a line of text from the socket (keep in mind this is not buffered) + Reads a line of text from the socket (keep in mind this is not buffered, can be a bit inefficient, and there is a length limit of 8000 bytes) */ String readLine() { return _()->readLine(); } /** @@ -326,13 +326,17 @@ class ASL_API Socket : public SmartObject return *this; } + /** + Reads a string from the socket that is preceded by its length as an int32 (the sender must send the byte length before) + */ Socket& operator>>(String& x) { int n; *this >> n; x.resize(n); x[n] = '\0'; - read(&x[0], n); + n = read(&x[0], n); + x.fix(n >= 0 ? n : 0); return *this; }