136 INTS4 retval , buflen_tmp;
139 struct timeval read_timeout;
140 fd_set xrmask,xwmask,xemask;
141 INTS4 num_of_bytes_read = 0;
143 buflen_tmp = i_buflen;
144 p_buffer_tmp = (
INTS1*) p_buffer;
150 read_timeout.tv_sec = i_timeout;
151 read_timeout.tv_usec = 0;
154#ifndef DISABLE_POLLING_TIMEOUT
155 if (i_timeout == 555555) {
156 read_timeout.tv_sec = 0;
157 read_timeout.tv_usec = 50000;
162 printf(
"STC: read %6d bytes channel %d ",i_buflen,
i_channel);fflush(stdout);
164 while( num_of_bytes_read < i_buflen && buflen_tmp > 0 )
178 retval = select(
i_channel+1, &xrmask, &xwmask, &xemask, &read_timeout);
187 case EINTR :
continue;
200 printf(
"read ");fflush(stdout);
203 retval = recv(
i_channel, p_buffer_tmp, buflen_tmp, 0);
205 retval = read(
i_channel, p_buffer_tmp, buflen_tmp);
228 num_of_bytes_read += retval;
229 buflen_tmp -= retval;
230 p_buffer_tmp += retval;
231 if( ++i_retry == 100000 ) {
232 printf(
"Request %d bytes, read %d, timeout after 100000 retries\n",i_buflen,num_of_bytes_read);
236#ifndef DISABLE_POLLING_TIMEOUT
237 if (i_timeout == 555555) {
238 read_timeout.tv_sec = 0;
239 read_timeout.tv_usec = 50000;
241 read_timeout.tv_sec = 100;
242 read_timeout.tv_usec = 0;
245 read_timeout.tv_sec = 100;
246 read_timeout.tv_usec = 0;
253 printf(
"done\n"); fflush(stdout);
255 if( num_of_bytes_read == i_buflen )
return STC__SUCCESS;
506 WORD wVersionRequested;
508 wVersionRequested = MAKEWORD( 2, 2 );
510 if (WSAStartup( wVersionRequested, &wsaData) != 0) {
511 printf(
"WinSock NOT found");
516 if ( LOBYTE( wsaData.wVersion ) != 2 ||
517 HIBYTE( wsaData.wVersion ) != 2 ) {
521 printf(
"WinSock %d.%d",LOBYTE( wsaData.wVersion ),HIBYTE( wsaData.wVersion ));
527 s_client.
socket =
socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
529 *ps_client = s_client;
530 *pi_channel = s_client.
socket;
547 if(( s_client.
hostentptr = gethostbyname(c_node)) == NULL)
551 closesocket(s_client.
socket);
562 s_client.sock.sin_family = s_client.
hostentstruct.h_addrtype;
563 s_client.sock.sin_port = htons(l_port);
564 s_client.sock.sin_addr =
567 retval = connect( s_client.
socket,
568 (
struct sockaddr *) &s_client.sock,
569 sizeof(s_client.sock));
573 closesocket(s_client.
socket);
591 *ps_client = s_client;
852 INTS4 retval , retry;
857 WORD wVersionRequested;
859 wVersionRequested = MAKEWORD( 2, 2 );
861 if (WSAStartup( wVersionRequested, &wsaData) != 0) {
862 printf(
"WinSock NOT found");
867 if ( LOBYTE( wsaData.wVersion ) != 2 ||
868 HIBYTE( wsaData.wVersion ) != 2 ) {
872 printf(
"WinSock %d.%d",LOBYTE( wsaData.wVersion ),HIBYTE( wsaData.wVersion ));
878 if( *pl_port == 0 ) {
885 s_server.
sock_rw =
socket (AF_INET, SOCK_STREAM, IPPROTO_TCP);
905 printf(
"--E--f_stc_createserver() error get local hostname\n");
911 printf(
"--E--f_stc_createserver() error get local Internet address\n");
917 s_server.
sock_name.sin_addr.s_addr = htonl(INADDR_ANY);
918 s_server.
sock_name.sin_port = htons(*pl_port);
920 retval = bind( s_server.
sock_rw,
924 if( retval == -1 && retry == 0 )
941 while ( retval == -1 && retry == 1 )
944 s_server.
sock_rw =
socket (AF_INET, SOCK_STREAM, IPPROTO_TCP);
963 printf(
"--E--f_stc_createserver() error get local hostname\n");
970 printf(
"--E--f_stc_createserver() error get local Internet address\n");
978 s_server.
sock_name.sin_addr.s_addr = htonl(INADDR_ANY);
979 s_server.
sock_name.sin_port = htons(*pl_port);
981 retval = bind( s_server.
sock_rw,
990 if( *pl_port > 65535 )
992 printf(
"--E--f_stc_createserver() portnumber exceeded > 655535\n");
1011 retval = listen(s_server.
sock_rw,5);
1024 *ps_server = s_server;
1253 struct timeval read_timeout;
1254 fd_set rset , allset , wset , eset;
1255 INTS4 listenfd , maxfd , sts;
1257 read_timeout.tv_sec = 0;
1258 read_timeout.tv_usec = 0;
1260 listenfd = ps_server->
sock_rw;
1266 FD_SET(listenfd,&rset);
1267 FD_SET(listenfd,&wset);
1268 FD_SET(listenfd,&eset);
1271 sts = select( maxfd + 1 , &rset ,
1273 &eset , &read_timeout);
1288 if( FD_ISSET(listenfd,&eset)) {
1292 if( FD_ISSET(listenfd,&rset)) {
1296 if( FD_ISSET(listenfd,&wset)) {