From 518a99a961677d21182b6ac00d5f55d7f843fbd4 Mon Sep 17 00:00:00 2001 From: Kiritow <1362050620@qq.com> Date: Mon, 11 Jun 2018 11:45:50 +0800 Subject: [PATCH] Update helper --- gsock_helper.cpp | 25 ++++++++++++++++++++++++- gsock_helper.h | 3 +++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/gsock_helper.cpp b/gsock_helper.cpp index 779626d..9c19fa0 100644 --- a/gsock_helper.cpp +++ b/gsock_helper.cpp @@ -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& cond_fn, int& bytes_recv) { @@ -180,4 +203,4 @@ int sock_helper::recvline(std::string& out_data, const std::string& separator, b } } return done; -} \ No newline at end of file +} \ No newline at end of file diff --git a/gsock_helper.h b/gsock_helper.h index 46a6cab..e97803b 100644 --- a/gsock_helper.h +++ b/gsock_helper.h @@ -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& cond_fn); int recvuntil(void* buff, int max_length, const std::function& cond_fn, int& bytes_recv); int recvuntil(void* buff, int max_length, const std::function& cond_fn);