use WSAEWOULDBLOCK on windows, EWOULDBLOCK on linux/osx
Adrian Smith
10 years ago
83 | 83 |
while (len) {
|
84 | 84 |
n = send(sock, ptr, len, MSG_NOSIGNAL);
|
85 | 85 |
if (n <= 0) {
|
86 | |
if (n < 0 && last_error() == EAGAIN && try < 10) {
|
|
86 |
if (n < 0 && last_error() == ERROR_WOULDBLOCK && try < 10) {
|
87 | 87 |
LOG_DEBUG("retrying (%d) writing to socket", ++try);
|
88 | 88 |
usleep(1000);
|
89 | 89 |
continue;
|
|
459 | 459 |
if (expect > 0) {
|
460 | 460 |
int n = recv(sock, buffer + got, expect, 0);
|
461 | 461 |
if (n <= 0) {
|
462 | |
if (n < 0 && last_error() == EAGAIN) {
|
|
462 |
if (n < 0 && last_error() == ERROR_WOULDBLOCK) {
|
463 | 463 |
continue;
|
464 | 464 |
}
|
465 | 465 |
LOG_INFO("error reading from socket: %s", n ? strerror(last_error()) : "closed");
|
|
474 | 474 |
} else if (expect == 0) {
|
475 | 475 |
int n = recv(sock, buffer + got, 2 - got, 0);
|
476 | 476 |
if (n <= 0) {
|
477 | |
if (n < 0 && last_error() == EAGAIN) {
|
|
477 |
if (n < 0 && last_error() == ERROR_WOULDBLOCK) {
|
478 | 478 |
continue;
|
479 | 479 |
}
|
480 | 480 |
LOG_INFO("error reading from socket: %s", n ? strerror(last_error()) : "closed");
|
139 | 139 |
#define thread_t pthread_t;
|
140 | 140 |
#define closesocket(s) close(s)
|
141 | 141 |
#define last_error() errno
|
|
142 |
#define ERROR_WOULDBLOCK EWOULDBLOCK
|
142 | 143 |
|
143 | 144 |
typedef u_int8_t u8_t;
|
144 | 145 |
typedef u_int16_t u16_t;
|
|
193 | 194 |
#define usleep(x) Sleep(x/1000)
|
194 | 195 |
#define sleep(x) Sleep(x*1000)
|
195 | 196 |
#define last_error() WSAGetLastError()
|
|
197 |
#define ERROR_WOULDBLOCK WSAEWOULDBLOCK
|
196 | 198 |
#define open _open
|
197 | 199 |
#define read _read
|
198 | 200 |
|
45 | 45 |
while (len) {
|
46 | 46 |
n = send(fd, ptr, len, MSG_NOSIGNAL);
|
47 | 47 |
if (n <= 0) {
|
48 | |
if (n < 0 && last_error() == EAGAIN && try < 10) {
|
|
48 |
if (n < 0 && last_error() == ERROR_WOULDBLOCK && try < 10) {
|
49 | 49 |
LOG_SDEBUG("retrying (%d) writing to socket", ++try);
|
50 | 50 |
usleep(1000);
|
51 | 51 |
continue;
|
|
124 | 124 |
|
125 | 125 |
int n = recv(fd, &c, 1, 0);
|
126 | 126 |
if (n <= 0) {
|
127 | |
if (n < 0 && last_error() == EAGAIN) {
|
|
127 |
if (n < 0 && last_error() == ERROR_WOULDBLOCK) {
|
128 | 128 |
UNLOCK;
|
129 | 129 |
continue;
|
130 | 130 |
}
|
|
166 | 166 |
u8_t c;
|
167 | 167 |
int n = recv(fd, &c, 1, 0);
|
168 | 168 |
if (n <= 0) {
|
169 | |
if (n < 0 && last_error() == EAGAIN) {
|
|
169 |
if (n < 0 && last_error() == ERROR_WOULDBLOCK) {
|
170 | 170 |
UNLOCK;
|
171 | 171 |
continue;
|
172 | 172 |
}
|
|
183 | 183 |
if (stream.meta_left) {
|
184 | 184 |
int n = recv(fd, stream.header + stream.header_len, stream.meta_left, 0);
|
185 | 185 |
if (n <= 0) {
|
186 | |
if (n < 0 && last_error() == EAGAIN) {
|
|
186 |
if (n < 0 && last_error() == ERROR_WOULDBLOCK) {
|
187 | 187 |
UNLOCK;
|
188 | 188 |
continue;
|
189 | 189 |
}
|
|
222 | 222 |
LOG_INFO("end of stream");
|
223 | 223 |
_disconnect(DISCONNECT, DISCONNECT_OK);
|
224 | 224 |
}
|
225 | |
if (n < 0 && last_error() != EAGAIN) {
|
|
225 |
if (n < 0 && last_error() != ERROR_WOULDBLOCK) {
|
226 | 226 |
LOG_INFO("error reading: %s", strerror(last_error()));
|
227 | 227 |
_disconnect(DISCONNECT, REMOTE_DISCONNECT);
|
228 | 228 |
}
|