mirror of
https://github.com/Kiritow/GSock.git
synced 2024-03-22 13:10:51 +08:00
Update helper
This commit is contained in:
parent
767e457a41
commit
518a99a961
|
@ -55,6 +55,29 @@ int sock_helper::sendall(const void* ptr, int datasz)
|
|||
return sendall(ptr, datasz, x);
|
||||
}
|
||||
|
||||
int sock_helper::recvall(void* ptr, int length_to_recv)
|
||||
{
|
||||
int x;
|
||||
return recvall(ptr, length_to_recv, x);
|
||||
}
|
||||
|
||||
int sock_helper::recvall(void* ptr, int length_to_recv, int& bytes_recv)
|
||||
{
|
||||
int done = 0;
|
||||
while (done < length_to_recv)
|
||||
{
|
||||
int ret = _s.recv(((char*)ptr) + done, length_to_recv - done);
|
||||
if (ret <= 0)
|
||||
{
|
||||
bytes_recv = done;
|
||||
return ret;
|
||||
}
|
||||
done += ret;
|
||||
}
|
||||
bytes_recv = done;
|
||||
return done;
|
||||
}
|
||||
|
||||
int sock_helper::recvuntil(void* buff, int max_length,
|
||||
const std::function<bool()>& cond_fn, int& bytes_recv)
|
||||
{
|
||||
|
@ -180,4 +203,4 @@ int sock_helper::recvline(std::string& out_data, const std::string& separator, b
|
|||
}
|
||||
}
|
||||
return done;
|
||||
}
|
||||
}
|
|
@ -18,6 +18,9 @@ public:
|
|||
int sendall(const void* ptr, int datasz);
|
||||
int sendall(const void* ptr, int datasz, int& bytes_sent);
|
||||
|
||||
int recvall(void* ptr, int length_to_recv);
|
||||
int recvall(void* ptr, int length_to_recv, int& bytes_recv);
|
||||
|
||||
int recvuntil(void* buff, int max_length, const std::function<bool()>& cond_fn);
|
||||
int recvuntil(void* buff, int max_length, const std::function<bool()>& cond_fn, int& bytes_recv);
|
||||
int recvuntil(void* buff, int max_length, const std::function<bool(void*, int)>& cond_fn);
|
||||
|
|
Loading…
Reference in New Issue
Block a user