131 INTS4 retval , buflen_tmp;
134 struct timeval read_timeout;
135 fd_set xrmask,xwmask,xemask;
136 INTS4 num_of_bytes_read = 0;
138 buflen_tmp = i_buflen;
139 p_buffer_tmp = (
INTS1*) p_buffer;
144 FD_SET(i_channel,&xrmask);
145 read_timeout.tv_sec = i_timeout;
146 read_timeout.tv_usec = 0;
148 printf(
"STC: read %6d bytes channel %d ",i_buflen,i_channel);fflush(stdout);
150 while( num_of_bytes_read < i_buflen && buflen_tmp > 0 )
164 retval = select(i_channel+1, &xrmask, &xwmask, &xemask, &read_timeout);
173 case EINTR :
continue;
175 default : sprintf(
c_msg,
"STC select error channel %d",i_channel);
186 printf(
"read ");fflush(stdout);
189 retval = recv(i_channel, p_buffer_tmp, buflen_tmp, 0);
191 retval = read(i_channel, p_buffer_tmp, buflen_tmp);
202 default : sprintf(
c_msg,
"STC read error channel %d",i_channel);
214 num_of_bytes_read += retval;
215 buflen_tmp -= retval;
216 p_buffer_tmp += retval;
217 if( ++i_retry == 100000 ) {
218 printf(
"Request %d bytes, read %d, timeout after 100000 retries\n",i_buflen,num_of_bytes_read);
222 read_timeout.tv_sec = 100;
223 read_timeout.tv_usec = 0;
229 printf(
"done\n"); fflush(stdout);
231 if( num_of_bytes_read == i_buflen )
return STC__SUCCESS;
324 printf(
"STC: write %5d bytes channel %d ",i_buflen,i_channel);fflush(stdout);
326 l_retval = send(i_channel , p_buffer , i_buflen , 0);
336 default : sprintf(
c_msg,
"STC write error channel %d",i_channel);
348 printf(
"done\n");fflush(stdout);
472 INTS4 shut , retval ;
483 WORD wVersionRequested;
486 wVersionRequested = MAKEWORD( 2, 2 );
488 if (WSAStartup( wVersionRequested, &wsaData)!=0) {
489 printf(
"WinSock NOT found");
494 if ( LOBYTE( wsaData.wVersion ) != 2 ||
495 HIBYTE( wsaData.wVersion ) != 2 ) {
499 printf(
"WinSock %d.%d",LOBYTE( wsaData.wVersion ),HIBYTE( wsaData.wVersion ));
505 s_client.
socket =
socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
507 *ps_client = s_client;
508 *pi_channel = s_client.
socket;
525 if(( s_client.
hostentptr = gethostbyname(c_node)) == NULL)
529 closesocket(s_client.
socket);
540 s_client.sock.sin_family = s_client.
hostentstruct.h_addrtype;
541 s_client.sock.sin_port = htons(l_port);
542 s_client.sock.sin_addr =
545 retval = connect( s_client.
socket,
546 (
struct sockaddr *) &s_client.sock,
547 sizeof(s_client.sock));
551 closesocket(s_client.
socket);
569 *ps_client = s_client;
669 *pi_channel = accept( ps_server->
sock_rw,
670 (
struct sockaddr *) &ps_server->
sock_name,
673 *pi_channel = accept( ps_server->
sock_rw,
674 (
struct sockaddr *) &ps_server->
sock_name,
677 if( *pi_channel == -1)
827 INTS4 retval , i , retry , on ;
833 WORD wVersionRequested;
836 wVersionRequested = MAKEWORD( 2, 2 );
838 if (WSAStartup( wVersionRequested, &wsaData)!=0) {
839 printf(
"WinSock NOT found");
844 if ( LOBYTE( wsaData.wVersion ) != 2 ||
845 HIBYTE( wsaData.wVersion ) != 2 ) {
849 printf(
"WinSock %d.%d",LOBYTE( wsaData.wVersion ),HIBYTE( wsaData.wVersion ));
857 if( *pl_port == 0 ) {
864 s_server.
sock_rw =
socket (AF_INET, SOCK_STREAM, IPPROTO_TCP);
884 printf(
"--E--f_stc_createserver() error get local hostname\n");
890 printf(
"--E--f_stc_createserver() error get local Internet address\n");
896 s_server.
sock_name.sin_addr.s_addr = htonl(INADDR_ANY);
897 s_server.
sock_name.sin_port = htons(*pl_port);
899 retval = bind( s_server.
sock_rw,
903 if( retval == -1 && retry == 0 )
920 while ( retval == -1 && retry == 1 )
923 s_server.
sock_rw =
socket (AF_INET, SOCK_STREAM, IPPROTO_TCP);
942 printf(
"--E--f_stc_createserver() error get local hostname\n");
949 printf(
"--E--f_stc_createserver() error get local Internet address\n");
957 s_server.
sock_name.sin_addr.s_addr = htonl(INADDR_ANY);
958 s_server.
sock_name.sin_port = htons(*pl_port);
960 retval = bind( s_server.
sock_rw,
969 if( *pl_port > 65535 )
971 printf(
"--E--f_stc_createserver() portnumber exceeded > 655535\n");
990 retval = listen(s_server.
sock_rw,5);
1003 *ps_server = s_server;
1074 retval = shutdown( ps_tcp->
socket,2);
1078 retval = close(ps_tcp->
socket);
1154 retval = close( i_channel );
1232 struct timeval read_timeout;
1233 fd_set rset , allset , wset , eset;
1234 INTS4 listenfd , maxfd , sts;
1236 read_timeout.tv_sec = 0;
1237 read_timeout.tv_usec = 0;
1239 listenfd = ps_server->
sock_rw;
1245 FD_SET(listenfd,&rset);
1246 FD_SET(listenfd,&wset);
1247 FD_SET(listenfd,&eset);
1250 sts = select( maxfd + 1 , &rset ,
1252 &eset , &read_timeout);
1267 if( FD_ISSET(listenfd,&eset)) {
1271 if( FD_ISSET(listenfd,&rset)) {
1275 if( FD_ISSET(listenfd,&wset)) {
1383 sprintf(c_line,
"-I- f_stc failure");
1386 sprintf(c_line,
"-I- f_stc failure");
1389 sprintf(c_line,
"-I- f_stc invalid socket number");
1392 sprintf(c_line,
"-I- f_stc buffer points outside allocated address space");
1395 sprintf(c_line,
"-I- f_stc buffer length is negative");
1398 sprintf(c_line,
"-I- f_stc time limit is negativ or to long");
1401 sprintf(c_line,
"-I- f_stc timeout read data from socket");
1404 sprintf(c_line,
"-I- f_stc socket number points to a file not a socket");
1407 sprintf(c_line,
"-I- f_stc invalid address specified in parameter");
1410 sprintf(c_line,
"-I- f_stc the specified address family is not supported");
1413 sprintf(c_line,
"-I- f_stc The specified socket type is not supported.");
1416 sprintf(c_line,
"-I- f_stc The specified protocol is not supported.");
1419 sprintf(c_line,
"-I- f_stc The per-process descriptor table is full.");
1422 sprintf(c_line,
"-I- f_stc No buffer space is available. The socket can't be created");
1425 sprintf(c_line,
"-I- f_stc socket is already connected.");
1428 sprintf(c_line,
"-I- f_stc connection timed out without establishing a connection.");
1431 sprintf(c_line,
"-I- f_stc The network is not reachable from this host.");
1434 sprintf(c_line,
"-I- f_stc The specified Internet Address and port is already in use.");
1437 sprintf(c_line,
"-I- f_stc socket address is protected.");
1440 sprintf(c_line,
"-I- f_stc connection refused.");
1443 sprintf(c_line,
"-I- f_stc error connect portserver");
1446 sprintf(c_line,
"-I- f_stc error register service at portserver");
1449 sprintf(c_line,
"-I- f_stc error write buffer to portserver");
1452 sprintf(c_line,
"-I- f_stc error read status message from portserver");
1455 sprintf(c_line,
"-I- f_stc error get spec. info from portserver");
1458 sprintf(c_line,
"-I- f_stc unknown message id %d",i_error);
1459 if(i_out==0)printf(
"%s\n",c_line);
1460 if(i_out==1)strcpy(c_dest,c_line);
1464 if(i_out==0) printf(
"%s\n",c_line);
1465 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)