5 #ifndef HOG_NETIO_H_INCLUDED 6 #define HOG_NETIO_H_INCLUDED 14 #include <sys/types.h> 15 #include <sys/socket.h> 19 #define out std::cout << "[" << hobbes::showDateTime(hobbes::time() / 1000) << "]: " 21 inline void ssend(
int c,
const uint8_t* d,
size_t dsz) {
25 rc = ::send(c, d + o, dsz, 0);
37 throw std::runtime_error(
"error sending on connection: " + std::string(strerror(errno)));
41 inline void ssend(
int c,
const std::string& s) {
43 ssend(c, (
const uint8_t*)&n,
sizeof(n));
44 ssend(c, (
const uint8_t*)s.data(), n);
47 inline void srecv(
int c, uint8_t* d,
size_t dsz) {
51 rc = recv(c, d + o, dsz, 0);
63 throw std::runtime_error(
"error receiving on connection: " + std::string(strerror(errno)));
67 inline void srecv(
int c, std::vector<uint8_t>* d) {
69 srecv(c, (uint8_t*)&sz,
sizeof(sz));
71 srecv(c, &(*d)[0], sz);
74 inline void srecv(
int c, std::string* s) {
76 srecv(c, (uint8_t*)&sz,
sizeof(sz));
78 srecv(c, (uint8_t*)&(*s)[0], sz);
110 if (sz > this->allocsz) {
113 this->data = (uint8_t*)
malloc(psz);
116 printf(
"failed to allocate %d bytes from %d bytes!\n", (
int)psz, (
int)sz);
125 srecv(c, (uint8_t*)&sz,
sizeof(sz));
uint8_t * data
Definition: netio.H:96
buffer()
Definition: netio.H:99
void srecv(int c, uint8_t *d, size_t dsz)
Definition: netio.H:47
Definition: batchrecv.C:20
void reserve(size_t sz)
Definition: netio.H:109
size_t allocsz
Definition: netio.H:95
size_t uptoPow2(size_t x)
Definition: netio.H:81
size_t size
Definition: netio.H:97
~buffer()
Definition: netio.H:105
void ssend(int c, const uint8_t *d, size_t dsz)
Definition: netio.H:21