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