Skip to content

Commit

Permalink
Socket: better doc readLine() and fix op>>(String) in case of error
Browse files Browse the repository at this point in the history
  • Loading branch information
aslze committed May 25, 2023
1 parent ef879b2 commit 2539b58
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions include/asl/Socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -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(); }
/**
Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit 2539b58

Please sign in to comment.