Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

/MbsAPI/f_stccomm.c

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

Generated on Tue Nov 8 10:56:08 2005 for Go4-v2.10-5 by doxygen1.2.15