2018-06-07 21:01:40 +08:00
|
|
|
/** General Socket Wrapper
|
|
|
|
* Created By Kiritow. (https://github.com/kiritow)
|
|
|
|
* Licensed under MIT
|
|
|
|
*/
|
|
|
|
|
|
|
|
// GSock Helper
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
#include "gsock.h"
|
|
|
|
#include <functional>
|
2018-06-08 12:02:59 +08:00
|
|
|
#include <string>
|
2018-06-07 21:01:40 +08:00
|
|
|
|
|
|
|
class sock_helper
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
sock_helper(sock&);
|
|
|
|
|
2018-08-26 00:27:37 +08:00
|
|
|
int sendall(const std::string& data);
|
2018-06-07 21:01:40 +08:00
|
|
|
int sendall(const void* ptr, int datasz);
|
|
|
|
int sendall(const void* ptr, int datasz, int& bytes_sent);
|
|
|
|
|
2018-06-11 11:45:50 +08:00
|
|
|
int recvall(void* ptr, int length_to_recv);
|
|
|
|
int recvall(void* ptr, int length_to_recv, int& bytes_recv);
|
|
|
|
|
2018-06-07 21:01:40 +08:00
|
|
|
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);
|
|
|
|
int recvuntil(void* buff, int max_length, const std::function<bool(void*, int)>& cond_fn, int& bytes_recv);
|
2018-06-08 12:02:59 +08:00
|
|
|
|
|
|
|
int sendpack(const void* ptr, int datasz);
|
|
|
|
int sendpack(const std::string& data);
|
|
|
|
int recvpack(std::string& out_data);
|
|
|
|
|
2018-06-16 23:27:47 +08:00
|
|
|
int sendline(const std::string& data, const std::string& seperator="\r\n");
|
2018-06-08 12:02:59 +08:00
|
|
|
int recvline(std::string& out_data, const std::string& separator="\r\n", bool keep_sep = false);
|
2018-06-07 21:01:40 +08:00
|
|
|
private:
|
|
|
|
sock & _s;
|
|
|
|
};
|