#include "input_windows.h" /* void init_wsa(void) { WSADATA wsa; WSAStartup(WINSOCK_VERSION, &wsa); } */ int windows_read(int fd, char *buffer, int len) { struct timeval tv; fd_set rfd; retry: FD_ZERO(&rfd); FD_SET(fd, &rfd); tv.tv_sec = 0; tv.tv_usec = 200; int rs; int ret; rs = select(fd+1, &rfd, NULL, NULL, &tv); if (errno == EINTR) { goto retry; } if (rs == -1) { // error return -1; } if (rs == 0 ) { return 0; } if (FD_ISSET(fd, &rfd)) { ret = recv(fd, buffer, len, 0); if (ret == 0) { // select, recv = 0: connection closed. return -1; } return ret; } return -1; }