388 |
FD_SET(fd, &rds); |
FD_SET(fd, &rds); |
389 |
do |
do |
390 |
n = select(fd + 1, &rds, NULL, NULL, NULL); |
n = select(fd + 1, &rds, NULL, NULL, NULL); |
391 |
while (errno == EINTR); |
while (n < 0 && errno == EINTR); |
392 |
if (n > 0) { |
if (n > 0) { |
393 |
n = read(fd, data, size); |
n = read(fd, data, size); |
394 |
if (n >= 0) |
if (n >= 0) |
403 |
return strerror(rc); |
return strerror(rc); |
404 |
} |
} |
405 |
|
|
|
#if defined(O_NONBLOCK) |
|
|
# define FCNTL_NONBLOCK O_NONBLOCK |
|
|
#elif defined(O_NDELAY) |
|
|
# define FCNTL_NONBLOCK O_NDELAY |
|
|
#else |
|
|
# error "Neither O_NONBLOCK nor O_NDELAY are defined" |
|
|
#endif |
|
|
|
|
|
int |
|
|
set_nonblocking(int fd) |
|
|
{ |
|
|
int flags; |
|
|
|
|
|
if ((flags = fcntl(fd, F_GETFL, 0)) < 0) { |
|
|
perror("F_GETFL"); |
|
|
return -1; |
|
|
} |
|
|
if (fcntl(fd, F_SETFL, flags | FCNTL_NONBLOCK) < 0) { |
|
|
perror("F_GETFL"); |
|
|
return -1; |
|
|
} |
|
|
return 0; |
|
|
} |
|
|
|
|
406 |
void |
void |
407 |
stdinout(void) |
stdinout(void) |
408 |
{ |
{ |
432 |
free_mem(); |
free_mem(); |
433 |
return; |
return; |
434 |
} |
} |
|
set_nonblocking(sd_client); |
|
|
set_nonblocking(sd_server); |
|
435 |
remote_client = (void *)sd_client; |
remote_client = (void *)sd_client; |
436 |
remote_server = (void *)sd_server; |
remote_server = (void *)sd_server; |
437 |
net_set_io(CLIENT, _stdio_read, _stdio_write, NULL, _stdio_strerror); |
net_set_io(CLIENT, _stdio_read, _stdio_write, NULL, _stdio_strerror); |