Changeset 18920 for trunk/FACT++/dim/src/tcpip.c
- Timestamp:
- 10/18/17 13:54:41 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/FACT++/dim/src/tcpip.c
r18097 r18920 16 16 #ifdef WIN32 17 17 #define FD_SETSIZE 16384 18 #define poll(pfd,nfds,timeout) WSAPoll(pfd,nfds,timeout) 18 #endif 19 20 #include <stdio.h> 21 #include <time.h> 22 #define DIMLIB 23 #include <dim.h> 24 25 #ifdef WIN32 26 //#define poll(pfd,nfds,timeout) WSAPoll(pfd,nfds,timeout) 19 27 #define ioctl ioctlsocket 20 28 … … 26 34 #define EADDRNOTAVAIL WSAEADDRNOTAVAIL 27 35 #define EWOULDBLOCK WSAEWOULDBLOCK 36 #define EINPROGRESS WSAEINPROGRESS 28 37 #define ECONNREFUSED WSAECONNREFUSED 38 #define ETIMEDOUT WSAETIMEDOUT 29 39 #define HOST_NOT_FOUND WSAHOST_NOT_FOUND 30 40 #define NO_DATA WSANO_DATA … … 80 90 #define MY_FD_ISSET(fd, set) FD_ISSET(fd, set) 81 91 #endif 82 83 #include <stdio.h>84 #include <time.h>85 #define DIMLIB86 #include <dim.h>87 92 88 93 #define ushort unsigned short … … 813 818 fd_set rfds; 814 819 int conn_id, ret, selret, count; 820 #ifndef __linux__ 815 821 struct timeval timeout; 822 #endif 816 823 817 824 if(num){} 818 825 do 819 826 { 820 timeout.tv_sec = 0; /* Don't wait, just poll */821 timeout.tv_usec = 0;822 827 list_to_fds( &rfds ); 823 828 #ifdef __linux__ 824 829 selret = poll(Pollfds, Pollfd_size, 0); 825 830 #else 831 timeout.tv_sec = 0; /* Don't wait, just poll */ 832 timeout.tv_usec = 0; 826 833 selret = select(FD_SETSIZE, &rfds, NULL, NULL, &timeout); 827 834 #endif … … 890 897 #endif 891 898 if(ret <= 0) 892 893 printf("poll returned %d, errno %d\n", ret, errno);894 899 { 900 printf("poll/select returned %d, errno %d\n", ret, errno); 901 } 895 902 if(ret > 0) 896 903 { … … 1023 1030 int host_addr; 1024 1031 #endif 1025 int path, val, ret_code, ret ;1032 int path, val, ret_code, ret, retcon, selret; 1026 1033 int a,b,c,d; 1027 1034 /* Fix for gcc 4.6 "dereferencing type-punned pointer will break strict-aliasing rules"?!*/ … … 1029 1036 unsigned char *ipaddr = ipaddr_buff; 1030 1037 int host_number = 0; 1038 int tcpip_would_block(); 1039 #ifdef __linux__ 1040 struct pollfd pollitem; 1041 #else 1042 struct timeval timeout; 1043 fd_set rfds, wfds, efds; 1044 #endif 1045 int so_error = ETIMEDOUT; 1046 int so_error_len = sizeof(so_error); 1031 1047 1032 1048 dim_tcpip_init(0); … … 1161 1177 #endif 1162 1178 sockname.sin_port = htons((ushort) port); /* port number to send to */ 1163 while((ret = connect(path, (struct sockaddr*)&sockname, sizeof(sockname))) == -1 ) 1164 { 1165 if(errno != EINTR) 1179 /* 1180 while ((ret = connect(path, (struct sockaddr*)&sockname, sizeof(sockname))) == -1) 1181 { 1182 if (errno != EINTR) 1166 1183 { 1167 1184 closesock(path); … … 1169 1186 } 1170 1187 } 1171 strcpy( Net_conns[conn_id].node, node ); 1188 */ 1189 set_non_blocking(path); 1190 retcon = connect(path, (struct sockaddr*)&sockname, sizeof(sockname)); 1191 #ifndef WIN32 1192 ret = errno; 1193 #else 1194 ret = WSAGetLastError(); 1195 #endif 1196 set_blocking(path); 1197 if (retcon == -1) 1198 { 1199 if (tcpip_would_block(ret)) 1200 { 1201 #ifdef __linux__ 1202 pollitem.fd = path; 1203 pollitem.events = POLLIN | POLLOUT | POLLERR; 1204 pollitem.revents = 0; 1205 selret = poll(&pollitem, 1, CONNECT_TMOUT * 1000); 1206 #else 1207 timeout.tv_sec = CONNECT_TMOUT; 1208 timeout.tv_usec = 0; 1209 FD_ZERO(&wfds); 1210 FD_SET(path, &wfds); 1211 FD_ZERO(&rfds); 1212 FD_SET(path, &rfds); 1213 FD_ZERO(&efds); 1214 FD_SET(path, &efds); 1215 selret = select(FD_SETSIZE, &rfds, &wfds, &efds, &timeout); 1216 #endif 1217 if (selret > 0) 1218 { 1219 getsockopt(path, SOL_SOCKET, SO_ERROR, (void *)&so_error, &so_error_len); 1220 } 1221 } 1222 if (so_error != 0) 1223 { 1224 #ifndef WIN32 1225 errno = so_error; 1226 #else 1227 WSASetLastError(so_error); 1228 #endif 1229 closesock(path); 1230 return(0); 1231 } 1232 } 1233 strcpy(Net_conns[conn_id].node, node); 1172 1234 strcpy( Net_conns[conn_id].task, task ); 1173 1235 Net_conns[conn_id].channel = path; … … 1547 1609 if(code == EWOULDBLOCK) 1548 1610 return(1); 1549 return(0); 1611 else if (code == EINPROGRESS) 1612 return(1); 1613 return(0); 1550 1614 } 1551 1615
Note:
See TracChangeset
for help on using the changeset viewer.