GSI Object Oriented Online Offline (Go4)  GO4-6.1.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
f_stccomm.c
Go to the documentation of this file.
1 // $Id: f_stccomm.c 3326 2021-10-18 10:19:10Z linev $
2 //-----------------------------------------------------------------------
3 // The GSI Online Offline Object Oriented (Go4) Project
4 // Experiment Data Processing at EE department, GSI
5 //-----------------------------------------------------------------------
6 // Copyright (C) 2000- GSI Helmholtzzentrum fuer Schwerionenforschung GmbH
7 // Planckstr. 1, 64291 Darmstadt, Germany
8 // Contact: http://go4.gsi.de
9 //-----------------------------------------------------------------------
10 // This software can be used under the license agreements as stated
11 // in Go4License.txt file which is part of the distribution.
12 //-----------------------------------------------------------------------
13 
14 #include "f_stccomm.h"
15 
16 // JAM1-6-2021- test if this helps the streamserver problems
17 // #define DISABLE_POLLING_TIMEOUT 1
18 
19 
20 
22 /*#define DEBUG 1*/
23 
24 /* %%+HEAD: */
25 /*****************+***********+****************************************/
26 /* */
27 /* GSI, Gesellschaft fuer Schwerionenforschung mbH */
28 /* Postfach 11 05 41 */
29 /* D-6100 Darmstadt 11 */
30 /* */
31 /*1+ PLI Main ****************+****************************************/
32 /* */
33 /*+ Module : f_stc_read */
34 /* */
35 /*--------------------------------------------------------------------*/
36 /*+ CALLING : f_stc_read( INTS1 p_buffer , INTS4 i_buflen , */
37 /* INTS4 i_channel , INTS4 i_timeout ) */
38 /* */
39 /*--------------------------------------------------------------------*/
40 /* */
41 /*+ PURPOSE : f_stc_read read bytes from a connected socket */
42 /* and places them in a buffer (p_buffer). */
43 /* */
44 /*+ ARGUMENTS : */
45 /* */
46 /*+ p_buffer : Pointer to free data buffer. */
47 /* */
48 /*+ i_buflen : buffer length. */
49 /* */
50 /*+ i_channel : Id from the connected socket. */
51 /* */
52 /*+ i_timeout : Timeout value ( seconds ) for read from socket. */
53 /*- i_timeout = 0 : Return immediately after */
54 /* checking the connected socket. */
55 /*- i_timeout > 0 : Return when the specified socket */
56 /* is ready for I/O, but don't wait */
57 /* beyond a fixed amount of time. */
58 /*- i_timeout = -1 : Return only when the specified */
59 /* socket is ready for I/O. */
60 /* */
61 /*+ Return type : integer. */
62 /* */
63 /*2+DESCRIPTION***+***********+****************************************/
64 /* */
65 /*+ CALLING : f_stc_read ( INTS1 p_buffer , INTS4 i_buflen , */
66 /* INTS4 i_channel , INTS4 i_timeout ) */
67 /* */
68 /*+ ARGUMENTS : */
69 /* */
70 /*+ p_buffer : Pointer to free data buffer. */
71 /* */
72 /*+ i_buflen : buffer length. */
73 /* */
74 /*+ i_channel : Id from the connected socket. */
75 /* */
76 /*+ i_timeout : Timeout value ( seconds ) for read from socket. */
77 /* */
78 /*- i_timeout = 0 : Return immediately after checking */
79 /* the connected socket. */
80 /*- i_timeout > 0 : Return when the specified socket */
81 /* is ready for I/O, but don't wait */
82 /* beyond a fixed amount of time. */
83 /*- i_timeout = -1 : Return only when the specified */
84 /* socket is ready for I/O. */
85 /* */
86 /*+ FUNCTION : Read bytes from a connected socket and places them */
87 /* in a buffer (p_buffer) */
88 /* The procedure f_stc_read wait max timeout seconds */
89 /* getting data from the socket. */
90 /* */
91 /*+ REMARKS : - */
92 /* */
93 /*2+IMPLEMENTATION************+****************************************/
94 /* */
95 /*+ Input/Output: SYS$INPUT, SYS$OUTPUT */
96 /*+ Return type : INTEGER */
97 /*+ Status codes: */
98 /*- STC__SUCCESS : success. */
99 /*- STC__FAIlURE : failure. */
100 /*- STC__INVSOCK : invalid socket number. */
101 /*- STC__INVBUF : buffer points outside allocated */
102 /* adress space. */
103 /*- STC__NGBUFSIZE : buffer length is negative. */
104 /*- STC__INVTIME : time limit is unacceptable negativ */
105 /* or to long. */
106 /*- STC__TIMEOUT : timeout read from socket. */
107 /*+ File name : */
108 /*+ Version : 1.01 */
109 /*+ Author : R.Fritzsche */
110 /*+ Last Update : 17-Jul-1995 */
111 /* */
112 /*2+UPDATES*******+***********+*********************************************/
113 /* */
114 /*+ Updates : Date Purpose */
115 /*- 17-Jul-1995 : f_stc_connectserver H.G. */
116 /* close socket in case of failure to avoid */
117 /* hanging sockets */
118 /*- 17-Jul-1995 : f_stc_discclient H.G. */
119 /* remove shutdown (which didn't work and */
120 /* inibited close) and make close in any case */
121 /*- 17-Jul-1995 : f_stc_disperror H.G. */
122 /* new message no.: STC__ECONNREF */
123 /* */
124 /*2+INTERNALS*****+***********+*********************************************/
125 /* */
126 /*+ Utility : EXAMPLES */
127 /*+ Compile lib.: GOOINC.TLB */
128 /*+ Home direct.: GOO$EXAMPLES */
129 /*+ Created : 25-Jan-1994 */
130 /* */
131 /*1- PLI Main ****************+****************************************/
132 /* %%-HEAD: */
133 
134 INTS4 f_stc_read(void *p_buffer, INTS4 i_buflen, INTS4 i_channel, INTS4 i_timeout)
135 {
136  INTS4 retval , buflen_tmp;
137  INTS1 *p_buffer_tmp;
138  INTS4 i_retry = 0;
139  struct timeval read_timeout;
140  fd_set xrmask,xwmask,xemask;
141  INTS4 num_of_bytes_read = 0;
142 
143  buflen_tmp = i_buflen;
144  p_buffer_tmp = (INTS1*) p_buffer; /* actual pointer to buffer */
145 
146  FD_ZERO(&xrmask);
147  FD_ZERO(&xemask);
148  FD_ZERO(&xwmask);
149  FD_SET(i_channel,&xrmask);
150  read_timeout.tv_sec = i_timeout;
151  read_timeout.tv_usec = 0;
152 
153  // JAM1-6-2021- test if this helps the streamserver problems
154 #ifndef DISABLE_POLLING_TIMEOUT
155  if (i_timeout == 555555) {
156  read_timeout.tv_sec = 0;
157  read_timeout.tv_usec = 50000; // 0.05 sec
158  }
159 #endif
160 
161 #ifdef DEBUG
162  printf("STC: read %6d bytes channel %d ",i_buflen,i_channel);fflush(stdout);
163 #endif
164  while( num_of_bytes_read < i_buflen && buflen_tmp > 0 )
165  {
166  if( i_timeout >= 0 )
167  {
168  /*
169 #ifdef GSI__AIX
170  retval = select(32,&xrmask,&xwmask,&xemask,&read_timeout);
171 #else
172  retval = select(32,&rmask,&wmask,&emask,&read_timeout);
173 #endif
174  */
175 
176  /* Changed by S.Linev, 18.09.2007 */
177  // retval = select(32,(fd_set*) &rmask, (fd_set*) &wmask, (fd_set*) &emask,&read_timeout);
178  retval = select(i_channel+1, &xrmask, &xwmask, &xemask, &read_timeout);
179 
180  switch( retval )
181  {
182  case -1:
183  switch( errno )
184  {
185  case EBADF : return STC__INVSOCK;
186  case EINVAL : return STC__INVTIME;
187  case EINTR : continue;
188  case ECONNRESET : return STC__ECONNRES;
189  default : sprintf(c_msg,"STC select error channel %d",i_channel);
190  perror(c_msg);
191  return STC__FAILURE;
192  }
193  case 0: return STC__TIMEOUT;
194  }
195  }
196  /* ------------------------------------------------------- */
197  /* read data from the connect socket. */
198  /* ------------------------------------------------------- */
199 #ifdef DEBUG
200  printf("read ");fflush(stdout);
201 #endif
202 #ifdef GSI__WINNT
203  retval = recv(i_channel, p_buffer_tmp, buflen_tmp, 0); /* Mohammad Al-Turany 31.07.00 */
204 #else
205  retval = read(i_channel, p_buffer_tmp, buflen_tmp);
206 #endif
207  if( retval == -1 )
208  {
209  switch( errno )
210  {
211  case EBADF : return STC__INVSOCK;
212  case EFAULT : return STC__INVBUF;
213  case EINVAL : return STC__NGBUFSIZE;
214  case EINTR : return STC__EINTR;
215  case ECONNRESET : return STC__ECONNRES;
216  default : sprintf(c_msg,"STC read error channel %d",i_channel);
217  perror(c_msg);
218  return STC__FAILURE;
219  } /* switch( errno ) */
220 
221  } /* if( retval == -1 ) */
222 
223  /* ------------------------------------------------------- */
224  /* set the num of bytes to read in the next */
225  /* read statement. */
226  /* ------------------------------------------------------- */
227 
228  num_of_bytes_read += retval;
229  buflen_tmp -= retval;
230  p_buffer_tmp += retval; /* calc actual pointer */
231  if( ++i_retry == 100000 ) {
232  printf("Request %d bytes, read %d, timeout after 100000 retries\n",i_buflen,num_of_bytes_read);
233  return STC__NODATA;
234  }
235  // JAM1-6-2021- test if this helps the streamserver problems
236 #ifndef DISABLE_POLLING_TIMEOUT
237  if (i_timeout == 555555) {
238  read_timeout.tv_sec = 0;
239  read_timeout.tv_usec = 50000;
240  } else {
241  read_timeout.tv_sec = 100;
242  read_timeout.tv_usec = 0;
243  }
244 #else
245  read_timeout.tv_sec = 100;
246  read_timeout.tv_usec = 0;
247 #endif
248 
249  } /* end while */
250 
251 
252 #ifdef DEBUG
253  printf("done\n"); fflush(stdout);
254 #endif
255  if( num_of_bytes_read == i_buflen ) return STC__SUCCESS;
256 
257  return STC__FAILURE;
258 } /* f_stc_read() */
259 
260 /* ------------------------------------------------------------------------- */
261 
262 /* %%+HEAD: */
263 /*****************+***********+****************************************/
264 /* */
265 /* GSI, Gesellschaft fuer Schwerionenforschung mbH */
266 /* Postfach 11 05 41 */
267 /* D-6100 Darmstadt 11 */
268 /* */
269 /*1+ PLI Main ****************+****************************************/
270 /* */
271 /*+ Module : f_stc_write */
272 /* */
273 /*--------------------------------------------------------------------*/
274 /*+ CALLING : f_stc_write( INTS1 p_buffer , INTS4 i_buflen , */
275 /* INTS4 i_channel ) */
276 /*--------------------------------------------------------------------*/
277 /* */
278 /*+ PURPOSE : f_stc_write. write a buffer to a connected */
279 /* socket. */
280 /* */
281 /*+ ARGUMENTS : */
282 /* */
283 /*+ p_buffer : Pointer to buffer. */
284 /* */
285 /*+ i_buflen : length of buffer. */
286 /* */
287 /*+ i_channel : Id from the connected socket. */
288 /* */
289 /*+ Return type : integer. */
290 /* */
291 /*2+DESCRIPTION***+***********+****************************************/
292 /* */
293 /*+ CALLING : f_stc_write( INTS1 p_buffer , INTS4 i_buflen , */
294 /* INTS4 i_channel ) */
295 /* */
296 /*+ ARGUMENTS : */
297 /* */
298 /*+ p_buffer : Pointer to buffer. */
299 /* */
300 /*+ i_buflen : length of buffer. */
301 /* */
302 /*+ i_channel : Id from the connected socket. */
303 /* */
304 /*+ FUNCTION : Write a specified buffer to a connected socket */
305 /* */
306 /*+ REMARKS : - */
307 /* */
308 /*2+IMPLEMENTATION************+****************************************/
309 /* */
310 /*+ Input/Output: SYS$INPUT, SYS$OUTPUT */
311 /*+ Return type : INTEGER */
312 /*+ Status codes: */
313 /*- STC__SUCCESS : success. */
314 /*- STC__FAILURE : failure. */
315 /*- STC__INVSOCK : invalid socket number. */
316 /*- STC__NOTSOCK : socket number points to a file */
317 /* not a socket. */
318 /*- STC__INVADDR : invalid address specified in */
319 /* parameter. */
320 /*+ File name : */
321 /*+ Version : 1.01 */
322 /*+ Author : R.Fritzsche */
323 /*+ Last Update : 27-Jan-1994 */
324 /* */
325 /*2+UPDATES*******+***********+****************************************/
326 /* */
327 /*+ Updates : Date Purpose */
328 /* */
329 /*2+INTERNALS*****+***********+****************************************/
330 /* */
331 /*+ Utility : EXAMPLES */
332 /*+ Compile lib.: GOOINC.TLB */
333 /*+ Home direct.: GOO$EXAMPLES */
334 /*+ Created : 25-Jan-1994 */
335 /* */
336 /*1- PLI Main ****************+****************************************/
337 /* %%-HEAD: */
338 
339 INTS4 f_stc_write(void *p_buffer, INTS4 i_buflen, INTS4 i_channel)
340 {
341  INTS4 l_retval;
342 
343  /* ---------------------------------------------------------- */
344  /* send data to server. */
345  /* ---------------------------------------------------------- */
346 
347 #ifdef DEBUG
348  printf("STC: write %5d bytes channel %d ",i_buflen,i_channel);fflush(stdout);
349 #endif
350  l_retval = send(i_channel , p_buffer , i_buflen , 0);
351 
352  switch( l_retval )
353  {
354  case -1:
355  switch( errno )
356  {
357  case EBADF : return STC__INVSOCK;
358  case ENOTSOCK : return STC__NOTSOCK;
359  case EFAULT : return STC__INVADDR;
360  default : sprintf(c_msg,"STC write error channel %d",i_channel);
361  perror(c_msg);
362  return STC__FAILURE;
363  } /* switch( errno ) */
364 
365  } /* switch( l_retval ) */
366 
367  /* ---------------------------------------------------------- */
368  /* send() returns the number of bytes sent. */
369  /* ---------------------------------------------------------- */
370 
371 #ifdef DEBUG
372  printf("done\n");fflush(stdout);
373 #endif
374  if(l_retval == i_buflen) return STC__SUCCESS;
375 
376  return STC__FAILURE;
377 } /* end f_stc_write() */
378 
379 
380 /* %%+HEAD: */
381 /*****************+***********+****************************************/
382 /* */
383 /* GSI, Gesellschaft fuer Schwerionenforschung mbH */
384 /* Postfach 11 05 41 */
385 /* D-6100 Darmstadt 11 */
386 /* */
387 /*1+ PLI Main ****************+****************************************/
388 /* */
389 /*+ Module : f_stc_connectserver */
390 /* */
391 /*--------------------------------------------------------------------*/
392 /*+ CALLING : f_stc_connectserver( CHARS c_node , INTS4 l_port , */
393 /* INTS4 pi_channel , */
394 /* struct s_tcpcomm ps_client ) */
395 /* */
396 /*--------------------------------------------------------------------*/
397 /* */
398 /*+ PURPOSE : f_stc_connectserver. connect a client process to a */
399 /* server process. */
400 /* */
401 /*+ ARGUMENTS : */
402 /* */
403 /*+ c_node : Name of server node */
404 /* */
405 /*+ l_port : Portnumber from server */
406 /* */
407 /*+ pi_channel : Pointer to channel number. */
408 /* i_channel specifies the address that will be filled */
409 /* in with the actual socket Id. */
410 /* */
411 /*+ pc_client : Pointer to structure s_tcpcomm. */
412 /* s_client specifies the address that will be filled */
413 /* in with the actual communication values. */
414 /* */
415 /* */
416 /*+ Return type : integer. */
417 /* */
418 /*2+DESCRIPTION***+***********+****************************************/
419 /* */
420 /*+ CALLING : f_stc_connectserver( CHARS c_node , INTS4 l_port , */
421 /* INTS4 pi_channel , */
422 /* struct s_tcpcomm ps_client ) */
423 /*+ ARGUMENTS : */
424 /* */
425 /*+ c_node : Name of server node */
426 /* */
427 /*+ l_port : Portnumber from server */
428 /* */
429 /*+ pi_channel : Pointer to channel number. */
430 /* i_channel specifies the address that will be filled */
431 /* in with the actual socket Id. */
432 /* */
433 /*+ ps_client : Pointer to structure s_tcpcomm. */
434 /* s_client specifies the address that will be filled */
435 /* in with the actual communication values. */
436 /* */
437 /*+ FUNCTION : f_stc_connectserver. connect a client process to a */
438 /* server process on node "c_node"*/
439 /* and port "l_port". */
440 /* f_stc_connectserver() modify */
441 /* the channel number and fill the*/
442 /* structure s_tcpcomm. */
443 /* The channel number is required */
444 /* to read and write data, to the */
445 /* connected server. */
446 /*+ REMARKS : - */
447 /* */
448 /*2+IMPLEMENTATION************+****************************************/
449 /* */
450 /*+ Input/Output: SYS$INPUT, SYS$OUTPUT */
451 /*+ Return type : INTEGER */
452 /*+ Status codes: */
453 /*- STC__SUCCESS : success. */
454 /*- STC__FAILURE : failure. */
455 /*- STC__INVADDRF: The specified address family is not */
456 /* supported. */
457 /*- STC__SOCKNSUP: The specified socket type is not */
458 /* supported. */
459 /*- STC__INVPROTO: The specified protocol is not */
460 /* supported. */
461 /*- STC__SOCKTABF: The per-process descriptor table */
462 /* is full. */
463 /*- STC__SOCKSPAF: No buffer space is available. The */
464 /* socket can't be created. */
465 /*- STC__INVSOCK : invalid socket number. */
466 /*- STC__NOTSOCK : socket number points to a file not a */
467 /* socket. */
468 /*- STC__SOCKISC : socket is already connected. */
469 /*- STC__CONNTOUT: connection timed out without */
470 /* establishing a connection. */
471 /*- STC__NETUNREA: The network is not reachable from */
472 /* this host. */
473 /*- STC__PORTINUS: The specified Internet Address and */
474 /* port is already in use. */
475 /*+ File name : */
476 /*+ Version : 1.01 */
477 /*+ Author : R.Fritzsche */
478 /*+ Last Update : 24-Jan-1994 */
479 /* */
480 /*2+UPDATES*******+***********+****************************************/
481 /* */
482 /*+ Updates : Date Purpose */
483 /* */
484 /*2+INTERNALS*****+***********+****************************************/
485 /* */
486 /*+ Utility : EXAMPLES */
487 /*+ Compile lib.: GOOINC.TLB */
488 /*+ Home direct.: GOO$EXAMPLES */
489 /*+ Created : 24-Jan-1994 */
490 /* */
491 /*1- PLI Main ****************+****************************************/
492 /* %%-HEAD: */
493 
494 INTS4 f_stc_connectserver(CHARS *c_node, INTS4 l_port, INTS4 *pi_channel, struct s_tcpcomm *ps_client)
495 {
496  INTS4 retval ;
497  struct s_tcpcomm s_client;
498 
499 
500  /* ----------------------------------------------------------------------- */
501  /* init communication socket. */
502  /* ----------------------------------------------------------------------- */
503 
504 
505 #ifdef GSI__WINNT
506  WORD wVersionRequested;
507  WSADATA wsaData;
508  char message1[512];
509  wVersionRequested = MAKEWORD( 2, 2 );
510  //err = WSAStartup( wVersionRequested, &wsaData );
511  if (WSAStartup( wVersionRequested, &wsaData)!=0) {
512  printf("WinSock NOT found");
513  /* Tell the user that we could not find a usable */
514  /* WinSock DLL. */
515  }
516 
517  if ( LOBYTE( wsaData.wVersion ) != 2 ||
518  HIBYTE( wsaData.wVersion ) != 2 ) {
519  /* Tell the user that we could not find a usable */
520  /* WinSock DLL.
521  */
522  printf("WinSock %d.%d",LOBYTE( wsaData.wVersion ),HIBYTE( wsaData.wVersion ));
523  WSACleanup( );
524  }
525 
526 #endif
527 
528  s_client.socket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
529 
530  *ps_client = s_client;
531  *pi_channel = s_client.socket; /* save channel also in case of error */
532  /* 17.7.95, H.G. */
533  switch( s_client.socket )
534  {
535  case -1:
536  switch( errno )
537  {
538  case EAFNOSUPPORT : return STC__INVADDRF;
539  case ESOCKTNOSUPPORT : return STC__SOCKNSUP;
540  case EPROTONOSUPPORT : return STC__INVPROTO;
541  case EMFILE : return STC__SOCKTABF;
542  case ENOBUFS : return STC__SOCKSPAF;
543  default : return STC__FAILURE;
544  } /* switch( errno ) */
545  } /* switch( s_client.socket) */
546 
547 
548  if(( s_client.hostentptr = gethostbyname(c_node)) == NULL)
549  {
550 
551 #ifdef GSI__WINNT
552  closesocket(s_client.socket); /* Mohammad Al-Turany 31.07.00*/
553 #else
554  close(s_client.socket); /* close socket here and in any case! */
555  /* H.G., 17.7.95 */
556 #endif
557  /* printf("--E--f_stc_connectserver(): error gethostbyname: >%s<\n",c_node);*/
558  return STC__FAILURE;
559  }
560 
561 
562  s_client.hostentstruct = *s_client.hostentptr;
563  s_client.sock.sin_family = s_client.hostentstruct.h_addrtype;
564  s_client.sock.sin_port = htons(l_port);
565  s_client.sock.sin_addr =
566  * ((struct in_addr *) s_client.hostentstruct.h_addr);
567 
568  retval = connect( s_client.socket,
569  ( struct sockaddr *) &s_client.sock,
570  sizeof(s_client.sock));
571  if( retval == -1)
572  {
573 #ifdef GSI__WINNT
574  closesocket(s_client.socket); /* Mohammad Al-Turany 31.07.00*/
575 #else
576  close(s_client.socket); /* close socket here and in any case! */
577  /* H.G., 17.7.95 */
578 #endif
579  switch( errno )
580  {
581  case EBADF : return STC__INVSOCK;
582  case ENOTSOCK : return STC__NOTSOCK;
583  case EISCONN : return STC__SOCKISC;
584  case ETIMEDOUT : return STC__CONNTOUT;
585  case ENETUNREACH : return STC__NETUNREA;
586  case EADDRINUSE : return STC__PORTINUS;
587  case ECONNREFUSED : return STC__ECONNREF;
588  default : return STC__FAILURE;
589  } /* switch( errno ) */
590  }
591 
592  *ps_client = s_client;
593 
594  return STC__SUCCESS;
595 
596 } /* f_stc_connectserver() */
597 
598 /* %%+HEAD: */
599 /*****************+***********+****************************************/
600 /* */
601 /* GSI, Gesellschaft fuer Schwerionenforschung mbH */
602 /* Postfach 11 05 41 */
603 /* D-6100 Darmstadt 11 */
604 /* */
605 /*1+ PLI Main ****************+****************************************/
606 /* */
607 /*+ Module : f_stc_acceptclient */
608 /* */
609 /*--------------------------------------------------------------------*/
610 /*+ CALLING : f_stc_acceptclient( struct s_tcpcomm s_server , */
611 /* INTS4 pi_channel ) */
612 /*--------------------------------------------------------------------*/
613 /* */
614 /*+ PURPOSE : f_stc_acceptclient. completes a connection between */
615 /* server and client. */
616 /* f_stc_acceptclient() modify the */
617 /* channel Id from the accepted */
618 /* client. The channel Id is */
619 /* required to read and write data */
620 /* to the client. */
621 /* */
622 /*+ ARGUMENTS : */
623 /* */
624 /*+ s_server : Pointer to structure s_tcpcomm. */
625 /* */
626 /*+ pi_channel : Id from the connected client. */
627 /* i_channel specifies the address that will be filled */
628 /* in with the actual client socket Id. */
629 /* */
630 /*+ Return type : integer. */
631 /* */
632 /*2+DESCRIPTION***+***********+****************************************/
633 /* */
634 /*+ CALLING : f_stc_acceptclient( struct s_tcpcomm s_server , */
635 /* INTS4 pi_channel ) */
636 /* */
637 /*+ PURPOSE : f_stc_acceptclient. completes a connection between */
638 /* server and client. */
639 /* f_stc_acceptclient() modify the */
640 /* channel Id from the accepted */
641 /* client. The channel Id is */
642 /* required to read and write data */
643 /* to the client. */
644 /* */
645 /*+ ARGUMENTS : */
646 /* */
647 /*+ s_server : Pointer to structure s_tcpcomm. */
648 /* */
649 /*+ pi_channel : Id from the connected client. */
650 /* i_channel specifies the address that will be filled */
651 /* in with the actual client socket id. */
652 /* */
653 /*+ Return type : integer. */
654 /* */
655 /*+ REMARKS : - */
656 /* */
657 /*2+IMPLEMENTATION************+****************************************/
658 /* */
659 /*+ Input/Output: SYS$INPUT, SYS$OUTPUT */
660 /*+ Return type : INTEGER */
661 /*+ Status codes: Status of last command */
662 /*- STC__SUCCESS : success. */
663 /*- STC__FAILURE : failure. */
664 /*- STC__INVSOCK : invalid socket number. */
665 /*- STC__NOTSOCK : socket number points to a file not */
666 /* a socket. */
667 /*+ File name : GOO$EXAMPLES: */
668 /*+ Version : 1.01 */
669 /*+ Author : R.Fritzsche */
670 /*+ Last Update : 25-Jan-1994 */
671 /* */
672 /*2+UPDATES*******+***********+****************************************/
673 /* */
674 /*+ Updates : Date Purpose */
675 /* */
676 /*2+INTERNALS*****+***********+****************************************/
677 /* */
678 /*+ Utility : EXAMPLES */
679 /*+ Compile lib.: GOOINC.TLB */
680 /*+ Home direct.: GOO$EXAMPLES */
681 /*+ Created : 15-Jan-1994 */
682 /* */
683 /*1- PLI Main ****************+****************************************/
684 /* %%-HEAD: */
685 
686 INTS4 f_stc_acceptclient(struct s_tcpcomm *ps_server, INTS4 *pi_channel)
687 {
688 #ifdef GSI__AIX
689  *pi_channel = accept( ps_server->sock_rw,
690  ( struct sockaddr *) &ps_server->sock_name,
691  (socklen_t *) &ps_server->namelength);
692 #else
693 #ifdef GSI__WINNT
694  *pi_channel = accept( ps_server->sock_rw,
695  ( struct sockaddr *) &ps_server->sock_name,
696  (int *) &ps_server->namelength);
697 #else
698  *pi_channel = accept( ps_server->sock_rw,
699  ( struct sockaddr *) &ps_server->sock_name,
700  (socklen_t *) &ps_server->namelength);
701 #endif
702 #endif
703 if( *pi_channel == -1)
704 {
705  switch( errno )
706  {
707  case EBADF : return STC__INVSOCK;
708  case ENOTSOCK : return STC__NOTSOCK;
709  default : return STC__FAILURE;
710  } /* switch( errno ) */
711 }
712 
713 /*
714  hostname of remote node.
715  he = gethostbyaddr( ps_server->sock_name.sin_addr.s_addr,
716  sizeof(ps_server->sock_name.sin_addr.s_addr),
717  AF_INET );
718 
719  if( he != NULL )
720  printf("name of client: %s\n",he->h_name);
721  */
722 
723  return STC__SUCCESS;
724 } /* end f_stc_acceptclient() */
725 
726 /* %%+HEAD: */
727 /*****************+***********+****************************************/
728 /* */
729 /* GSI, Gesellschaft fuer Schwerionenforschung mbH */
730 /* Postfach 11 05 41 */
731 /* D-6100 Darmstadt 11 */
732 /* */
733 /*1+ PLI Main ****************+****************************************/
734 /* */
735 /*+ Module : f_stc_createserver */
736 /* */
737 /*--------------------------------------------------------------------*/
738 /*+ CALLING : f_stc_createserver( INTS4 pl_port , */
739 /* struct s_tcpcomm ps_server ) */
740 /*--------------------------------------------------------------------*/
741 /* */
742 /*+ PURPOSE : f_stc_createserver creates an endpoint for */
743 /* client-server communications. */
744 /* The endpoint of communication */
745 /* data is not the process name. */
746 /* The client-server communication */
747 /* use portnumbers as endpoints of */
748 /* communications. */
749 /* The port numbers in the range */
750 /* 1 to 1023 are privileged ports. */
751 /* User can use ports in the range */
752 /* 1024 to 65535. */
753 /* also you can use portnumber 0, */
754 /* then f_stc_createserver() search*/
755 /* for a free portnumber and modify*/
756 /* the value from l_port, */
757 /* else f_stc_createserver() */
758 /* returns 0 */
759 /* */
760 /*+ ARGUMENTS : */
761 /* */
762 /*+ l_port : Pointer to Portnumber. ( 1024 - 65535 ) or ( 0 ). */
763 /* */
764 /*+ s_server : Pointer to structure s_tcpcomm */
765 /* s_server specifies the address that will be filled */
766 /* in with the actual communication values. */
767 /* */
768 /*+ Return type : integer. */
769 /* */
770 /*2+DESCRIPTION***+***********+****************************************/
771 /* */
772 /*+ CALLING : f_stc_createserver( INTS4 l_port , */
773 /* struct s_tcpcomm s_server) */
774 /* */
775 /*+ ARGUMENTS : */
776 /* */
777 /*+ l_port : Pointer to Portnumber. ( 1024 - 65535 ) or ( 0 ). */
778 /* l_port specifies the address that will be filled */
779 /* in with the actual server portnumber. */
780 /* */
781 /*+ S_SERVER : Pointer to structure s_tcpcomm */
782 /* s_server specifies the address that will be filled */
783 /* in with the actual communication values. */
784 /* */
785 /*+ FUNCTION : f_stc_createserver creates an endpoint for */
786 /* client - server communications. */
787 /* The endpoint of communication for */
788 /* data is not the a process name. */
789 /* The client - server communication */
790 /* use portnumbers as endpoints of */
791 /* communications. */
792 /* The port numbers in the range */
793 /* 1 to 1023 are privileged ports. */
794 /* User can use ports in the range */
795 /* 1024 to 65535. */
796 /* also you can use portnumber 0, */
797 /* then f_stc_createserver() search */
798 /* for a free portnumber and write */
799 /* the free portnumber to l_port, */
800 /* else f_stc_createserver() */
801 /* returns 0 */
802 /* */
803 /*+ REMARKS : - */
804 /* */
805 /*2+IMPLEMENTATION************+****************************************/
806 /* */
807 /*+ Input/Output: SYS$INPUT, SYS$OUTPUT */
808 /*+ Return type : INTEGER */
809 /*+ Status codes: */
810 /*- STC__SUCCESS : success. */
811 /*- STC__FAILURE : failure. */
812 /*- STC__INVADDRF : The specified address family is not */
813 /* supported. */
814 /*- STC__SOCKNSUP : The specified socket type is not */
815 /* supported. */
816 /*- STC__INVPROTO : The specified protocol is not */
817 /* supported. */
818 /*- STC__SOCKTABF : The per-process descriptor table */
819 /* is full. */
820 /*- STC__SOCKSPAF : No buffer space is available. */
821 /* The socket can't be created. */
822 /*- STC__INVSOCK : invalid socket number. */
823 /*- STC__NOTSOCK : socket number points to a file not */
824 /* a socket. */
825 /*- STC__PORTINUS : The specified Internet Address */
826 /* and port is already in use. */
827 /*- STC__SOCKISC : socket is already connected. */
828 /*- STC__SOCKISP : socket address is protected and the */
829 /* current user has inadequate */
830 /* permission to access it. */
831 /*+ File name : */
832 /*+ Version : 1.01 */
833 /*+ Author : R.Fritzsche */
834 /*+ Last Update : 25-Jan-1994 */
835 /* */
836 /*2+UPDATES*******+***********+****************************************/
837 /* */
838 /*+ Updates : Date Purpose */
839 /* */
840 /*2+INTERNALS*****+***********+****************************************/
841 /* */
842 /*+ Utility : EXAMPLES */
843 /*+ Compile lib.: GOOINC.TLB */
844 /*+ Home direct.: GOO$EXAMPLES */
845 /*+ Created : 25-Jan-1994 */
846 /* */
847 /*1- PLI Main ****************+****************************************/
848 /* %%-HEAD: */
849 
850 INTS4 f_stc_createserver(INTS4 *pl_port, struct s_tcpcomm *ps_server)
851 {
852 
853  INTS4 retval , retry;
854  struct s_tcpcomm s_server;
855 
856 
857 #ifdef GSI__WINNT
858  WORD wVersionRequested;
859  WSADATA wsaData;
860  char message1[512];
861  wVersionRequested = MAKEWORD( 2, 2 );
862  //err = WSAStartup( wVersionRequested, &wsaData );
863  if (WSAStartup( wVersionRequested, &wsaData)!=0) {
864  printf("WinSock NOT found");
865  /* Tell the user that we could not find a usable */
866  /* WinSock DLL. */
867  }
868 
869  if ( LOBYTE( wsaData.wVersion ) != 2 ||
870  HIBYTE( wsaData.wVersion ) != 2 ) {
871  /* Tell the user that we could not find a usable */
872  /* WinSock DLL.
873  */
874  printf("WinSock %d.%d",LOBYTE( wsaData.wVersion ),HIBYTE( wsaData.wVersion ));
875  WSACleanup( );
876  }
877 
878 #endif
879 
880  if( *pl_port == 0 ) {
881  retry = 1 ;
882  *pl_port = 1024;
883  }
884  else
885  retry = 0;
886 
887  s_server.sock_rw = socket (AF_INET, SOCK_STREAM, IPPROTO_TCP);
888 
889  switch( s_server.sock_rw )
890  {
891  case -1:
892  switch( errno )
893  {
894  case EAFNOSUPPORT : return STC__INVADDRF;
895  case ESOCKTNOSUPPORT : return STC__SOCKNSUP;
896  case EPROTONOSUPPORT : return STC__INVPROTO;
897  case EMFILE : return STC__SOCKTABF;
898  case ENOBUFS : return STC__SOCKSPAF;
899  default : return STC__FAILURE;
900  } /* switch( errno ) */
901  } /* switch( s_server.sock_rw) */
902 
903 
904  retval = gethostname(s_server.hostname,sizeof(s_server.hostname));
905  if(retval)
906  {
907  printf("--E--f_stc_createserver() error get local hostname\n");
908  return STC__FAILURE;
909  }
910 
911  if((s_server.hostentptr = gethostbyname (s_server.hostname)) == NULL)
912  {
913  printf("--E--f_stc_createserver() error get local Internet address\n");
914  return STC__FAILURE;
915  }
916 
917  bzero( (CHARS *) &s_server.sock_name , sizeof( s_server.sock_name ) );
918  s_server.sock_name.sin_family = AF_INET;
919  s_server.sock_name.sin_addr.s_addr = htonl(INADDR_ANY);
920  s_server.sock_name.sin_port = htons(*pl_port);
921 
922  retval = bind( s_server.sock_rw,
923  (struct sockaddr *) &s_server.sock_name,
924  sizeof(s_server.sock_name));
925 
926  if( retval == -1 && retry == 0 )
927  {
928  close( s_server.sock_rw );
929 
930  switch( errno )
931  {
932  case EBADF : return STC__INVSOCK;
933  case ENOTSOCK : return STC__NOTSOCK;
934  case EADDRINUSE : return STC__PORTINUS;
935  case EINVAL : return STC__SOCKISC;
936  case EACCES : return STC__SOCKISP;
937  default : return STC__FAILURE;
938  }
939  }
940 
941  retval = -1;
942 
943  while ( retval == -1 && retry == 1 )
944  {
945 
946  s_server.sock_rw = socket (AF_INET, SOCK_STREAM, IPPROTO_TCP);
947 
948  switch( s_server.sock_rw )
949  {
950  case -1:
951  switch( errno )
952  {
953  case EAFNOSUPPORT : return STC__INVADDRF;
954  case ESOCKTNOSUPPORT : return STC__SOCKNSUP;
955  case EPROTONOSUPPORT : return STC__INVPROTO;
956  case EMFILE : return STC__SOCKTABF;
957  case ENOBUFS : return STC__SOCKSPAF;
958  default : return STC__FAILURE;
959  }
960  }
961 
962  retval = gethostname(s_server.hostname,sizeof(s_server.hostname));
963  if(retval)
964  {
965  printf("--E--f_stc_createserver() error get local hostname\n");
966  return STC__FAILURE;
967  }
968 
969 
970  if((s_server.hostentptr = gethostbyname (s_server.hostname)) == NULL)
971  {
972  printf("--E--f_stc_createserver() error get local Internet address\n");
973  return STC__FAILURE;
974  }
975 
976  retval = -1;
977 
978  bzero( (CHARS *) &s_server.sock_name , sizeof( s_server.sock_name ) );
979  s_server.sock_name.sin_family = AF_INET;
980  s_server.sock_name.sin_addr.s_addr = htonl(INADDR_ANY);
981  s_server.sock_name.sin_port = htons(*pl_port);
982 
983  retval = bind( s_server.sock_rw,
984  (struct sockaddr *) &s_server.sock_name,
985  sizeof(s_server.sock_name));
986  if( retval == -1 )
987  {
988  close( s_server.sock_rw );
989 
990  *pl_port += 1;
991 
992  if( *pl_port > 65535 )
993  {
994  printf("--E--f_stc_createserver() portnumber exceeded > 655535\n");
995 
996  switch( errno )
997  {
998  case EBADF : return STC__INVSOCK;
999  case ENOTSOCK : return STC__NOTSOCK;
1000  case EADDRINUSE : return STC__PORTINUS;
1001  case EINVAL : return STC__SOCKISC;
1002  case EACCES : return STC__SOCKISP;
1003  default : return STC__FAILURE;
1004  } /* end switch( errno ) */
1005 
1006  } /* end if *pl_port > ... ) */
1007 
1008  } /* end if (retval == -1 ) */
1009 
1010 
1011  }
1012 
1013  retval = listen(s_server.sock_rw,5);
1014  if( retval == -1 )
1015  {
1016  switch( errno )
1017  {
1018  case EBADF : return STC__INVSOCK;
1019  case ENOTSOCK : return STC__NOTSOCK;
1020  default : return STC__FAILURE;
1021  }
1022  }
1023 
1024  s_server.namelength = sizeof( s_server.sock_name);
1025 
1026  *ps_server = s_server;
1027 
1028  return STC__SUCCESS;
1029 } /* end f_stc_createserver() */
1030 
1031 /* %%+HEAD: */
1032 /*****************+***********+****************************************/
1033 /* */
1034 /* GSI, Gesellschaft fuer Schwerionenforschung mbH */
1035 /* Postfach 11 05 41 */
1036 /* D-6100 Darmstadt 11 */
1037 /* */
1038 /*1+ PLI Main ****************+****************************************/
1039 /* */
1040 /*+ Module : f_stc_close */
1041 /* */
1042 /*--------------------------------------------------------------------*/
1043 /*+ CALLING : f_stc_close( struct s_tcpcomm ps_tcp ) */
1044 /*--------------------------------------------------------------------*/
1045 /* */
1046 /*+ PURPOSE : f_stc_close close the client server */
1047 /* communication. */
1048 /* */
1049 /*+ ARGUMENTS : */
1050 /* */
1051 /*+ S_TCP : Pointer to structure s_tcpcomm. */
1052 /* */
1053 /*+ Return type : integer. */
1054 /* */
1055 /*2+DESCRIPTION***+***********+****************************************/
1056 /* */
1057 /*+ CALLING : f_stc_close( struct s_tcpcomm ps_tcp ) */
1058 /* */
1059 /*+ ARGUMENTS : */
1060 /* */
1061 /*+ FUNCTION : f_stc_close close the client server */
1062 /* communication. */
1063 /* */
1064 /*+ S_TCP : Pointer to structure s_tcpcomm. */
1065 /* */
1066 /*+ REMARKS : - */
1067 /* */
1068 /*2+IMPLEMENTATION************+****************************************/
1069 /* */
1070 /*+ Input/Output: SYS$INPUT, SYS$OUTPUT */
1071 /*+ Return type : INTEGER */
1072 /*+ File name : */
1073 /*+ Version : 1.01 */
1074 /*+ Author : R.Fritzsche */
1075 /*+ Last Update : 25-Jan-1994 */
1076 /* */
1077 /*2+UPDATES*******+***********+****************************************/
1078 /* */
1079 /*+ Updates : Date Purpose */
1080 /* */
1081 /*2+INTERNALS*****+***********+****************************************/
1082 /* */
1083 /*+ Utility : EXAMPLES */
1084 /*+ Compile lib.: GOOCINC.TLB */
1085 /*+ Home direct.: GOO$EXAMPLES */
1086 /*+ Created : 25-Jan-1994 */
1087 /* */
1088 /*1- PLI Main ****************+****************************************/
1089 /* %%-HEAD: */
1090 
1091 INTS4 f_stc_close(struct s_tcpcomm * ps_tcp)
1092 {
1093  INTS4 retval;
1094 
1095  if( ps_tcp->socket )
1096  {
1097  retval = shutdown( ps_tcp->socket,2);
1098  if(retval == -1) {
1099  return STC__FAILURE;
1100  }
1101  retval = close(ps_tcp->socket);
1102  if(retval == -1) {
1103  return STC__FAILURE;
1104  }
1105 
1106  return STC__SUCCESS;
1107  }
1108 
1109  return STC__FAILURE;
1110 } /* f_stc_close() */
1111 
1112 /* %%+HEAD: */
1113 /*****************+***********+****************************************/
1114 /* */
1115 /* GSI, Gesellschaft fuer Schwerionenforschung mbH */
1116 /* Postfach 11 05 41 */
1117 /* D-6100 Darmstadt 11 */
1118 /* */
1119 /*1+ PLI Main ****************+****************************************/
1120 /* */
1121 /*+ Module : f_stc_discclient */
1122 /* */
1123 /*--------------------------------------------------------------------*/
1124 /*+ CALLING : f_stc_discclient( INTS4 i_channel ) */
1125 /*--------------------------------------------------------------------*/
1126 /* */
1127 /*+ PURPOSE : f_stc_discclient close the specified client */
1128 /* server communication. */
1129 /* */
1130 /*+ ARGUMENTS : */
1131 /* */
1132 /*+ I_CHANNEL : Channel Id from the specified client. */
1133 /* */
1134 /*+ Return type : integer. */
1135 /* */
1136 /*2+DESCRIPTION***+***********+****************************************/
1137 /* */
1138 /*+ CALLING : f_stc_discclient( INTS4 i_channel ) */
1139 /* */
1140 /*+ ARGUMENTS : */
1141 /* */
1142 /*+ FUNCTION : f_stc_discclient close the specified client */
1143 /* server communication. */
1144 /* */
1145 /*+ I_CHANNEL : Channel Id from the specified client. */
1146 /* */
1147 /*+ REMARKS : - */
1148 /* */
1149 /*2+IMPLEMENTATION************+****************************************/
1150 /* */
1151 /*+ Input/Output: SYS$INPUT, SYS$OUTPUT */
1152 /*+ Return type : INTEGER */
1153 /*+ File name : */
1154 /*+ Version : 1.01 */
1155 /*+ Author : R.Fritzsche */
1156 /*+ Last Update : 01-Mar-1994 */
1157 /* */
1158 /*2+UPDATES*******+***********+****************************************/
1159 /* */
1160 /*+ Updates : Date Purpose */
1161 /* */
1162 /*2+INTERNALS*****+***********+****************************************/
1163 /* */
1164 /*+ Utility : EXAMPLES */
1165 /*+ Compile lib.: */
1166 /*+ Home direct.: */
1167 /*+ Created : 01-Mar-1994 */
1168 /* */
1169 /*1- PLI Main ****************+****************************************/
1170 /* %%-HEAD: */
1171 
1173 {
1174  INTS4 retval;
1175 
1176  /* call of shutdown removed 17.7.95, H.G. */
1177  retval = close( i_channel );
1178  if(retval == -1)
1179  return STC__FAILURE;
1180 
1181  return STC__SUCCESS;
1182 } /* f_stc_discclient() */
1183 
1184 /* %%+HEAD: */
1185 /*****************+***********+****************************************/
1186 /* */
1187 /* GSI, Gesellschaft fuer Schwerionenforschung mbH */
1188 /* Postfach 11 05 41 */
1189 /* D-6100 Darmstadt 11 */
1190 /* */
1191 /*1+ PLI Main ****************+****************************************/
1192 /* */
1193 /*+ Module : f_stc_listenserver */
1194 /* */
1195 /*--------------------------------------------------------------------*/
1196 /*+ CALLING : f_stc_listenserver( struct s_tcpcomm ps_server ) */
1197 /*--------------------------------------------------------------------*/
1198 /* */
1199 /*+ PURPOSE : f_stc_listenserver look for a pending client */
1200 /* connection on the specified */
1201 /* server. */
1202 /* */
1203 /*+ ARGUMENTS : */
1204 /* */
1205 /*+ PS_SERVER : Pointer to structure s_tcpcomm. */
1206 /* */
1207 /*+ Return type : integer. */
1208 /* */
1209 /*2+DESCRIPTION***+***********+****************************************/
1210 /* */
1211 /*+ CALLING : f_stc_listenserver( struct s_tcpcomm ps_server ) */
1212 /* */
1213 /*+ ARGUMENTS : */
1214 /* */
1215 /*+ FUNCTION : f_stc_listenserver look for a pending client */
1216 /* connection on the specified */
1217 /* server. */
1218 /* */
1219 /*+ PS_SERVER : Pointer to structure s_tcpcomm. */
1220 /* */
1221 /*+ REMARKS : - */
1222 /* */
1223 /*2+IMPLEMENTATION************+****************************************/
1224 /* */
1225 /*+ Input/Output: SYS$INPUT, SYS$OUTPUT */
1226 /*+ Return type : INTEGER */
1227 /*+ Status codes: */
1228 /*- STC__SUCCESS : success. */
1229 /*- STC__FAIlURE : failure. */
1230 /*- STC__INVSOCK : invalid socket number. */
1231 /*- STC__TIMEOUT : timeout. */
1232 /*- STC__INVTIME : time limit is unacceptable */
1233 /* negativ or to long. */
1234 /*+ File name : */
1235 /*+ Version : 1.01 */
1236 /*+ Author : R.Fritzsche */
1237 /*+ Last Update : 25-Jan-1994 */
1238 /* */
1239 /*2+UPDATES*******+***********+****************************************/
1240 /* */
1241 /*+ Updates : Date Purpose */
1242 /* */
1243 /*2+INTERNALS*****+***********+****************************************/
1244 /* */
1245 /*+ Utility : EXAMPLES */
1246 /*+ Compile lib.: GOOCINC.TLB */
1247 /*+ Home direct.: GOO$EXAMPLES */
1248 /*+ Created : 25-Jan-1994 */
1249 /* */
1250 /*1- PLI Main ****************+****************************************/
1251 /* %%-HEAD: */
1252 
1254 {
1255  struct timeval read_timeout;
1256  fd_set rset , allset , wset , eset;
1257  INTS4 listenfd , maxfd , sts;
1258 
1259  read_timeout.tv_sec = 0;
1260  read_timeout.tv_usec = 0;
1261 
1262  listenfd = ps_server->sock_rw;
1263 
1264  FD_ZERO(&rset);
1265  FD_ZERO(&wset);
1266  FD_ZERO(&eset);
1267  FD_ZERO(&allset);
1268  FD_SET(listenfd,&rset);
1269  FD_SET(listenfd,&wset);
1270  FD_SET(listenfd,&eset);
1271  maxfd = listenfd;
1272 
1273  sts = select( maxfd + 1 , &rset ,
1274  &wset ,
1275  &eset , &read_timeout);
1276  switch( sts )
1277  {
1278  case -1:
1279  switch( errno )
1280  {
1281  case EBADF : return STC__INVSOCK;
1282  case EINVAL : return STC__INVTIME;
1283  default : return STC__FAILURE;
1284  } /* switch( errno ) */
1285 
1286  case 0: return STC__TIMEOUT;
1287 
1288  } /* end switch( sts ) */
1289 
1290  if( FD_ISSET(listenfd,&eset)) {
1291  return STC__SUCCESS;
1292  }
1293 
1294  if( FD_ISSET(listenfd,&rset)) {
1295  return STC__SUCCESS;
1296  }
1297 
1298  if( FD_ISSET(listenfd,&wset)) {
1299  return STC__SUCCESS;
1300  }
1301 
1302  return STC__FAILURE;
1303 }
1304 
1305 
1306 /* %%+HEAD: */
1307 /*****************+***********+****************************************/
1308 /* */
1309 /* GSI, Gesellschaft fuer Schwerionenforschung mbH */
1310 /* Postfach 11 05 41 */
1311 /* D-6100 Darmstadt 11 */
1312 /* */
1313 /*1+ PLI Main ****************+****************************************/
1314 /* */
1315 /*+ Module : f_stc_disperror */
1316 /* */
1317 /*--------------------------------------------------------------------*/
1318 /*+ CALLING : f_stc_disperror( INTS4 i_error , CHARS c_string[256], */
1319 /* INTS4 i_out ) */
1320 /*--------------------------------------------------------------------*/
1321 /* */
1322 /*+ PURPOSE : f_stc_disperror displays the error message for the */
1323 /* error id ( i_error ) */
1324 /* if i_out = 1 the error message is */
1325 /* copied into c_string, else */
1326 /* f_stc_disperror() print the message */
1327 /* on the terminal. */
1328 /* */
1329 /*+ ARGUMENTS : */
1330 /* */
1331 /*+ I_ERROR : The error id. */
1332 /* */
1333 /*+ C_STRING : The string into f_stc_disperror() copies the */
1334 /* message. */
1335 /* */
1336 /*+ I_OUT : specifies the output device for the error message. */
1337 /* */
1338 /*- I_OUT = 1 : the error message is copied into */
1339 /* the string. */
1340 /*- I_OUT = 0 : the error message is printed on */
1341 /* the terminal. */
1342 /* */
1343 /*+ Return type : integer. */
1344 /* */
1345 /*2+DESCRIPTION***+***********+****************************************/
1346 /* */
1347 /*+ CALLING : f_stc_disperror( INTS4 i_error , CHARS c_string[256], */
1348 /* INTS4 i_out ) */
1349 /* */
1350 /*+ ARGUMENTS : */
1351 /* */
1352 /*+ I_ERROR : The error id. */
1353 /* */
1354 /*+ C_STRING : The string into f_stc_disperror() copies the */
1355 /* message. */
1356 /* */
1357 /*+ I_OUT : specifies the output device for the error message. */
1358 /* */
1359 /*- I_OUT = 1 : the error message is copied into the */
1360 /* string. */
1361 /*- I_OUT = 0 : the error message is printed on the */
1362 /* terminal. */
1363 /* */
1364 /*+ FUNCTION : f_stc_disperror displays the error message for the */
1365 /* error id ( i_error ) */
1366 /* if i_out = 1 the error message is */
1367 /* copied into c_string, else */
1368 /* f_stc_disperror() print the message */
1369 /* on the terminal. */
1370 /* */
1371 /*+ REMARKS : - */
1372 /* */
1373 /*2+IMPLEMENTATION************+****************************************/
1374 /* */
1375 /*+ Input/Output: SYS$INPUT, SYS$OUTPUT */
1376 /*+ Return type : INTEGER */
1377 /*+ Status codes: */
1378 /*- STC__SUCCESS : success. */
1379 /*- STC__FAIlURE : failure. */
1380 /*+ File name : */
1381 /*+ Version : 1.01 */
1382 /*+ Author : R.Fritzsche */
1383 /*+ Last Update : 28-Jan-1994 */
1384 /* */
1385 /*2+UPDATES*******+***********+****************************************/
1386 /* */
1387 /*+ Updates : Date Purpose */
1388 /* */
1389 /*2+INTERNALS*****+***********+****************************************/
1390 /* */
1391 /*+ Utility : EXAMPLES */
1392 /*+ Compile lib.: GOOCINC.TLB */
1393 /*+ Home direct.: GOO$EXAMPLES */
1394 /*+ Created : 28-Jan-1994 */
1395 /* */
1396 /*1- PLI Main ****************+****************************************/
1397 /* %%-HEAD: */
1398 
1399 INTS4 f_stc_disperror(INTS4 i_error, CHARS *c_dest, INTS4 i_out)
1400 {
1401  CHARS c_line[80];
1402 
1403  switch( i_error )
1404  {
1405  case STC__FAILURE :
1406  sprintf(c_line,"-I- f_stc failure");
1407  break;
1408  case STC__SUCCESS :
1409  sprintf(c_line,"-I- f_stc failure");
1410  break;
1411  case STC__INVSOCK :
1412  sprintf(c_line,"-I- f_stc invalid socket number");
1413  break;
1414  case STC__INVBUF :
1415  sprintf(c_line,"-I- f_stc buffer points outside allocated address space");
1416  break;
1417  case STC__NGBUFSIZE :
1418  sprintf(c_line,"-I- f_stc buffer length is negative");
1419  break;
1420  case STC__INVTIME :
1421  sprintf(c_line,"-I- f_stc time limit is negativ or to long");
1422  break;
1423  case STC__TIMEOUT :
1424  sprintf(c_line,"-I- f_stc timeout read data from socket");
1425  break;
1426  case STC__NOTSOCK :
1427  sprintf(c_line,"-I- f_stc socket number points to a file not a socket");
1428  break;
1429  case STC__INVADDR :
1430  sprintf(c_line,"-I- f_stc invalid address specified in parameter");
1431  break;
1432  case STC__INVADDRF :
1433  sprintf(c_line,"-I- f_stc the specified address family is not supported");
1434  break;
1435  case STC__SOCKNSUP :
1436  sprintf(c_line,"-I- f_stc The specified socket type is not supported.");
1437  break;
1438  case STC__INVPROTO :
1439  sprintf(c_line,"-I- f_stc The specified protocol is not supported.");
1440  break;
1441  case STC__SOCKTABF :
1442  sprintf(c_line,"-I- f_stc The per-process descriptor table is full.");
1443  break;
1444  case STC__SOCKSPAF :
1445  sprintf(c_line,"-I- f_stc No buffer space is available. The socket can't be created");
1446  break;
1447  case STC__SOCKISC :
1448  sprintf(c_line,"-I- f_stc socket is already connected.");
1449  break;
1450  case STC__CONNTOUT :
1451  sprintf(c_line,"-I- f_stc connection timed out without establishing a connection.");
1452  break;
1453  case STC__NETUNREA :
1454  sprintf(c_line,"-I- f_stc The network is not reachable from this host.");
1455  break;
1456  case STC__PORTINUS :
1457  sprintf(c_line,"-I- f_stc The specified Internet Address and port is already in use.");
1458  break;
1459  case STC__SOCKISP :
1460  sprintf(c_line,"-I- f_stc socket address is protected.");
1461  break;
1462  case STC__ECONNREF : /* added 17.7.95, H.G. */
1463  sprintf(c_line,"-I- f_stc connection refused.");
1464  break;
1465  case TPS__ECPORTS :
1466  sprintf(c_line,"-I- f_stc error connect portserver");
1467  break;
1468  case TPS__EREGSERV :
1469  sprintf(c_line,"-I- f_stc error register service at portserver");
1470  break;
1471  case TPS__EWTOPORTS :
1472  sprintf(c_line,"-I- f_stc error write buffer to portserver");
1473  break;
1474  case TPS__ERMFRPORTS :
1475  sprintf(c_line,"-I- f_stc error read status message from portserver");
1476  break;
1477  case TPS__EGSERVICE :
1478  sprintf(c_line,"-I- f_stc error get spec. info from portserver");
1479  break;
1480  default:
1481  sprintf(c_line,"-I- f_stc unknown message id %d",i_error);
1482  if(i_out==0)printf("%s\n",c_line);
1483  if(i_out==1)strcpy(c_dest,c_line);
1484  return STC__FAILURE;
1485  } /* end switch( i_error ) */
1486 
1487  if(i_out==0) printf("%s\n",c_line);
1488  if(i_out==1) strcpy(c_dest,c_line);
1489 
1490  return STC__SUCCESS;
1491 } /* f_stc_disperror() */
#define STC__ECONNRES
Definition: f_stccomm.h:396
char INTS1
Definition: typedefs.h:24
#define STC__NETUNREA
Definition: f_stccomm.h:384
INTS4 namelength
Definition: f_stccomm.h:305
INTS4 socket
Definition: f_stccomm.h:305
INTS4 f_stc_close(struct s_tcpcomm *ps_tcp)
Definition: f_stccomm.c:1091
#define EAFNOSUPPORT
Definition: typedefs_nt.h:34
INTS4 f_stc_read(void *p_buffer, INTS4 i_buflen, INTS4 i_channel, INTS4 i_timeout)
Definition: f_stccomm.c:134
#define STC__NOTSOCK
Definition: f_stccomm.h:375
struct hostent hostentstruct
Definition: f_stccomm.h:308
INTS4 f_stc_listenserver(struct s_tcpcomm *ps_server)
Definition: f_stccomm.c:1253
CHARS c_msg[80]
Definition: f_stccomm.c:21
#define STC__CONNTOUT
Definition: f_stccomm.h:383
#define ENETUNREACH
Definition: typedefs_nt.h:54
INTS4 f_stc_write(void *p_buffer, INTS4 i_buflen, INTS4 i_channel)
Definition: f_stccomm.c:339
#define ECONNRESET
Definition: typedefs_nt.h:26
#define ETIMEDOUT
Definition: typedefs_nt.h:50
#define STC__EINTR
Definition: f_stccomm.h:395
#define ENOTSOCK
Definition: typedefs_nt.h:30
INTS4 f_stc_disperror(INTS4 i_error, CHARS *c_dest, INTS4 i_out)
Definition: f_stccomm.c:1399
#define EISCONN
Definition: typedefs_nt.h:46
#define TPS__ERMFRPORTS
Definition: f_stccomm.h:390
INTS4 f_stc_acceptclient(struct s_tcpcomm *ps_server, INTS4 *pi_channel)
Definition: f_stccomm.c:686
#define STC__SOCKSPAF
Definition: f_stccomm.h:381
INTS4 sock_rw
Definition: f_stccomm.h:305
#define TPS__EWTOPORTS
Definition: f_stccomm.h:389
#define STC__TIMEOUT
Definition: f_stccomm.h:374
INTS4 f_stc_discclient(INTS4 i_channel)
Definition: f_stccomm.c:1172
#define EADDRINUSE
Definition: typedefs_nt.h:58
#define STC__PORTINUS
Definition: f_stccomm.h:385
INTS4 f_stc_connectserver(CHARS *c_node, INTS4 l_port, INTS4 *pi_channel, struct s_tcpcomm *ps_client)
Definition: f_stccomm.c:494
#define STC__SUCCESS
Definition: f_stccomm.h:369
#define TPS__EREGSERV
Definition: f_stccomm.h:388
struct hostent * hostentptr
Definition: f_stccomm.h:309
int INTS4
Definition: typedefs.h:28
#define STC__INVTIME
Definition: f_stccomm.h:373
#define EPROTONOSUPPORT
Definition: typedefs_nt.h:38
#define STC__SOCKNSUP
Definition: f_stccomm.h:378
#define ECONNREFUSED
Definition: typedefs_nt.h:62
#define STC__INVSOCK
Definition: f_stccomm.h:370
#define ENOBUFS
Definition: typedefs_nt.h:42
#define STC__INVADDR
Definition: f_stccomm.h:376
#define TPS__EGSERVICE
Definition: f_stccomm.h:391
INTS1 hostname[256]
Definition: f_stccomm.h:310
#define STC__ECONNREF
Definition: f_stccomm.h:394
#define ESOCKTNOSUPPORT
Definition: typedefs_nt.h:22
#define STC__NODATA
Definition: f_stccomm.h:393
#define STC__SOCKISP
Definition: f_stccomm.h:386
#define TPS__ECPORTS
Definition: f_stccomm.h:387
#define STC__FAILURE
Definition: f_stccomm.h:368
struct sockaddr_in sock sock_name
Definition: f_stccomm.h:307
#define STC__INVBUF
Definition: f_stccomm.h:371
#define STC__NGBUFSIZE
Definition: f_stccomm.h:372
#define STC__INVPROTO
Definition: f_stccomm.h:379
#define STC__SOCKISC
Definition: f_stccomm.h:382
INTS4 f_stc_createserver(INTS4 *pl_port, struct s_tcpcomm *ps_server)
Definition: f_stccomm.c:850
#define STC__SOCKTABF
Definition: f_stccomm.h:380
#define STC__INVADDRF
Definition: f_stccomm.h:377
int i_channel
Definition: f_evcli.c:173
char CHARS
Definition: typedefs.h:21