00001 // $Id: f_stccomm.c 1202 2014-05-09 07:07:18Z linev $ 00002 //----------------------------------------------------------------------- 00003 // The GSI Online Offline Object Oriented (Go4) Project 00004 // Experiment Data Processing at EE department, GSI 00005 //----------------------------------------------------------------------- 00006 // Copyright (C) 2000- GSI Helmholtzzentrum für Schwerionenforschung GmbH 00007 // Planckstr. 1, 64291 Darmstadt, Germany 00008 // Contact: http://go4.gsi.de 00009 //----------------------------------------------------------------------- 00010 // This software can be used under the license agreements as stated 00011 // in Go4License.txt file which is part of the distribution. 00012 //----------------------------------------------------------------------- 00013 00014 #include "f_stccomm.h" 00015 00016 CHARS c_msg[80]; 00017 /*#define DEBUG 1*/ 00018 00019 /* %%+HEAD: */ 00020 /*****************+***********+****************************************/ 00021 /* */ 00022 /* GSI, Gesellschaft fuer Schwerionenforschung mbH */ 00023 /* Postfach 11 05 41 */ 00024 /* D-6100 Darmstadt 11 */ 00025 /* */ 00026 /*1+ PLI Main ****************+****************************************/ 00027 /* */ 00028 /*+ Module : f_stc_read */ 00029 /* */ 00030 /*--------------------------------------------------------------------*/ 00031 /*+ CALLING : f_stc_read( INTS1 p_buffer , INTS4 i_buflen , */ 00032 /* INTS4 i_channel , INTS4 i_timeout ) */ 00033 /* */ 00034 /*--------------------------------------------------------------------*/ 00035 /* */ 00036 /*+ PURPOSE : f_stc_read read bytes from a connected socket */ 00037 /* and places them in a buffer (p_buffer). */ 00038 /* */ 00039 /*+ ARGUMENTS : */ 00040 /* */ 00041 /*+ p_buffer : Pointer to free data buffer. */ 00042 /* */ 00043 /*+ i_buflen : buffer length. */ 00044 /* */ 00045 /*+ i_channel : Id from the connected socket. */ 00046 /* */ 00047 /*+ i_timeout : Timeout value ( seconds ) for read from socket. */ 00048 /*- i_timeout = 0 : Return immediately after */ 00049 /* checking the connected socket. */ 00050 /*- i_timeout > 0 : Return when the specified socket */ 00051 /* is ready for I/O, but don't wait */ 00052 /* beyond a fixed amount of time. */ 00053 /*- i_timeout = -1 : Return only when the specified */ 00054 /* socket is ready for I/O. */ 00055 /* */ 00056 /*+ Return type : integer. */ 00057 /* */ 00058 /*2+DESCRIPTION***+***********+****************************************/ 00059 /* */ 00060 /*+ CALLING : f_stc_read ( INTS1 p_buffer , INTS4 i_buflen , */ 00061 /* INTS4 i_channel , INTS4 i_timeout ) */ 00062 /* */ 00063 /*+ ARGUMENTS : */ 00064 /* */ 00065 /*+ p_buffer : Pointer to free data buffer. */ 00066 /* */ 00067 /*+ i_buflen : buffer length. */ 00068 /* */ 00069 /*+ i_channel : Id from the connected socket. */ 00070 /* */ 00071 /*+ i_timeout : Timeout value ( seconds ) for read from socket. */ 00072 /* */ 00073 /*- i_timeout = 0 : Return immediately after checking */ 00074 /* the connected socket. */ 00075 /*- i_timeout > 0 : Return when the specified socket */ 00076 /* is ready for I/O, but don't wait */ 00077 /* beyond a fixed amount of time. */ 00078 /*- i_timeout = -1 : Return only when the specified */ 00079 /* socket is ready for I/O. */ 00080 /* */ 00081 /*+ FUNCTION : Read bytes from a connected socket and places them */ 00082 /* in a buffer (p_buffer) */ 00083 /* The procedure f_stc_read wait max timeout seconds */ 00084 /* getting data from the socket. */ 00085 /* */ 00086 /*+ REMARKS : - */ 00087 /* */ 00088 /*2+IMPLEMENTATION************+****************************************/ 00089 /* */ 00090 /*+ Input/Output: SYS$INPUT, SYS$OUTPUT */ 00091 /*+ Return type : INTEGER */ 00092 /*+ Status codes: */ 00093 /*- STC__SUCCESS : success. */ 00094 /*- STC__FAIlURE : failure. */ 00095 /*- STC__INVSOCK : invalid socket number. */ 00096 /*- STC__INVBUF : buffer points outside allocated */ 00097 /* adress space. */ 00098 /*- STC__NGBUFSIZE : buffer length is negative. */ 00099 /*- STC__INVTIME : time limit is unacceptable negativ */ 00100 /* or to long. */ 00101 /*- STC__TIMEOUT : timeout read from socket. */ 00102 /*+ File name : */ 00103 /*+ Version : 1.01 */ 00104 /*+ Author : R.Fritzsche */ 00105 /*+ Last Update : 17-Jul-1995 */ 00106 /* */ 00107 /*2+UPDATES*******+***********+*********************************************/ 00108 /* */ 00109 /*+ Updates : Date Purpose */ 00110 /*- 17-Jul-1995 : f_stc_connectserver H.G. */ 00111 /* close socket in case of failure to avoid */ 00112 /* hanging sockets */ 00113 /*- 17-Jul-1995 : f_stc_discclient H.G. */ 00114 /* remove shutdown (which didn't work and */ 00115 /* inibited close) and make close in any case */ 00116 /*- 17-Jul-1995 : f_stc_disperror H.G. */ 00117 /* new message no.: STC__ECONNREF */ 00118 /* */ 00119 /*2+INTERNALS*****+***********+*********************************************/ 00120 /* */ 00121 /*+ Utility : EXAMPLES */ 00122 /*+ Compile lib.: GOOINC.TLB */ 00123 /*+ Home direct.: GOO$EXAMPLES */ 00124 /*+ Created : 25-Jan-1994 */ 00125 /* */ 00126 /*1- PLI Main ****************+****************************************/ 00127 /* %%-HEAD: */ 00128 00129 INTS4 f_stc_read(void *p_buffer, INTS4 i_buflen, INTS4 i_channel, INTS4 i_timeout) 00130 { 00131 INTS4 retval , buflen_tmp; 00132 INTS1 *p_buffer_tmp; 00133 INTS4 i_retry=0; 00134 struct timeval read_timeout; 00135 fd_set xrmask,xwmask,xemask; 00136 INTS4 num_of_bytes_read = 0; 00137 00138 buflen_tmp = i_buflen; 00139 p_buffer_tmp = (INTS1*) p_buffer; /* actual pointer to buffer */ 00140 00141 FD_ZERO(&xrmask); 00142 FD_ZERO(&xemask); 00143 FD_ZERO(&xwmask); 00144 FD_SET(i_channel,&xrmask); 00145 read_timeout.tv_sec = i_timeout; 00146 read_timeout.tv_usec = 0; 00147 #ifdef DEBUG 00148 printf("STC: read %6d bytes channel %d ",i_buflen,i_channel);fflush(stdout); 00149 #endif 00150 while( num_of_bytes_read < i_buflen && buflen_tmp > 0 ) 00151 { 00152 if( i_timeout >= 0 ) 00153 { 00154 /* 00155 #ifdef GSI__AIX 00156 retval = select(32,&xrmask,&xwmask,&xemask,&read_timeout); 00157 #else 00158 retval = select(32,&rmask,&wmask,&emask,&read_timeout); 00159 #endif 00160 */ 00161 00162 /* Changed by S.Linev, 18.09.2007 */ 00163 // retval = select(32,(fd_set*) &rmask, (fd_set*) &wmask, (fd_set*) &emask,&read_timeout); 00164 retval = select(i_channel+1, &xrmask, &xwmask, &xemask, &read_timeout); 00165 00166 switch( retval ) 00167 { 00168 case -1: 00169 switch( errno ) 00170 { 00171 case EBADF : return STC__INVSOCK; 00172 case EINVAL : return STC__INVTIME; 00173 case EINTR : continue; 00174 case ECONNRESET : return STC__ECONNRES; 00175 default : sprintf(c_msg,"STC select error channel %d",i_channel); 00176 perror(c_msg); 00177 return STC__FAILURE; 00178 } 00179 case 0: return STC__TIMEOUT; 00180 } 00181 } 00182 /* ------------------------------------------------------- */ 00183 /* read data from the connect socket. */ 00184 /* ------------------------------------------------------- */ 00185 #ifdef DEBUG 00186 printf("read ");fflush(stdout); 00187 #endif 00188 #ifdef GSI__WINNT 00189 retval = recv(i_channel ,p_buffer_tmp, buflen_tmp,0); /* Mohammad Al-Turany 31.07.00 */ 00190 #else 00191 retval = read(i_channel , p_buffer_tmp,buflen_tmp); 00192 #endif 00193 if( retval == -1 ) 00194 { 00195 switch( errno ) 00196 { 00197 case EBADF : return STC__INVSOCK; 00198 case EFAULT : return STC__INVBUF; 00199 case EINVAL : return STC__NGBUFSIZE; 00200 case EINTR : return STC__EINTR; 00201 case ECONNRESET : return STC__ECONNRES; 00202 default : sprintf(c_msg,"STC read error channel %d",i_channel); 00203 perror(c_msg); 00204 return STC__FAILURE; 00205 } /* switch( errno ) */ 00206 00207 } /* if( retval == -1 ) */ 00208 00209 /* ------------------------------------------------------- */ 00210 /* set the num of bytes to read in the next */ 00211 /* read statement. */ 00212 /* ------------------------------------------------------- */ 00213 00214 num_of_bytes_read += retval; 00215 buflen_tmp -= retval; 00216 p_buffer_tmp += retval; /* calc actual pointer */ 00217 if( i_retry == 100000 ) 00218 {printf("Request %d bytes, read %d, timeout after 100000 retries\n",i_buflen,num_of_bytes_read); 00219 return STC__NODATA;} 00220 ++i_retry; 00221 00222 read_timeout.tv_sec = 100; 00223 read_timeout.tv_usec = 0; 00224 00225 } /* end while */ 00226 00227 00228 #ifdef DEBUG 00229 printf("done\n");fflush(stdout); 00230 #endif 00231 if( num_of_bytes_read == i_buflen ) return STC__SUCCESS; 00232 00233 return STC__FAILURE; 00234 } /* f_stc_read() */ 00235 00236 /* ------------------------------------------------------------------------- */ 00237 00238 /* %%+HEAD: */ 00239 /*****************+***********+****************************************/ 00240 /* */ 00241 /* GSI, Gesellschaft fuer Schwerionenforschung mbH */ 00242 /* Postfach 11 05 41 */ 00243 /* D-6100 Darmstadt 11 */ 00244 /* */ 00245 /*1+ PLI Main ****************+****************************************/ 00246 /* */ 00247 /*+ Module : f_stc_write */ 00248 /* */ 00249 /*--------------------------------------------------------------------*/ 00250 /*+ CALLING : f_stc_write( INTS1 p_buffer , INTS4 i_buflen , */ 00251 /* INTS4 i_channel ) */ 00252 /*--------------------------------------------------------------------*/ 00253 /* */ 00254 /*+ PURPOSE : f_stc_write. write a buffer to a connected */ 00255 /* socket. */ 00256 /* */ 00257 /*+ ARGUMENTS : */ 00258 /* */ 00259 /*+ p_buffer : Pointer to buffer. */ 00260 /* */ 00261 /*+ i_buflen : length of buffer. */ 00262 /* */ 00263 /*+ i_channel : Id from the connected socket. */ 00264 /* */ 00265 /*+ Return type : integer. */ 00266 /* */ 00267 /*2+DESCRIPTION***+***********+****************************************/ 00268 /* */ 00269 /*+ CALLING : f_stc_write( INTS1 p_buffer , INTS4 i_buflen , */ 00270 /* INTS4 i_channel ) */ 00271 /* */ 00272 /*+ ARGUMENTS : */ 00273 /* */ 00274 /*+ p_buffer : Pointer to buffer. */ 00275 /* */ 00276 /*+ i_buflen : length of buffer. */ 00277 /* */ 00278 /*+ i_channel : Id from the connected socket. */ 00279 /* */ 00280 /*+ FUNCTION : Write a specified buffer to a connected socket */ 00281 /* */ 00282 /*+ REMARKS : - */ 00283 /* */ 00284 /*2+IMPLEMENTATION************+****************************************/ 00285 /* */ 00286 /*+ Input/Output: SYS$INPUT, SYS$OUTPUT */ 00287 /*+ Return type : INTEGER */ 00288 /*+ Status codes: */ 00289 /*- STC__SUCCESS : success. */ 00290 /*- STC__FAILURE : failure. */ 00291 /*- STC__INVSOCK : invalid socket number. */ 00292 /*- STC__NOTSOCK : socket number points to a file */ 00293 /* not a socket. */ 00294 /*- STC__INVADDR : invalid address specified in */ 00295 /* parameter. */ 00296 /*+ File name : */ 00297 /*+ Version : 1.01 */ 00298 /*+ Author : R.Fritzsche */ 00299 /*+ Last Update : 27-Jan-1994 */ 00300 /* */ 00301 /*2+UPDATES*******+***********+****************************************/ 00302 /* */ 00303 /*+ Updates : Date Purpose */ 00304 /* */ 00305 /*2+INTERNALS*****+***********+****************************************/ 00306 /* */ 00307 /*+ Utility : EXAMPLES */ 00308 /*+ Compile lib.: GOOINC.TLB */ 00309 /*+ Home direct.: GOO$EXAMPLES */ 00310 /*+ Created : 25-Jan-1994 */ 00311 /* */ 00312 /*1- PLI Main ****************+****************************************/ 00313 /* %%-HEAD: */ 00314 00315 INTS4 f_stc_write(void *p_buffer, INTS4 i_buflen, INTS4 i_channel) 00316 { 00317 INTS4 l_retval; 00318 00319 /* ---------------------------------------------------------- */ 00320 /* send data to server. */ 00321 /* ---------------------------------------------------------- */ 00322 00323 #ifdef DEBUG 00324 printf("STC: write %5d bytes channel %d ",i_buflen,i_channel);fflush(stdout); 00325 #endif 00326 l_retval = send(i_channel , p_buffer , i_buflen , 0); 00327 00328 switch( l_retval ) 00329 { 00330 case -1: 00331 switch( errno ) 00332 { 00333 case EBADF : return STC__INVSOCK; 00334 case ENOTSOCK : return STC__NOTSOCK; 00335 case EFAULT : return STC__INVADDR; 00336 default : sprintf(c_msg,"STC write error channel %d",i_channel); 00337 perror(c_msg); 00338 return STC__FAILURE; 00339 } /* switch( errno ) */ 00340 00341 } /* switch( l_retval ) */ 00342 00343 /* ---------------------------------------------------------- */ 00344 /* send() returns the number of bytes sent. */ 00345 /* ---------------------------------------------------------- */ 00346 00347 #ifdef DEBUG 00348 printf("done\n");fflush(stdout); 00349 #endif 00350 if(l_retval == i_buflen) return STC__SUCCESS; 00351 00352 return STC__FAILURE; 00353 } /* end f_stc_write() */ 00354 00355 00356 /* %%+HEAD: */ 00357 /*****************+***********+****************************************/ 00358 /* */ 00359 /* GSI, Gesellschaft fuer Schwerionenforschung mbH */ 00360 /* Postfach 11 05 41 */ 00361 /* D-6100 Darmstadt 11 */ 00362 /* */ 00363 /*1+ PLI Main ****************+****************************************/ 00364 /* */ 00365 /*+ Module : f_stc_connectserver */ 00366 /* */ 00367 /*--------------------------------------------------------------------*/ 00368 /*+ CALLING : f_stc_connectserver( CHARS c_node , INTS4 l_port , */ 00369 /* INTS4 pi_channel , */ 00370 /* struct s_tcpcomm ps_client ) */ 00371 /* */ 00372 /*--------------------------------------------------------------------*/ 00373 /* */ 00374 /*+ PURPOSE : f_stc_connectserver. connect a client process to a */ 00375 /* server process. */ 00376 /* */ 00377 /*+ ARGUMENTS : */ 00378 /* */ 00379 /*+ c_node : Name of server node */ 00380 /* */ 00381 /*+ l_port : Portnumber from server */ 00382 /* */ 00383 /*+ pi_channel : Pointer to channel number. */ 00384 /* i_channel specifies the address that will be filled */ 00385 /* in with the actual socket Id. */ 00386 /* */ 00387 /*+ pc_client : Pointer to structure s_tcpcomm. */ 00388 /* s_client specifies the address that will be filled */ 00389 /* in with the actual communication values. */ 00390 /* */ 00391 /* */ 00392 /*+ Return type : integer. */ 00393 /* */ 00394 /*2+DESCRIPTION***+***********+****************************************/ 00395 /* */ 00396 /*+ CALLING : f_stc_connectserver( CHARS c_node , INTS4 l_port , */ 00397 /* INTS4 pi_channel , */ 00398 /* struct s_tcpcomm ps_client ) */ 00399 /*+ ARGUMENTS : */ 00400 /* */ 00401 /*+ c_node : Name of server node */ 00402 /* */ 00403 /*+ l_port : Portnumber from server */ 00404 /* */ 00405 /*+ pi_channel : Pointer to channel number. */ 00406 /* i_channel specifies the address that will be filled */ 00407 /* in with the actual socket Id. */ 00408 /* */ 00409 /*+ ps_client : Pointer to structure s_tcpcomm. */ 00410 /* s_client specifies the address that will be filled */ 00411 /* in with the actual communication values. */ 00412 /* */ 00413 /*+ FUNCTION : f_stc_connectserver. connect a client process to a */ 00414 /* server process on node "c_node"*/ 00415 /* and port "l_port". */ 00416 /* f_stc_connectserver() modify */ 00417 /* the channel number and fill the*/ 00418 /* structure s_tcpcomm. */ 00419 /* The channel number is required */ 00420 /* to read and write data, to the */ 00421 /* connected server. */ 00422 /*+ REMARKS : - */ 00423 /* */ 00424 /*2+IMPLEMENTATION************+****************************************/ 00425 /* */ 00426 /*+ Input/Output: SYS$INPUT, SYS$OUTPUT */ 00427 /*+ Return type : INTEGER */ 00428 /*+ Status codes: */ 00429 /*- STC__SUCCESS : success. */ 00430 /*- STC__FAILURE : failure. */ 00431 /*- STC__INVADDRF: The specified address family is not */ 00432 /* supported. */ 00433 /*- STC__SOCKNSUP: The specified socket type is not */ 00434 /* supported. */ 00435 /*- STC__INVPROTO: The specified protocol is not */ 00436 /* supported. */ 00437 /*- STC__SOCKTABF: The per-process descriptor table */ 00438 /* is full. */ 00439 /*- STC__SOCKSPAF: No buffer space is available. The */ 00440 /* socket can't be created. */ 00441 /*- STC__INVSOCK : invalid socket number. */ 00442 /*- STC__NOTSOCK : socket number points to a file not a */ 00443 /* socket. */ 00444 /*- STC__SOCKISC : socket is already connected. */ 00445 /*- STC__CONNTOUT: connection timed out without */ 00446 /* establishing a connection. */ 00447 /*- STC__NETUNREA: The network is not reachable from */ 00448 /* this host. */ 00449 /*- STC__PORTINUS: The specified Internet Address and */ 00450 /* port is already in use. */ 00451 /*+ File name : */ 00452 /*+ Version : 1.01 */ 00453 /*+ Author : R.Fritzsche */ 00454 /*+ Last Update : 24-Jan-1994 */ 00455 /* */ 00456 /*2+UPDATES*******+***********+****************************************/ 00457 /* */ 00458 /*+ Updates : Date Purpose */ 00459 /* */ 00460 /*2+INTERNALS*****+***********+****************************************/ 00461 /* */ 00462 /*+ Utility : EXAMPLES */ 00463 /*+ Compile lib.: GOOINC.TLB */ 00464 /*+ Home direct.: GOO$EXAMPLES */ 00465 /*+ Created : 24-Jan-1994 */ 00466 /* */ 00467 /*1- PLI Main ****************+****************************************/ 00468 /* %%-HEAD: */ 00469 00470 INTS4 f_stc_connectserver(CHARS *c_node, INTS4 l_port, INTS4 *pi_channel, struct s_tcpcomm *ps_client) 00471 { 00472 INTS4 shut , retval ; 00473 INTS4 thirty = 30; 00474 struct s_tcpcomm s_client; 00475 00476 00477 /* ----------------------------------------------------------------------- */ 00478 /* init communication socket. */ 00479 /* ----------------------------------------------------------------------- */ 00480 00481 00482 #ifdef GSI__WINNT 00483 WORD wVersionRequested; 00484 WSADATA wsaData; 00485 char message1[512]; 00486 wVersionRequested = MAKEWORD( 2, 2 ); 00487 //err = WSAStartup( wVersionRequested, &wsaData ); 00488 if (WSAStartup( wVersionRequested, &wsaData)!=0) { 00489 printf("WinSock NOT found"); 00490 /* Tell the user that we could not find a usable */ 00491 /* WinSock DLL. */ 00492 } 00493 00494 if ( LOBYTE( wsaData.wVersion ) != 2 || 00495 HIBYTE( wsaData.wVersion ) != 2 ) { 00496 /* Tell the user that we could not find a usable */ 00497 /* WinSock DLL. 00498 */ 00499 printf("WinSock %d.%d",LOBYTE( wsaData.wVersion ),HIBYTE( wsaData.wVersion )); 00500 WSACleanup( ); 00501 } 00502 00503 #endif 00504 00505 s_client.socket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); 00506 00507 *ps_client = s_client; 00508 *pi_channel = s_client.socket; /* save channel also in case of error */ 00509 /* 17.7.95, H.G. */ 00510 switch( s_client.socket ) 00511 { 00512 case -1: 00513 switch( errno ) 00514 { 00515 case EAFNOSUPPORT : return STC__INVADDRF; 00516 case ESOCKTNOSUPPORT : return STC__SOCKNSUP; 00517 case EPROTONOSUPPORT : return STC__INVPROTO; 00518 case EMFILE : return STC__SOCKTABF; 00519 case ENOBUFS : return STC__SOCKSPAF; 00520 default : return STC__FAILURE; 00521 } /* switch( errno ) */ 00522 } /* switch( s_client.socket) */ 00523 00524 00525 if(( s_client.hostentptr = gethostbyname(c_node)) == NULL) 00526 { 00527 00528 #ifdef GSI__WINNT 00529 closesocket(s_client.socket); /* Mohammad Al-Turany 31.07.00*/ 00530 #else 00531 close(s_client.socket); /* close socket here and in any case! */ 00532 /* H.G., 17.7.95 */ 00533 #endif 00534 /* printf("--E--f_stc_connectserver(): error gethostbyname: >%s<\n",c_node);*/ 00535 return STC__FAILURE; 00536 } 00537 00538 00539 s_client.hostentstruct = *s_client.hostentptr; 00540 s_client.sock.sin_family = s_client.hostentstruct.h_addrtype; 00541 s_client.sock.sin_port = htons(l_port); 00542 s_client.sock.sin_addr = 00543 * ((struct in_addr *) s_client.hostentstruct.h_addr); 00544 00545 retval = connect( s_client.socket, 00546 ( struct sockaddr *) &s_client.sock, 00547 sizeof(s_client.sock)); 00548 if( retval == -1) 00549 { 00550 #ifdef GSI__WINNT 00551 closesocket(s_client.socket); /* Mohammad Al-Turany 31.07.00*/ 00552 #else 00553 close(s_client.socket); /* close socket here and in any case! */ 00554 /* H.G., 17.7.95 */ 00555 #endif 00556 switch( errno ) 00557 { 00558 case EBADF : return STC__INVSOCK; 00559 case ENOTSOCK : return STC__NOTSOCK; 00560 case EISCONN : return STC__SOCKISC; 00561 case ETIMEDOUT : return STC__CONNTOUT; 00562 case ENETUNREACH : return STC__NETUNREA; 00563 case EADDRINUSE : return STC__PORTINUS; 00564 case ECONNREFUSED : return STC__ECONNREF; 00565 default : return STC__FAILURE; 00566 } /* switch( errno ) */ 00567 } 00568 00569 *ps_client = s_client; 00570 00571 return STC__SUCCESS; 00572 00573 } /* f_stc_connectserver() */ 00574 00575 /* %%+HEAD: */ 00576 /*****************+***********+****************************************/ 00577 /* */ 00578 /* GSI, Gesellschaft fuer Schwerionenforschung mbH */ 00579 /* Postfach 11 05 41 */ 00580 /* D-6100 Darmstadt 11 */ 00581 /* */ 00582 /*1+ PLI Main ****************+****************************************/ 00583 /* */ 00584 /*+ Module : f_stc_acceptclient */ 00585 /* */ 00586 /*--------------------------------------------------------------------*/ 00587 /*+ CALLING : f_stc_acceptclient( struct s_tcpcomm s_server , */ 00588 /* INTS4 pi_channel ) */ 00589 /*--------------------------------------------------------------------*/ 00590 /* */ 00591 /*+ PURPOSE : f_stc_acceptclient. completes a connection between */ 00592 /* server and client. */ 00593 /* f_stc_acceptclient() modify the */ 00594 /* channel Id from the accepted */ 00595 /* client. The channel Id is */ 00596 /* required to read and write data */ 00597 /* to the client. */ 00598 /* */ 00599 /*+ ARGUMENTS : */ 00600 /* */ 00601 /*+ s_server : Pointer to structure s_tcpcomm. */ 00602 /* */ 00603 /*+ pi_channel : Id from the connected client. */ 00604 /* i_channel specifies the address that will be filled */ 00605 /* in with the actual client socket Id. */ 00606 /* */ 00607 /*+ Return type : integer. */ 00608 /* */ 00609 /*2+DESCRIPTION***+***********+****************************************/ 00610 /* */ 00611 /*+ CALLING : f_stc_acceptclient( struct s_tcpcomm s_server , */ 00612 /* INTS4 pi_channel ) */ 00613 /* */ 00614 /*+ PURPOSE : f_stc_acceptclient. completes a connection between */ 00615 /* server and client. */ 00616 /* f_stc_acceptclient() modify the */ 00617 /* channel Id from the accepted */ 00618 /* client. The channel Id is */ 00619 /* required to read and write data */ 00620 /* to the client. */ 00621 /* */ 00622 /*+ ARGUMENTS : */ 00623 /* */ 00624 /*+ s_server : Pointer to structure s_tcpcomm. */ 00625 /* */ 00626 /*+ pi_channel : Id from the connected client. */ 00627 /* i_channel specifies the address that will be filled */ 00628 /* in with the actual client socket id. */ 00629 /* */ 00630 /*+ Return type : integer. */ 00631 /* */ 00632 /*+ REMARKS : - */ 00633 /* */ 00634 /*2+IMPLEMENTATION************+****************************************/ 00635 /* */ 00636 /*+ Input/Output: SYS$INPUT, SYS$OUTPUT */ 00637 /*+ Return type : INTEGER */ 00638 /*+ Status codes: Status of last command */ 00639 /*- STC__SUCCESS : success. */ 00640 /*- STC__FAILURE : failure. */ 00641 /*- STC__INVSOCK : invalid socket number. */ 00642 /*- STC__NOTSOCK : socket number points to a file not */ 00643 /* a socket. */ 00644 /*+ File name : GOO$EXAMPLES: */ 00645 /*+ Version : 1.01 */ 00646 /*+ Author : R.Fritzsche */ 00647 /*+ Last Update : 25-Jan-1994 */ 00648 /* */ 00649 /*2+UPDATES*******+***********+****************************************/ 00650 /* */ 00651 /*+ Updates : Date Purpose */ 00652 /* */ 00653 /*2+INTERNALS*****+***********+****************************************/ 00654 /* */ 00655 /*+ Utility : EXAMPLES */ 00656 /*+ Compile lib.: GOOINC.TLB */ 00657 /*+ Home direct.: GOO$EXAMPLES */ 00658 /*+ Created : 15-Jan-1994 */ 00659 /* */ 00660 /*1- PLI Main ****************+****************************************/ 00661 /* %%-HEAD: */ 00662 00663 INTS4 f_stc_acceptclient(struct s_tcpcomm *ps_server, INTS4 *pi_channel) 00664 { 00665 INTS4 i_socket; 00666 struct hostent *he; 00667 00668 #ifdef GSI__AIX 00669 *pi_channel = accept( ps_server->sock_rw, 00670 ( struct sockaddr *) &ps_server->sock_name, 00671 (socklen_t *) &ps_server->namelength); 00672 #else 00673 *pi_channel = accept( ps_server->sock_rw, 00674 ( struct sockaddr *) &ps_server->sock_name, 00675 &ps_server->namelength); 00676 #endif 00677 if( *pi_channel == -1) 00678 { 00679 switch( errno ) 00680 { 00681 case EBADF : return STC__INVSOCK; 00682 case ENOTSOCK : return STC__NOTSOCK; 00683 default : return STC__FAILURE; 00684 } /* switch( errno ) */ 00685 } 00686 00687 /* 00688 hostname of remote node. 00689 he = gethostbyaddr( ps_server->sock_name.sin_addr.s_addr, 00690 sizeof(ps_server->sock_name.sin_addr.s_addr), 00691 AF_INET ); 00692 00693 if( he != NULL ) 00694 printf("name of client: %s\n",he->h_name); 00695 */ 00696 00697 return STC__SUCCESS; 00698 } /* end f_stc_acceptclient() */ 00699 00700 /* %%+HEAD: */ 00701 /*****************+***********+****************************************/ 00702 /* */ 00703 /* GSI, Gesellschaft fuer Schwerionenforschung mbH */ 00704 /* Postfach 11 05 41 */ 00705 /* D-6100 Darmstadt 11 */ 00706 /* */ 00707 /*1+ PLI Main ****************+****************************************/ 00708 /* */ 00709 /*+ Module : f_stc_createserver */ 00710 /* */ 00711 /*--------------------------------------------------------------------*/ 00712 /*+ CALLING : f_stc_createserver( INTS4 pl_port , */ 00713 /* struct s_tcpcomm ps_server ) */ 00714 /*--------------------------------------------------------------------*/ 00715 /* */ 00716 /*+ PURPOSE : f_stc_createserver creates an endpoint for */ 00717 /* client-server communications. */ 00718 /* The endpoint of communication */ 00719 /* data is not the process name. */ 00720 /* The client-server communication */ 00721 /* use portnumbers as endpoints of */ 00722 /* communications. */ 00723 /* The port numbers in the range */ 00724 /* 1 to 1023 are privileged ports. */ 00725 /* User can use ports in the range */ 00726 /* 1024 to 65535. */ 00727 /* also you can use portnumber 0, */ 00728 /* then f_stc_createserver() search*/ 00729 /* for a free portnumber and modify*/ 00730 /* the value from l_port, */ 00731 /* else f_stc_createserver() */ 00732 /* returns 0 */ 00733 /* */ 00734 /*+ ARGUMENTS : */ 00735 /* */ 00736 /*+ l_port : Pointer to Portnumber. ( 1024 - 65535 ) or ( 0 ). */ 00737 /* */ 00738 /*+ s_server : Pointer to structure s_tcpcomm */ 00739 /* s_server specifies the address that will be filled */ 00740 /* in with the actual communication values. */ 00741 /* */ 00742 /*+ Return type : integer. */ 00743 /* */ 00744 /*2+DESCRIPTION***+***********+****************************************/ 00745 /* */ 00746 /*+ CALLING : f_stc_createserver( INTS4 l_port , */ 00747 /* struct s_tcpcomm s_server) */ 00748 /* */ 00749 /*+ ARGUMENTS : */ 00750 /* */ 00751 /*+ l_port : Pointer to Portnumber. ( 1024 - 65535 ) or ( 0 ). */ 00752 /* l_port specifies the address that will be filled */ 00753 /* in with the actual server portnumber. */ 00754 /* */ 00755 /*+ S_SERVER : Pointer to structure s_tcpcomm */ 00756 /* s_server specifies the address that will be filled */ 00757 /* in with the actual communication values. */ 00758 /* */ 00759 /*+ FUNCTION : f_stc_createserver creates an endpoint for */ 00760 /* client - server communications. */ 00761 /* The endpoint of communication for */ 00762 /* data is not the a process name. */ 00763 /* The client - server communication */ 00764 /* use portnumbers as endpoints of */ 00765 /* communications. */ 00766 /* The port numbers in the range */ 00767 /* 1 to 1023 are privileged ports. */ 00768 /* User can use ports in the range */ 00769 /* 1024 to 65535. */ 00770 /* also you can use portnumber 0, */ 00771 /* then f_stc_createserver() search */ 00772 /* for a free portnumber and write */ 00773 /* the free portnumber to l_port, */ 00774 /* else f_stc_createserver() */ 00775 /* returns 0 */ 00776 /* */ 00777 /*+ REMARKS : - */ 00778 /* */ 00779 /*2+IMPLEMENTATION************+****************************************/ 00780 /* */ 00781 /*+ Input/Output: SYS$INPUT, SYS$OUTPUT */ 00782 /*+ Return type : INTEGER */ 00783 /*+ Status codes: */ 00784 /*- STC__SUCCESS : success. */ 00785 /*- STC__FAILURE : failure. */ 00786 /*- STC__INVADDRF : The specified address family is not */ 00787 /* supported. */ 00788 /*- STC__SOCKNSUP : The specified socket type is not */ 00789 /* supported. */ 00790 /*- STC__INVPROTO : The specified protocol is not */ 00791 /* supported. */ 00792 /*- STC__SOCKTABF : The per-process descriptor table */ 00793 /* is full. */ 00794 /*- STC__SOCKSPAF : No buffer space is available. */ 00795 /* The socket can't be created. */ 00796 /*- STC__INVSOCK : invalid socket number. */ 00797 /*- STC__NOTSOCK : socket number points to a file not */ 00798 /* a socket. */ 00799 /*- STC__PORTINUS : The specified Internet Address */ 00800 /* and port is already in use. */ 00801 /*- STC__SOCKISC : socket is already connected. */ 00802 /*- STC__SOCKISP : socket address is protected and the */ 00803 /* current user has inadequate */ 00804 /* permission to access it. */ 00805 /*+ File name : */ 00806 /*+ Version : 1.01 */ 00807 /*+ Author : R.Fritzsche */ 00808 /*+ Last Update : 25-Jan-1994 */ 00809 /* */ 00810 /*2+UPDATES*******+***********+****************************************/ 00811 /* */ 00812 /*+ Updates : Date Purpose */ 00813 /* */ 00814 /*2+INTERNALS*****+***********+****************************************/ 00815 /* */ 00816 /*+ Utility : EXAMPLES */ 00817 /*+ Compile lib.: GOOINC.TLB */ 00818 /*+ Home direct.: GOO$EXAMPLES */ 00819 /*+ Created : 25-Jan-1994 */ 00820 /* */ 00821 /*1- PLI Main ****************+****************************************/ 00822 /* %%-HEAD: */ 00823 00824 INTS4 f_stc_createserver(INTS4 *pl_port, struct s_tcpcomm *ps_server) 00825 { 00826 00827 INTS4 retval , i , retry , on ; 00828 struct protoent *p; 00829 struct s_tcpcomm s_server; 00830 00831 00832 #ifdef GSI__WINNT 00833 WORD wVersionRequested; 00834 WSADATA wsaData; 00835 char message1[512]; 00836 wVersionRequested = MAKEWORD( 2, 2 ); 00837 //err = WSAStartup( wVersionRequested, &wsaData ); 00838 if (WSAStartup( wVersionRequested, &wsaData)!=0) { 00839 printf("WinSock NOT found"); 00840 /* Tell the user that we could not find a usable */ 00841 /* WinSock DLL. */ 00842 } 00843 00844 if ( LOBYTE( wsaData.wVersion ) != 2 || 00845 HIBYTE( wsaData.wVersion ) != 2 ) { 00846 /* Tell the user that we could not find a usable */ 00847 /* WinSock DLL. 00848 */ 00849 printf("WinSock %d.%d",LOBYTE( wsaData.wVersion ),HIBYTE( wsaData.wVersion )); 00850 WSACleanup( ); 00851 } 00852 00853 #endif 00854 00855 on = 1; 00856 00857 if( *pl_port == 0 ) { 00858 retry = 1 ; 00859 *pl_port = 1024; 00860 } 00861 else 00862 retry = 0; 00863 00864 s_server.sock_rw = socket (AF_INET, SOCK_STREAM, IPPROTO_TCP); 00865 00866 switch( s_server.sock_rw ) 00867 { 00868 case -1: 00869 switch( errno ) 00870 { 00871 case EAFNOSUPPORT : return STC__INVADDRF; 00872 case ESOCKTNOSUPPORT : return STC__SOCKNSUP; 00873 case EPROTONOSUPPORT : return STC__INVPROTO; 00874 case EMFILE : return STC__SOCKTABF; 00875 case ENOBUFS : return STC__SOCKSPAF; 00876 default : return STC__FAILURE; 00877 } /* switch( errno ) */ 00878 } /* switch( s_server.sock_rw) */ 00879 00880 00881 retval = gethostname(s_server.hostname,sizeof(s_server.hostname)); 00882 if(retval) 00883 { 00884 printf("--E--f_stc_createserver() error get local hostname\n"); 00885 return STC__FAILURE; 00886 } 00887 00888 if((s_server.hostentptr = gethostbyname (s_server.hostname)) == NULL) 00889 { 00890 printf("--E--f_stc_createserver() error get local Internet address\n"); 00891 return STC__FAILURE; 00892 } 00893 00894 bzero( (CHARS *) &s_server.sock_name , sizeof( s_server.sock_name ) ); 00895 s_server.sock_name.sin_family = AF_INET; 00896 s_server.sock_name.sin_addr.s_addr = htonl(INADDR_ANY); 00897 s_server.sock_name.sin_port = htons(*pl_port); 00898 00899 retval = bind( s_server.sock_rw, 00900 (struct sockaddr *) &s_server.sock_name, 00901 sizeof(s_server.sock_name)); 00902 00903 if( retval == -1 && retry == 0 ) 00904 { 00905 close( s_server.sock_rw ); 00906 00907 switch( errno ) 00908 { 00909 case EBADF : return STC__INVSOCK; 00910 case ENOTSOCK : return STC__NOTSOCK; 00911 case EADDRINUSE : return STC__PORTINUS; 00912 case EINVAL : return STC__SOCKISC; 00913 case EACCES : return STC__SOCKISP; 00914 default : return STC__FAILURE; 00915 } 00916 } 00917 00918 retval = -1; 00919 00920 while ( retval == -1 && retry == 1 ) 00921 { 00922 00923 s_server.sock_rw = socket (AF_INET, SOCK_STREAM, IPPROTO_TCP); 00924 00925 switch( s_server.sock_rw ) 00926 { 00927 case -1: 00928 switch( errno ) 00929 { 00930 case EAFNOSUPPORT : return STC__INVADDRF; 00931 case ESOCKTNOSUPPORT : return STC__SOCKNSUP; 00932 case EPROTONOSUPPORT : return STC__INVPROTO; 00933 case EMFILE : return STC__SOCKTABF; 00934 case ENOBUFS : return STC__SOCKSPAF; 00935 default : return STC__FAILURE; 00936 } 00937 } 00938 00939 retval = gethostname(s_server.hostname,sizeof(s_server.hostname)); 00940 if(retval) 00941 { 00942 printf("--E--f_stc_createserver() error get local hostname\n"); 00943 return STC__FAILURE; 00944 } 00945 00946 00947 if((s_server.hostentptr = gethostbyname (s_server.hostname)) == NULL) 00948 { 00949 printf("--E--f_stc_createserver() error get local Internet address\n"); 00950 return STC__FAILURE; 00951 } 00952 00953 retval = -1; 00954 00955 bzero( (CHARS *) &s_server.sock_name , sizeof( s_server.sock_name ) ); 00956 s_server.sock_name.sin_family = AF_INET; 00957 s_server.sock_name.sin_addr.s_addr = htonl(INADDR_ANY); 00958 s_server.sock_name.sin_port = htons(*pl_port); 00959 00960 retval = bind( s_server.sock_rw, 00961 (struct sockaddr *) &s_server.sock_name, 00962 sizeof(s_server.sock_name)); 00963 if( retval == -1 ) 00964 { 00965 close( s_server.sock_rw ); 00966 00967 *pl_port += 1; 00968 00969 if( *pl_port > 65535 ) 00970 { 00971 printf("--E--f_stc_createserver() portnumber exceeded > 655535\n"); 00972 00973 switch( errno ) 00974 { 00975 case EBADF : return STC__INVSOCK; 00976 case ENOTSOCK : return STC__NOTSOCK; 00977 case EADDRINUSE : return STC__PORTINUS; 00978 case EINVAL : return STC__SOCKISC; 00979 case EACCES : return STC__SOCKISP; 00980 default : return STC__FAILURE; 00981 } /* end switch( errno ) */ 00982 00983 } /* end if *pl_port > ... ) */ 00984 00985 } /* end if (retval == -1 ) */ 00986 00987 00988 } 00989 00990 retval = listen(s_server.sock_rw,5); 00991 if( retval == -1 ) 00992 { 00993 switch( errno ) 00994 { 00995 case EBADF : return STC__INVSOCK; 00996 case ENOTSOCK : return STC__NOTSOCK; 00997 default : return STC__FAILURE; 00998 } 00999 } 01000 01001 s_server.namelength = sizeof( s_server.sock_name); 01002 01003 *ps_server = s_server; 01004 01005 return STC__SUCCESS; 01006 } /* end f_stc_createserver() */ 01007 01008 /* %%+HEAD: */ 01009 /*****************+***********+****************************************/ 01010 /* */ 01011 /* GSI, Gesellschaft fuer Schwerionenforschung mbH */ 01012 /* Postfach 11 05 41 */ 01013 /* D-6100 Darmstadt 11 */ 01014 /* */ 01015 /*1+ PLI Main ****************+****************************************/ 01016 /* */ 01017 /*+ Module : f_stc_close */ 01018 /* */ 01019 /*--------------------------------------------------------------------*/ 01020 /*+ CALLING : f_stc_close( struct s_tcpcomm ps_tcp ) */ 01021 /*--------------------------------------------------------------------*/ 01022 /* */ 01023 /*+ PURPOSE : f_stc_close close the client server */ 01024 /* communication. */ 01025 /* */ 01026 /*+ ARGUMENTS : */ 01027 /* */ 01028 /*+ S_TCP : Pointer to structure s_tcpcomm. */ 01029 /* */ 01030 /*+ Return type : integer. */ 01031 /* */ 01032 /*2+DESCRIPTION***+***********+****************************************/ 01033 /* */ 01034 /*+ CALLING : f_stc_close( struct s_tcpcomm ps_tcp ) */ 01035 /* */ 01036 /*+ ARGUMENTS : */ 01037 /* */ 01038 /*+ FUNCTION : f_stc_close close the client server */ 01039 /* communication. */ 01040 /* */ 01041 /*+ S_TCP : Pointer to structure s_tcpcomm. */ 01042 /* */ 01043 /*+ REMARKS : - */ 01044 /* */ 01045 /*2+IMPLEMENTATION************+****************************************/ 01046 /* */ 01047 /*+ Input/Output: SYS$INPUT, SYS$OUTPUT */ 01048 /*+ Return type : INTEGER */ 01049 /*+ File name : */ 01050 /*+ Version : 1.01 */ 01051 /*+ Author : R.Fritzsche */ 01052 /*+ Last Update : 25-Jan-1994 */ 01053 /* */ 01054 /*2+UPDATES*******+***********+****************************************/ 01055 /* */ 01056 /*+ Updates : Date Purpose */ 01057 /* */ 01058 /*2+INTERNALS*****+***********+****************************************/ 01059 /* */ 01060 /*+ Utility : EXAMPLES */ 01061 /*+ Compile lib.: GOOCINC.TLB */ 01062 /*+ Home direct.: GOO$EXAMPLES */ 01063 /*+ Created : 25-Jan-1994 */ 01064 /* */ 01065 /*1- PLI Main ****************+****************************************/ 01066 /* %%-HEAD: */ 01067 01068 INTS4 f_stc_close(struct s_tcpcomm * ps_tcp) 01069 { 01070 INTS4 retval; 01071 01072 if( ps_tcp->socket ) 01073 { 01074 retval = shutdown( ps_tcp->socket,2); 01075 if(retval == -1) { 01076 return STC__FAILURE; 01077 } 01078 retval = close(ps_tcp->socket); 01079 if(retval == -1) { 01080 return STC__FAILURE; 01081 } 01082 01083 return STC__SUCCESS; 01084 } 01085 01086 return STC__FAILURE; 01087 } /* f_stc_close() */ 01088 01089 /* %%+HEAD: */ 01090 /*****************+***********+****************************************/ 01091 /* */ 01092 /* GSI, Gesellschaft fuer Schwerionenforschung mbH */ 01093 /* Postfach 11 05 41 */ 01094 /* D-6100 Darmstadt 11 */ 01095 /* */ 01096 /*1+ PLI Main ****************+****************************************/ 01097 /* */ 01098 /*+ Module : f_stc_discclient */ 01099 /* */ 01100 /*--------------------------------------------------------------------*/ 01101 /*+ CALLING : f_stc_discclient( INTS4 i_channel ) */ 01102 /*--------------------------------------------------------------------*/ 01103 /* */ 01104 /*+ PURPOSE : f_stc_discclient close the specified client */ 01105 /* server communication. */ 01106 /* */ 01107 /*+ ARGUMENTS : */ 01108 /* */ 01109 /*+ I_CHANNEL : Channel Id from the specified client. */ 01110 /* */ 01111 /*+ Return type : integer. */ 01112 /* */ 01113 /*2+DESCRIPTION***+***********+****************************************/ 01114 /* */ 01115 /*+ CALLING : f_stc_discclient( INTS4 i_channel ) */ 01116 /* */ 01117 /*+ ARGUMENTS : */ 01118 /* */ 01119 /*+ FUNCTION : f_stc_discclient close the specified client */ 01120 /* server communication. */ 01121 /* */ 01122 /*+ I_CHANNEL : Channel Id from the specified client. */ 01123 /* */ 01124 /*+ REMARKS : - */ 01125 /* */ 01126 /*2+IMPLEMENTATION************+****************************************/ 01127 /* */ 01128 /*+ Input/Output: SYS$INPUT, SYS$OUTPUT */ 01129 /*+ Return type : INTEGER */ 01130 /*+ File name : */ 01131 /*+ Version : 1.01 */ 01132 /*+ Author : R.Fritzsche */ 01133 /*+ Last Update : 01-Mar-1994 */ 01134 /* */ 01135 /*2+UPDATES*******+***********+****************************************/ 01136 /* */ 01137 /*+ Updates : Date Purpose */ 01138 /* */ 01139 /*2+INTERNALS*****+***********+****************************************/ 01140 /* */ 01141 /*+ Utility : EXAMPLES */ 01142 /*+ Compile lib.: */ 01143 /*+ Home direct.: */ 01144 /*+ Created : 01-Mar-1994 */ 01145 /* */ 01146 /*1- PLI Main ****************+****************************************/ 01147 /* %%-HEAD: */ 01148 01149 INTS4 f_stc_discclient(INTS4 i_channel) 01150 { 01151 INTS4 retval; 01152 01153 /* call of shutdown removed 17.7.95, H.G. */ 01154 retval = close( i_channel ); 01155 if(retval == -1) 01156 return STC__FAILURE; 01157 01158 return STC__SUCCESS; 01159 } /* f_stc_discclient() */ 01160 01161 /* %%+HEAD: */ 01162 /*****************+***********+****************************************/ 01163 /* */ 01164 /* GSI, Gesellschaft fuer Schwerionenforschung mbH */ 01165 /* Postfach 11 05 41 */ 01166 /* D-6100 Darmstadt 11 */ 01167 /* */ 01168 /*1+ PLI Main ****************+****************************************/ 01169 /* */ 01170 /*+ Module : f_stc_listenserver */ 01171 /* */ 01172 /*--------------------------------------------------------------------*/ 01173 /*+ CALLING : f_stc_listenserver( struct s_tcpcomm ps_server ) */ 01174 /*--------------------------------------------------------------------*/ 01175 /* */ 01176 /*+ PURPOSE : f_stc_listenserver look for a pending client */ 01177 /* connection on the specified */ 01178 /* server. */ 01179 /* */ 01180 /*+ ARGUMENTS : */ 01181 /* */ 01182 /*+ PS_SERVER : Pointer to structure s_tcpcomm. */ 01183 /* */ 01184 /*+ Return type : integer. */ 01185 /* */ 01186 /*2+DESCRIPTION***+***********+****************************************/ 01187 /* */ 01188 /*+ CALLING : f_stc_listenserver( struct s_tcpcomm ps_server ) */ 01189 /* */ 01190 /*+ ARGUMENTS : */ 01191 /* */ 01192 /*+ FUNCTION : f_stc_listenserver look for a pending client */ 01193 /* connection on the specified */ 01194 /* server. */ 01195 /* */ 01196 /*+ PS_SERVER : Pointer to structure s_tcpcomm. */ 01197 /* */ 01198 /*+ REMARKS : - */ 01199 /* */ 01200 /*2+IMPLEMENTATION************+****************************************/ 01201 /* */ 01202 /*+ Input/Output: SYS$INPUT, SYS$OUTPUT */ 01203 /*+ Return type : INTEGER */ 01204 /*+ Status codes: */ 01205 /*- STC__SUCCESS : success. */ 01206 /*- STC__FAIlURE : failure. */ 01207 /*- STC__INVSOCK : invalid socket number. */ 01208 /*- STC__TIMEOUT : timeout. */ 01209 /*- STC__INVTIME : time limit is unacceptable */ 01210 /* negativ or to long. */ 01211 /*+ File name : */ 01212 /*+ Version : 1.01 */ 01213 /*+ Author : R.Fritzsche */ 01214 /*+ Last Update : 25-Jan-1994 */ 01215 /* */ 01216 /*2+UPDATES*******+***********+****************************************/ 01217 /* */ 01218 /*+ Updates : Date Purpose */ 01219 /* */ 01220 /*2+INTERNALS*****+***********+****************************************/ 01221 /* */ 01222 /*+ Utility : EXAMPLES */ 01223 /*+ Compile lib.: GOOCINC.TLB */ 01224 /*+ Home direct.: GOO$EXAMPLES */ 01225 /*+ Created : 25-Jan-1994 */ 01226 /* */ 01227 /*1- PLI Main ****************+****************************************/ 01228 /* %%-HEAD: */ 01229 01230 INTS4 f_stc_listenserver(struct s_tcpcomm *ps_server) 01231 { 01232 struct timeval read_timeout; 01233 fd_set rset , allset , wset , eset; 01234 INTS4 listenfd , maxfd , sts; 01235 01236 read_timeout.tv_sec = 0; 01237 read_timeout.tv_usec = 0; 01238 01239 listenfd = ps_server->sock_rw; 01240 01241 FD_ZERO(&rset); 01242 FD_ZERO(&wset); 01243 FD_ZERO(&eset); 01244 FD_ZERO(&allset); 01245 FD_SET(listenfd,&rset); 01246 FD_SET(listenfd,&wset); 01247 FD_SET(listenfd,&eset); 01248 maxfd = listenfd; 01249 01250 sts = select( maxfd + 1 , &rset , 01251 &wset , 01252 &eset , &read_timeout); 01253 switch( sts ) 01254 { 01255 case -1: 01256 switch( errno ) 01257 { 01258 case EBADF : return STC__INVSOCK; 01259 case EINVAL : return STC__INVTIME; 01260 default : return STC__FAILURE; 01261 } /* switch( errno ) */ 01262 01263 case 0: return STC__TIMEOUT; 01264 01265 } /* end switch( sts ) */ 01266 01267 if( FD_ISSET(listenfd,&eset)) { 01268 return STC__SUCCESS; 01269 } 01270 01271 if( FD_ISSET(listenfd,&rset)) { 01272 return STC__SUCCESS; 01273 } 01274 01275 if( FD_ISSET(listenfd,&wset)) { 01276 return STC__SUCCESS; 01277 } 01278 01279 return STC__FAILURE; 01280 } 01281 01282 01283 /* %%+HEAD: */ 01284 /*****************+***********+****************************************/ 01285 /* */ 01286 /* GSI, Gesellschaft fuer Schwerionenforschung mbH */ 01287 /* Postfach 11 05 41 */ 01288 /* D-6100 Darmstadt 11 */ 01289 /* */ 01290 /*1+ PLI Main ****************+****************************************/ 01291 /* */ 01292 /*+ Module : f_stc_disperror */ 01293 /* */ 01294 /*--------------------------------------------------------------------*/ 01295 /*+ CALLING : f_stc_disperror( INTS4 i_error , CHARS c_string[256], */ 01296 /* INTS4 i_out ) */ 01297 /*--------------------------------------------------------------------*/ 01298 /* */ 01299 /*+ PURPOSE : f_stc_disperror displays the error message for the */ 01300 /* error id ( i_error ) */ 01301 /* if i_out = 1 the error message is */ 01302 /* copied into c_string, else */ 01303 /* f_stc_disperror() print the message */ 01304 /* on the terminal. */ 01305 /* */ 01306 /*+ ARGUMENTS : */ 01307 /* */ 01308 /*+ I_ERROR : The error id. */ 01309 /* */ 01310 /*+ C_STRING : The string into f_stc_disperror() copies the */ 01311 /* message. */ 01312 /* */ 01313 /*+ I_OUT : specifies the output device for the error message. */ 01314 /* */ 01315 /*- I_OUT = 1 : the error message is copied into */ 01316 /* the string. */ 01317 /*- I_OUT = 0 : the error message is printed on */ 01318 /* the terminal. */ 01319 /* */ 01320 /*+ Return type : integer. */ 01321 /* */ 01322 /*2+DESCRIPTION***+***********+****************************************/ 01323 /* */ 01324 /*+ CALLING : f_stc_disperror( INTS4 i_error , CHARS c_string[256], */ 01325 /* INTS4 i_out ) */ 01326 /* */ 01327 /*+ ARGUMENTS : */ 01328 /* */ 01329 /*+ I_ERROR : The error id. */ 01330 /* */ 01331 /*+ C_STRING : The string into f_stc_disperror() copies the */ 01332 /* message. */ 01333 /* */ 01334 /*+ I_OUT : specifies the output device for the error message. */ 01335 /* */ 01336 /*- I_OUT = 1 : the error message is copied into the */ 01337 /* string. */ 01338 /*- I_OUT = 0 : the error message is printed on the */ 01339 /* terminal. */ 01340 /* */ 01341 /*+ FUNCTION : f_stc_disperror displays the error message for the */ 01342 /* error id ( i_error ) */ 01343 /* if i_out = 1 the error message is */ 01344 /* copied into c_string, else */ 01345 /* f_stc_disperror() print the message */ 01346 /* on the terminal. */ 01347 /* */ 01348 /*+ REMARKS : - */ 01349 /* */ 01350 /*2+IMPLEMENTATION************+****************************************/ 01351 /* */ 01352 /*+ Input/Output: SYS$INPUT, SYS$OUTPUT */ 01353 /*+ Return type : INTEGER */ 01354 /*+ Status codes: */ 01355 /*- STC__SUCCESS : success. */ 01356 /*- STC__FAIlURE : failure. */ 01357 /*+ File name : */ 01358 /*+ Version : 1.01 */ 01359 /*+ Author : R.Fritzsche */ 01360 /*+ Last Update : 28-Jan-1994 */ 01361 /* */ 01362 /*2+UPDATES*******+***********+****************************************/ 01363 /* */ 01364 /*+ Updates : Date Purpose */ 01365 /* */ 01366 /*2+INTERNALS*****+***********+****************************************/ 01367 /* */ 01368 /*+ Utility : EXAMPLES */ 01369 /*+ Compile lib.: GOOCINC.TLB */ 01370 /*+ Home direct.: GOO$EXAMPLES */ 01371 /*+ Created : 28-Jan-1994 */ 01372 /* */ 01373 /*1- PLI Main ****************+****************************************/ 01374 /* %%-HEAD: */ 01375 01376 INTS4 f_stc_disperror(INTS4 i_error, CHARS *c_dest, INTS4 i_out) 01377 { 01378 CHARS c_line[80]; 01379 01380 switch( i_error ) 01381 { 01382 case STC__FAILURE : 01383 sprintf(c_line,"-I- f_stc failure"); 01384 break; 01385 case STC__SUCCESS : 01386 sprintf(c_line,"-I- f_stc failure"); 01387 break; 01388 case STC__INVSOCK : 01389 sprintf(c_line,"-I- f_stc invalid socket number"); 01390 break; 01391 case STC__INVBUF : 01392 sprintf(c_line,"-I- f_stc buffer points outside allocated address space"); 01393 break; 01394 case STC__NGBUFSIZE : 01395 sprintf(c_line,"-I- f_stc buffer length is negative"); 01396 break; 01397 case STC__INVTIME : 01398 sprintf(c_line,"-I- f_stc time limit is negativ or to long"); 01399 break; 01400 case STC__TIMEOUT : 01401 sprintf(c_line,"-I- f_stc timeout read data from socket"); 01402 break; 01403 case STC__NOTSOCK : 01404 sprintf(c_line,"-I- f_stc socket number points to a file not a socket"); 01405 break; 01406 case STC__INVADDR : 01407 sprintf(c_line,"-I- f_stc invalid address specified in parameter"); 01408 break; 01409 case STC__INVADDRF : 01410 sprintf(c_line,"-I- f_stc the specified address family is not supported"); 01411 break; 01412 case STC__SOCKNSUP : 01413 sprintf(c_line,"-I- f_stc The specified socket type is not supported."); 01414 break; 01415 case STC__INVPROTO : 01416 sprintf(c_line,"-I- f_stc The specified protocol is not supported."); 01417 break; 01418 case STC__SOCKTABF : 01419 sprintf(c_line,"-I- f_stc The per-process descriptor table is full."); 01420 break; 01421 case STC__SOCKSPAF : 01422 sprintf(c_line,"-I- f_stc No buffer space is available. The socket can't be created"); 01423 break; 01424 case STC__SOCKISC : 01425 sprintf(c_line,"-I- f_stc socket is already connected."); 01426 break; 01427 case STC__CONNTOUT : 01428 sprintf(c_line,"-I- f_stc connection timed out without establishing a connection."); 01429 break; 01430 case STC__NETUNREA : 01431 sprintf(c_line,"-I- f_stc The network is not reachable from this host."); 01432 break; 01433 case STC__PORTINUS : 01434 sprintf(c_line,"-I- f_stc The specified Internet Address and port is already in use."); 01435 break; 01436 case STC__SOCKISP : 01437 sprintf(c_line,"-I- f_stc socket address is protected."); 01438 break; 01439 case STC__ECONNREF : /* added 17.7.95, H.G. */ 01440 sprintf(c_line,"-I- f_stc connection refused."); 01441 break; 01442 case TPS__ECPORTS : 01443 sprintf(c_line,"-I- f_stc error connect portserver"); 01444 break; 01445 case TPS__EREGSERV : 01446 sprintf(c_line,"-I- f_stc error register service at portserver"); 01447 break; 01448 case TPS__EWTOPORTS : 01449 sprintf(c_line,"-I- f_stc error write buffer to portserver"); 01450 break; 01451 case TPS__ERMFRPORTS : 01452 sprintf(c_line,"-I- f_stc error read status message from portserver"); 01453 break; 01454 case TPS__EGSERVICE : 01455 sprintf(c_line,"-I- f_stc error get spec. info from portserver"); 01456 break; 01457 default: 01458 sprintf(c_line,"-I- f_stc unknown message id %d",i_error); 01459 if(i_out==0)printf("%s\n",c_line); 01460 if(i_out==1)strcpy(c_dest,c_line); 01461 return STC__FAILURE; 01462 } /* end switch( i_error ) */ 01463 01464 if(i_out==0) printf("%s\n",c_line); 01465 if(i_out==1) strcpy(c_dest,c_line); 01466 01467 return STC__SUCCESS; 01468 } /* f_stc_disperror() */