54 throw NoConnection(
"No Socket",
HERE);
55 if (
_buffer.size() >= 2 && !size)
57 size = (
unsigned char)
_buffer[0] * 256 + (
unsigned char)
_buffer[1];
60 if (size &&
_buffer.size() >= size)
68 memset(chr, 0, MAXPKTSIZE);
70 res = recv(socket, chr, MAXPKTSIZE, 0);
72 res = recv(socket, chr, MAXPKTSIZE, MSG_TRUNC);
75 throw ConnectionClosed(
"Connection Closed",
HERE);
77 _buffer += std::string(chr, res);
81 size = (
unsigned char)
_buffer[0] * 256 + (
unsigned char)
_buffer[1];
84 if (
_buffer.size() > size - str.size())
86 str +=
_buffer.substr(0, size - str.size());
88 _buffer.size() - size - str.size());
95 if (str.size() >= size)
103 unsigned int pkg_size)
105 char chr[MAXPKTSIZE];
106 std::string str =
"";
108 struct sockaddr_in addr;
110 struct sockaddr_in6 addr6;
125 size =
sizeof(addr6);
128 throw NoConnection(
"No Socket",
HERE);
129 if (
_buffer.size() >= 2 && !pkg_size)
131 pkg_size = (
unsigned char)
_buffer[0] * 256 + (
unsigned char)
_buffer[1];
134 if (pkg_size &&
_buffer.size() >= pkg_size)
136 str =
_buffer.substr(0, pkg_size);
145 int flags = MSG_TRUNC;
150 res = recvfrom(socket, chr, MAXPKTSIZE, flags,
151 (
struct sockaddr *) &addr, &size);
154 res = recvfrom(socket, chr, MAXPKTSIZE, flags,
155 (
struct sockaddr *) &addr6, &size);
158 throw ConnectionClosed(
"Connection Closed",
HERE);
160 _buffer += std::string(chr, res).substr(0, res);
164 pkg_size = (
unsigned char)
_buffer[0] * 256 +
168 if (
_buffer.size() > pkg_size - str.size())
170 str +=
_buffer.substr(0, pkg_size - str.size());
172 _buffer.size() - pkg_size - str.size());
179 if (str.size() >= pkg_size)
186 host = std::string(inet_ntoa(addr.sin_addr));
187 port = ntohs(addr.sin_port);
192 char buf[INET6_ADDRSTRLEN];
193 if (inet_ntop(AF_INET6, &addr6.sin6_addr, buf, INET6_ADDRSTRLEN) == 0)
194 throw InetntopError(
"Not a valid address",
HERE);
195 host = std::string(buf);
196 port = ntohs(addr6.sin6_port);
std::string _read_line_bin(int socket, int &port, std::string &host, unsigned int pkg_size)
Get a line from socket and store client hostname and port in port and host variable (when used with b...