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;
149 FD_SET(i_channel,&xrmask);
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;
189 default : sprintf(
c_msg,
"STC select error channel %d",i_channel);
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);
216 default : sprintf(
c_msg,
"STC read error channel %d",i_channel);
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;
348 printf(
"STC: write %5d bytes channel %d ",i_buflen,i_channel);fflush(stdout);
350 l_retval = send(i_channel , p_buffer , i_buflen , 0);
360 default : sprintf(
c_msg,
"STC write error channel %d",i_channel);
372 printf(
"done\n");fflush(stdout);
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;
688 *pi_channel = accept( ps_server->
sock_rw,
689 (
struct sockaddr *) &ps_server->
sock_name,
693 *pi_channel = accept( ps_server->
sock_rw,
694 (
struct sockaddr *) &ps_server->
sock_name,
697 *pi_channel = accept( ps_server->
sock_rw,
698 (
struct sockaddr *) &ps_server->
sock_name,
702 if( *pi_channel == -1)
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;
1095 retval = shutdown( ps_tcp->
socket,2);
1099 retval = close(ps_tcp->
socket);
1175 retval = close( i_channel );
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)) {
1404 sprintf(c_line,
"-I- f_stc failure");
1407 sprintf(c_line,
"-I- f_stc failure");
1410 sprintf(c_line,
"-I- f_stc invalid socket number");
1413 sprintf(c_line,
"-I- f_stc buffer points outside allocated address space");
1416 sprintf(c_line,
"-I- f_stc buffer length is negative");
1419 sprintf(c_line,
"-I- f_stc time limit is negativ or to long");
1422 sprintf(c_line,
"-I- f_stc timeout read data from socket");
1425 sprintf(c_line,
"-I- f_stc socket number points to a file not a socket");
1428 sprintf(c_line,
"-I- f_stc invalid address specified in parameter");
1431 sprintf(c_line,
"-I- f_stc the specified address family is not supported");
1434 sprintf(c_line,
"-I- f_stc The specified socket type is not supported.");
1437 sprintf(c_line,
"-I- f_stc The specified protocol is not supported.");
1440 sprintf(c_line,
"-I- f_stc The per-process descriptor table is full.");
1443 sprintf(c_line,
"-I- f_stc No buffer space is available. The socket can't be created");
1446 sprintf(c_line,
"-I- f_stc socket is already connected.");
1449 sprintf(c_line,
"-I- f_stc connection timed out without establishing a connection.");
1452 sprintf(c_line,
"-I- f_stc The network is not reachable from this host.");
1455 sprintf(c_line,
"-I- f_stc The specified Internet Address and port is already in use.");
1458 sprintf(c_line,
"-I- f_stc socket address is protected.");
1461 sprintf(c_line,
"-I- f_stc connection refused.");
1464 sprintf(c_line,
"-I- f_stc error connect portserver");
1467 sprintf(c_line,
"-I- f_stc error register service at portserver");
1470 sprintf(c_line,
"-I- f_stc error write buffer to portserver");
1473 sprintf(c_line,
"-I- f_stc error read status message from portserver");
1476 sprintf(c_line,
"-I- f_stc error get spec. info from portserver");
1479 sprintf(c_line,
"-I- f_stc unknown message id %d",i_error);
1480 if(i_out == 0) printf(
"%s\n",c_line);
1481 if(i_out == 1) strcpy(c_dest,c_line);
1485 if(i_out==0) printf(
"%s\n",c_line);
1486 if(i_out==1) strcpy(c_dest,c_line);
INTS4 f_stc_close(struct s_tcpcomm *ps_tcp)
INTS4 f_stc_read(void *p_buffer, INTS4 i_buflen, INTS4 i_channel, INTS4 i_timeout)
struct hostent hostentstruct
INTS4 f_stc_listenserver(struct s_tcpcomm *ps_server)
INTS4 f_stc_write(void *p_buffer, INTS4 i_buflen, INTS4 i_channel)
INTS4 f_stc_disperror(INTS4 i_error, CHARS *c_dest, INTS4 i_out)
INTS4 f_stc_acceptclient(struct s_tcpcomm *ps_server, INTS4 *pi_channel)
INTS4 f_stc_discclient(INTS4 i_channel)
INTS4 f_stc_connectserver(CHARS *c_node, INTS4 l_port, INTS4 *pi_channel, struct s_tcpcomm *ps_client)
struct hostent * hostentptr
struct sockaddr_in sock sock_name
INTS4 f_stc_createserver(INTS4 *pl_port, struct s_tcpcomm *ps_server)