Update helper

This commit is contained in:
Kirigaya Kazuto 2018-06-11 11:45:50 +08:00
parent 767e457a41
commit 518a99a961
2 changed files with 27 additions and 1 deletions

View File

@ -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)
{

View File

@ -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);