29 : stream(str), closed(false), stat(0), current_timeout(9999)
32 s = ::socket(AF_INET, SOCK_STREAM, 0);
34 s = ::socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
44 : s(sock), stream(str), closed(false), stat(0), current_timeout(9999)
53 : stream(str), closed(false), stat(0), current_timeout(9999)
56 s = ::socket(AF_INET, SOCK_STREAM, 0);
58 s = ::socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
73 if (closed || s == INVALID_SOCKET)
return INVALID_SOCKET;
80 if (closed || s == INVALID_SOCKET)
return INVALID_SOCKET;
87 if (closed || s == INVALID_SOCKET)
return INVALID_SOCKET;
88 return stat =
::listen(s, max_connections);
94 if (closed || s == INVALID_SOCKET)
return 0;
96 SOCKET conn = INVALID_SOCKET;
100 int asize =
sizeof(a);
104 if (conn != INVALID_SOCKET && asize > 0) {
112 if (conn == INVALID_SOCKET)
115 return new(__FILE__,__LINE__)
NetSock(conn, stream);
123 if (closed || s == INVALID_SOCKET)
return 0;
126 if (::ioctlsocket(s, FIONREAD, &nbytes) == 0)
137 if (closed || s == INVALID_SOCKET)
return INVALID_SOCKET;
144 if (closed || s == INVALID_SOCKET)
return "";
146 static char rbuf[8192];
150 rlen =
::recv(s, rbuf,
sizeof(rbuf), 0);
153 rlen =
::recvfrom(s, rbuf,
sizeof(rbuf), 0, 0, 0);
164 case WSAECONNABORTED:
171 stat = WSAEWOULDBLOCK;
178 else if (rlen == 0) {
182 return Text(rbuf, rlen);
191 if (closed || s == INVALID_SOCKET)
return INVALID_SOCKET;
199 if (closed || s == INVALID_SOCKET)
return "";
201 static char rbuf[4096];
210 rlen =
::recvfrom(s, rbuf,
sizeof(rbuf), 0, 0, 0);
218 else if (rlen == 0) {
222 return Text(rbuf, rlen);
230 if (closed || s == INVALID_SOCKET)
return INVALID_SOCKET;
233 ZeroMemory(&fd,
sizeof(fd));
236 TIMEVAL timeval = {seconds, microseconds};
237 TIMEVAL* timeout = &timeval;
240 return stat =
::select(1, &fd, 0, 0, timeout);
243 return stat =
::select(1, 0, &fd, 0, timeout);
246 return stat =
::select(1, &fd, &fd, 0, timeout);
256 if (closed || s == INVALID_SOCKET)
return 0;
257 if (msecs == current_timeout)
return 1;
261 u_long nonblocking = 1;
262 if (::ioctlsocket(s, FIONBIO, &nonblocking) == SOCKET_ERROR) {
270 if (current_timeout == 0) {
271 u_long nonblocking = 0;
272 if (::ioctlsocket(s, FIONBIO, &nonblocking) == SOCKET_ERROR) {
281 ::setsockopt(s, SOL_SOCKET, SO_RCVTIMEO, (
char*) &maxto,
sizeof(maxto));
282 ::setsockopt(s, SOL_SOCKET, SO_SNDTIMEO, (
char*) &maxto,
sizeof(maxto));
287 ::setsockopt(s, SOL_SOCKET, SO_RCVTIMEO, (
char*) &msecs,
sizeof(msecs));
288 ::setsockopt(s, SOL_SOCKET, SO_SNDTIMEO, (
char*) &msecs,
sizeof(msecs));
292 current_timeout = msecs;
301 if (closed || s == INVALID_SOCKET)
return INVALID_SOCKET;
302 ::shutdown(s, SD_RECEIVE);
311 if (closed || s == INVALID_SOCKET)
return INVALID_SOCKET;
312 ::shutdown(s, SD_SEND);
321 if (s != INVALID_SOCKET && !closed) {
322 ::shutdown(s, SD_BOTH);
337 int len =
sizeof(size);
339 ::getsockopt(s, SOL_SOCKET, 0x2003, (
char*) &size, &len);