GSI Object Oriented Online Offline (Go4)  GO4-6.1.2
 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 3228 2021-06-11 07:07:35Z 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 , on ;
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  on = 1;
881 
882  if( *pl_port == 0 ) {
883  retry = 1 ;
884  *pl_port = 1024;
885  }
886  else
887  retry = 0;
888 
889  s_server.sock_rw = socket (AF_INET, SOCK_STREAM, IPPROTO_TCP);
890 
891  switch( s_server.sock_rw )
892  {
893  case -1:
894  switch( errno )
895  {
896  case EAFNOSUPPORT : return STC__INVADDRF;
897  case ESOCKTNOSUPPORT : return STC__SOCKNSUP;
898  case EPROTONOSUPPORT : return STC__INVPROTO;
899  case EMFILE : return STC__SOCKTABF;
900  case ENOBUFS : return STC__SOCKSPAF;
901  default : return STC__FAILURE;
902  } /* switch( errno ) */
903  } /* switch( s_server.sock_rw) */
904 
905 
906  retval = gethostname(s_server.hostname,sizeof(s_server.hostname));
907  if(retval)
908  {
909  printf("--E--f_stc_createserver() error get local hostname\n");
910  return STC__FAILURE;
911  }
912 
913  if((s_server.hostentptr = gethostbyname (s_server.hostname)) == NULL)
914  {
915  printf("--E--f_stc_createserver() error get local Internet address\n");
916  return STC__FAILURE;
917  }
918 
919  bzero( (CHARS *) &s_server.sock_name , sizeof( s_server.sock_name ) );
920  s_server.sock_name.sin_family = AF_INET;
921  s_server.sock_name.sin_addr.s_addr = htonl(INADDR_ANY);
922  s_server.sock_name.sin_port = htons(*pl_port);
923 
924  retval = bind( s_server.sock_rw,
925  (struct sockaddr *) &s_server.sock_name,
926  sizeof(s_server.sock_name));
927 
928  if( retval == -1 && retry == 0 )
929  {
930  close( s_server.sock_rw );
931 
932  switch( errno )
933  {
934  case EBADF : return STC__INVSOCK;
935  case ENOTSOCK : return STC__NOTSOCK;
936  case EADDRINUSE : return STC__PORTINUS;
937  case EINVAL : return STC__SOCKISC;
938  case EACCES : return STC__SOCKISP;
939  default : return STC__FAILURE;
940  }
941  }
942 
943  retval = -1;
944 
945  while ( retval == -1 && retry == 1 )
946  {
947 
948  s_server.sock_rw = socket (AF_INET, SOCK_STREAM, IPPROTO_TCP);
949 
950  switch( s_server.sock_rw )
951  {
952  case -1:
953  switch( errno )
954  {
955  case EAFNOSUPPORT : return STC__INVADDRF;
956  case ESOCKTNOSUPPORT : return STC__SOCKNSUP;
957  case EPROTONOSUPPORT : return STC__INVPROTO;
958  case EMFILE : return STC__SOCKTABF;
959  case ENOBUFS : return STC__SOCKSPAF;
960  default : return STC__FAILURE;
961  }
962  }
963 
964  retval = gethostname(s_server.hostname,sizeof(s_server.hostname));
965  if(retval)
966  {
967  printf("--E--f_stc_createserver() error get local hostname\n");
968  return STC__FAILURE;
969  }
970 
971 
972  if((s_server.hostentptr = gethostbyname (s_server.hostname)) == NULL)
973  {
974  printf("--E--f_stc_createserver() error get local Internet address\n");
975  return STC__FAILURE;
976  }
977 
978  retval = -1;
979 
980  bzero( (CHARS *) &s_server.sock_name , sizeof( s_server.sock_name ) );
981  s_server.sock_name.sin_family = AF_INET;
982  s_server.sock_name.sin_addr.s_addr = htonl(INADDR_ANY);
983  s_server.sock_name.sin_port = htons(*pl_port);
984 
985  retval = bind( s_server.sock_rw,
986  (struct sockaddr *) &s_server.sock_name,
987  sizeof(s_server.sock_name));
988  if( retval == -1 )
989  {
990  close( s_server.sock_rw );
991 
992  *pl_port += 1;
993 
994  if( *pl_port > 65535 )
995  {
996  printf("--E--f_stc_createserver() portnumber exceeded > 655535\n");
997 
998  switch( errno )
999  {
1000  case EBADF : return STC__INVSOCK;
1001  case ENOTSOCK : return STC__NOTSOCK;
1002  case EADDRINUSE : return STC__PORTINUS;
1003  case EINVAL : return STC__SOCKISC;
1004  case EACCES : return STC__SOCKISP;
1005  default : return STC__FAILURE;
1006  } /* end switch( errno ) */
1007 
1008  } /* end if *pl_port > ... ) */
1009 
1010  } /* end if (retval == -1 ) */
1011 
1012 
1013  }
1014 
1015  retval = listen(s_server.sock_rw,5);
1016  if( retval == -1 )
1017  {
1018  switch( errno )
1019  {
1020  case EBADF : return STC__INVSOCK;
1021  case ENOTSOCK : return STC__NOTSOCK;
1022  default : return STC__FAILURE;
1023  }
1024  }
1025 
1026  s_server.namelength = sizeof( s_server.sock_name);
1027 
1028  *ps_server = s_server;
1029 
1030  return STC__SUCCESS;
1031 } /* end f_stc_createserver() */
1032 
1033 /* %%+HEAD: */
1034 /*****************+***********+****************************************/
1035 /* */
1036 /* GSI, Gesellschaft fuer Schwerionenforschung mbH */
1037 /* Postfach 11 05 41 */
1038 /* D-6100 Darmstadt 11 */
1039 /* */
1040 /*1+ PLI Main ****************+****************************************/
1041 /* */
1042 /*+ Module : f_stc_close */
1043 /* */
1044 /*--------------------------------------------------------------------*/
1045 /*+ CALLING : f_stc_close( struct s_tcpcomm ps_tcp ) */
1046 /*--------------------------------------------------------------------*/
1047 /* */
1048 /*+ PURPOSE : f_stc_close close the client server */
1049 /* communication. */
1050 /* */
1051 /*+ ARGUMENTS : */
1052 /* */
1053 /*+ S_TCP : Pointer to structure s_tcpcomm. */
1054 /* */
1055 /*+ Return type : integer. */
1056 /* */
1057 /*2+DESCRIPTION***+***********+****************************************/
1058 /* */
1059 /*+ CALLING : f_stc_close( struct s_tcpcomm ps_tcp ) */
1060 /* */
1061 /*+ ARGUMENTS : */
1062 /* */
1063 /*+ FUNCTION : f_stc_close close the client server */
1064 /* communication. */
1065 /* */
1066 /*+ S_TCP : Pointer to structure s_tcpcomm. */
1067 /* */
1068 /*+ REMARKS : - */
1069 /* */
1070 /*2+IMPLEMENTATION************+****************************************/
1071 /* */
1072 /*+ Input/Output: SYS$INPUT, SYS$OUTPUT */
1073 /*+ Return type : INTEGER */
1074 /*+ File name : */
1075 /*+ Version : 1.01 */
1076 /*+ Author : R.Fritzsche */
1077 /*+ Last Update : 25-Jan-1994 */
1078 /* */
1079 /*2+UPDATES*******+***********+****************************************/
1080 /* */
1081 /*+ Updates : Date Purpose */
1082 /* */
1083 /*2+INTERNALS*****+***********+****************************************/
1084 /* */
1085 /*+ Utility : EXAMPLES */
1086 /*+ Compile lib.: GOOCINC.TLB */
1087 /*+ Home direct.: GOO$EXAMPLES */
1088 /*+ Created : 25-Jan-1994 */
1089 /* */
1090 /*1- PLI Main ****************+****************************************/
1091 /* %%-HEAD: */
1092 
1093 INTS4 f_stc_close(struct s_tcpcomm * ps_tcp)
1094 {
1095  INTS4 retval;
1096 
1097  if( ps_tcp->socket )
1098  {
1099  retval = shutdown( ps_tcp->socket,2);
1100  if(retval == -1) {
1101  return STC__FAILURE;
1102  }
1103  retval = close(ps_tcp->socket);
1104  if(retval == -1) {
1105  return STC__FAILURE;
1106  }
1107 
1108  return STC__SUCCESS;
1109  }
1110 
1111  return STC__FAILURE;
1112 } /* f_stc_close() */
1113 
1114 /* %%+HEAD: */
1115 /*****************+***********+****************************************/
1116 /* */
1117 /* GSI, Gesellschaft fuer Schwerionenforschung mbH */
1118 /* Postfach 11 05 41 */
1119 /* D-6100 Darmstadt 11 */
1120 /* */
1121 /*1+ PLI Main ****************+****************************************/
1122 /* */
1123 /*+ Module : f_stc_discclient */
1124 /* */
1125 /*--------------------------------------------------------------------*/
1126 /*+ CALLING : f_stc_discclient( INTS4 i_channel ) */
1127 /*--------------------------------------------------------------------*/
1128 /* */
1129 /*+ PURPOSE : f_stc_discclient close the specified client */
1130 /* server communication. */
1131 /* */
1132 /*+ ARGUMENTS : */
1133 /* */
1134 /*+ I_CHANNEL : Channel Id from the specified client. */
1135 /* */
1136 /*+ Return type : integer. */
1137 /* */
1138 /*2+DESCRIPTION***+***********+****************************************/
1139 /* */
1140 /*+ CALLING : f_stc_discclient( INTS4 i_channel ) */
1141 /* */
1142 /*+ ARGUMENTS : */
1143 /* */
1144 /*+ FUNCTION : f_stc_discclient close the specified client */
1145 /* server communication. */
1146 /* */
1147 /*+ I_CHANNEL : Channel Id from the specified client. */
1148 /* */
1149 /*+ REMARKS : - */
1150 /* */
1151 /*2+IMPLEMENTATION************+****************************************/
1152 /* */
1153 /*+ Input/Output: SYS$INPUT, SYS$OUTPUT */
1154 /*+ Return type : INTEGER */
1155 /*+ File name : */
1156 /*+ Version : 1.01 */
1157 /*+ Author : R.Fritzsche */
1158 /*+ Last Update : 01-Mar-1994 */
1159 /* */
1160 /*2+UPDATES*******+***********+****************************************/
1161 /* */
1162 /*+ Updates : Date Purpose */
1163 /* */
1164 /*2+INTERNALS*****+***********+****************************************/
1165 /* */
1166 /*+ Utility : EXAMPLES */
1167 /*+ Compile lib.: */
1168 /*+ Home direct.: */
1169 /*+ Created : 01-Mar-1994 */
1170 /* */
1171 /*1- PLI Main ****************+****************************************/
1172 /* %%-HEAD: */
1173 
1175 {
1176  INTS4 retval;
1177 
1178  /* call of shutdown removed 17.7.95, H.G. */
1179  retval = close( i_channel );
1180  if(retval == -1)
1181  return STC__FAILURE;
1182 
1183  return STC__SUCCESS;
1184 } /* f_stc_discclient() */
1185 
1186 /* %%+HEAD: */
1187 /*****************+***********+****************************************/
1188 /* */
1189 /* GSI, Gesellschaft fuer Schwerionenforschung mbH */
1190 /* Postfach 11 05 41 */
1191 /* D-6100 Darmstadt 11 */
1192 /* */
1193 /*1+ PLI Main ****************+****************************************/
1194 /* */
1195 /*+ Module : f_stc_listenserver */
1196 /* */
1197 /*--------------------------------------------------------------------*/
1198 /*+ CALLING : f_stc_listenserver( struct s_tcpcomm ps_server ) */
1199 /*--------------------------------------------------------------------*/
1200 /* */
1201 /*+ PURPOSE : f_stc_listenserver look for a pending client */
1202 /* connection on the specified */
1203 /* server. */
1204 /* */
1205 /*+ ARGUMENTS : */
1206 /* */
1207 /*+ PS_SERVER : Pointer to structure s_tcpcomm. */
1208 /* */
1209 /*+ Return type : integer. */
1210 /* */
1211 /*2+DESCRIPTION***+***********+****************************************/
1212 /* */
1213 /*+ CALLING : f_stc_listenserver( struct s_tcpcomm ps_server ) */
1214 /* */
1215 /*+ ARGUMENTS : */
1216 /* */
1217 /*+ FUNCTION : f_stc_listenserver look for a pending client */
1218 /* connection on the specified */
1219 /* server. */
1220 /* */
1221 /*+ PS_SERVER : Pointer to structure s_tcpcomm. */
1222 /* */
1223 /*+ REMARKS : - */
1224 /* */
1225 /*2+IMPLEMENTATION************+****************************************/
1226 /* */
1227 /*+ Input/Output: SYS$INPUT, SYS$OUTPUT */
1228 /*+ Return type : INTEGER */
1229 /*+ Status codes: */
1230 /*- STC__SUCCESS : success. */
1231 /*- STC__FAIlURE : failure. */
1232 /*- STC__INVSOCK : invalid socket number. */
1233 /*- STC__TIMEOUT : timeout. */
1234 /*- STC__INVTIME : time limit is unacceptable */
1235 /* negativ or to long. */
1236 /*+ File name : */
1237 /*+ Version : 1.01 */
1238 /*+ Author : R.Fritzsche */
1239 /*+ Last Update : 25-Jan-1994 */
1240 /* */
1241 /*2+UPDATES*******+***********+****************************************/
1242 /* */
1243 /*+ Updates : Date Purpose */
1244 /* */
1245 /*2+INTERNALS*****+***********+****************************************/
1246 /* */
1247 /*+ Utility : EXAMPLES */
1248 /*+ Compile lib.: GOOCINC.TLB */
1249 /*+ Home direct.: GOO$EXAMPLES */
1250 /*+ Created : 25-Jan-1994 */
1251 /* */
1252 /*1- PLI Main ****************+****************************************/
1253 /* %%-HEAD: */
1254 
1256 {
1257  struct timeval read_timeout;
1258  fd_set rset , allset , wset , eset;
1259  INTS4 listenfd , maxfd , sts;
1260 
1261  read_timeout.tv_sec = 0;
1262  read_timeout.tv_usec = 0;
1263 
1264  listenfd = ps_server->sock_rw;
1265 
1266  FD_ZERO(&rset);
1267  FD_ZERO(&wset);
1268  FD_ZERO(&eset);
1269  FD_ZERO(&allset);
1270  FD_SET(listenfd,&rset);
1271  FD_SET(listenfd,&wset);
1272  FD_SET(listenfd,&eset);
1273  maxfd = listenfd;
1274 
1275  sts = select( maxfd + 1 , &rset ,
1276  &wset ,
1277  &eset , &read_timeout);
1278  switch( sts )
1279  {
1280  case -1:
1281  switch( errno )
1282  {
1283  case EBADF : return STC__INVSOCK;
1284  case EINVAL : return STC__INVTIME;
1285  default : return STC__FAILURE;
1286  } /* switch( errno ) */
1287 
1288  case 0: return STC__TIMEOUT;
1289 
1290  } /* end switch( sts ) */
1291 
1292  if( FD_ISSET(listenfd,&eset)) {
1293  return STC__SUCCESS;
1294  }
1295 
1296  if( FD_ISSET(listenfd,&rset)) {
1297  return STC__SUCCESS;
1298  }
1299 
1300  if( FD_ISSET(listenfd,&wset)) {
1301  return STC__SUCCESS;
1302  }
1303 
1304  return STC__FAILURE;
1305 }
1306 
1307 
1308 /* %%+HEAD: */
1309 /*****************+***********+****************************************/
1310 /* */
1311 /* GSI, Gesellschaft fuer Schwerionenforschung mbH */
1312 /* Postfach 11 05 41 */
1313 /* D-6100 Darmstadt 11 */
1314 /* */
1315 /*1+ PLI Main ****************+****************************************/
1316 /* */
1317 /*+ Module : f_stc_disperror */
1318 /* */
1319 /*--------------------------------------------------------------------*/
1320 /*+ CALLING : f_stc_disperror( INTS4 i_error , CHARS c_string[256], */
1321 /* INTS4 i_out ) */
1322 /*--------------------------------------------------------------------*/
1323 /* */
1324 /*+ PURPOSE : f_stc_disperror displays the error message for the */
1325 /* error id ( i_error ) */
1326 /* if i_out = 1 the error message is */
1327 /* copied into c_string, else */
1328 /* f_stc_disperror() print the message */
1329 /* on the terminal. */
1330 /* */
1331 /*+ ARGUMENTS : */
1332 /* */
1333 /*+ I_ERROR : The error id. */
1334 /* */
1335 /*+ C_STRING : The string into f_stc_disperror() copies the */
1336 /* message. */
1337 /* */
1338 /*+ I_OUT : specifies the output device for the error message. */
1339 /* */
1340 /*- I_OUT = 1 : the error message is copied into */
1341 /* the string. */
1342 /*- I_OUT = 0 : the error message is printed on */
1343 /* the terminal. */
1344 /* */
1345 /*+ Return type : integer. */
1346 /* */
1347 /*2+DESCRIPTION***+***********+****************************************/
1348 /* */
1349 /*+ CALLING : f_stc_disperror( INTS4 i_error , CHARS c_string[256], */
1350 /* INTS4 i_out ) */
1351 /* */
1352 /*+ ARGUMENTS : */
1353 /* */
1354 /*+ I_ERROR : The error id. */
1355 /* */
1356 /*+ C_STRING : The string into f_stc_disperror() copies the */
1357 /* message. */
1358 /* */
1359 /*+ I_OUT : specifies the output device for the error message. */
1360 /* */
1361 /*- I_OUT = 1 : the error message is copied into the */
1362 /* string. */
1363 /*- I_OUT = 0 : the error message is printed on the */
1364 /* terminal. */
1365 /* */
1366 /*+ FUNCTION : f_stc_disperror displays the error message for the */
1367 /* error id ( i_error ) */
1368 /* if i_out = 1 the error message is */
1369 /* copied into c_string, else */
1370 /* f_stc_disperror() print the message */
1371 /* on the terminal. */
1372 /* */
1373 /*+ REMARKS : - */
1374 /* */
1375 /*2+IMPLEMENTATION************+****************************************/
1376 /* */
1377 /*+ Input/Output: SYS$INPUT, SYS$OUTPUT */
1378 /*+ Return type : INTEGER */
1379 /*+ Status codes: */
1380 /*- STC__SUCCESS : success. */
1381 /*- STC__FAIlURE : failure. */
1382 /*+ File name : */
1383 /*+ Version : 1.01 */
1384 /*+ Author : R.Fritzsche */
1385 /*+ Last Update : 28-Jan-1994 */
1386 /* */
1387 /*2+UPDATES*******+***********+****************************************/
1388 /* */
1389 /*+ Updates : Date Purpose */
1390 /* */
1391 /*2+INTERNALS*****+***********+****************************************/
1392 /* */
1393 /*+ Utility : EXAMPLES */
1394 /*+ Compile lib.: GOOCINC.TLB */
1395 /*+ Home direct.: GOO$EXAMPLES */
1396 /*+ Created : 28-Jan-1994 */
1397 /* */
1398 /*1- PLI Main ****************+****************************************/
1399 /* %%-HEAD: */
1400 
1401 INTS4 f_stc_disperror(INTS4 i_error, CHARS *c_dest, INTS4 i_out)
1402 {
1403  CHARS c_line[80];
1404 
1405  switch( i_error )
1406  {
1407  case STC__FAILURE :
1408  sprintf(c_line,"-I- f_stc failure");
1409  break;
1410  case STC__SUCCESS :
1411  sprintf(c_line,"-I- f_stc failure");
1412  break;
1413  case STC__INVSOCK :
1414  sprintf(c_line,"-I- f_stc invalid socket number");
1415  break;
1416  case STC__INVBUF :
1417  sprintf(c_line,"-I- f_stc buffer points outside allocated address space");
1418  break;
1419  case STC__NGBUFSIZE :
1420  sprintf(c_line,"-I- f_stc buffer length is negative");
1421  break;
1422  case STC__INVTIME :
1423  sprintf(c_line,"-I- f_stc time limit is negativ or to long");
1424  break;
1425  case STC__TIMEOUT :
1426  sprintf(c_line,"-I- f_stc timeout read data from socket");
1427  break;
1428  case STC__NOTSOCK :
1429  sprintf(c_line,"-I- f_stc socket number points to a file not a socket");
1430  break;
1431  case STC__INVADDR :
1432  sprintf(c_line,"-I- f_stc invalid address specified in parameter");
1433  break;
1434  case STC__INVADDRF :
1435  sprintf(c_line,"-I- f_stc the specified address family is not supported");
1436  break;
1437  case STC__SOCKNSUP :
1438  sprintf(c_line,"-I- f_stc The specified socket type is not supported.");
1439  break;
1440  case STC__INVPROTO :
1441  sprintf(c_line,"-I- f_stc The specified protocol is not supported.");
1442  break;
1443  case STC__SOCKTABF :
1444  sprintf(c_line,"-I- f_stc The per-process descriptor table is full.");
1445  break;
1446  case STC__SOCKSPAF :
1447  sprintf(c_line,"-I- f_stc No buffer space is available. The socket can't be created");
1448  break;
1449  case STC__SOCKISC :
1450  sprintf(c_line,"-I- f_stc socket is already connected.");
1451  break;
1452  case STC__CONNTOUT :
1453  sprintf(c_line,"-I- f_stc connection timed out without establishing a connection.");
1454  break;
1455  case STC__NETUNREA :
1456  sprintf(c_line,"-I- f_stc The network is not reachable from this host.");
1457  break;
1458  case STC__PORTINUS :
1459  sprintf(c_line,"-I- f_stc The specified Internet Address and port is already in use.");
1460  break;
1461  case STC__SOCKISP :
1462  sprintf(c_line,"-I- f_stc socket address is protected.");
1463  break;
1464  case STC__ECONNREF : /* added 17.7.95, H.G. */
1465  sprintf(c_line,"-I- f_stc connection refused.");
1466  break;
1467  case TPS__ECPORTS :
1468  sprintf(c_line,"-I- f_stc error connect portserver");
1469  break;
1470  case TPS__EREGSERV :
1471  sprintf(c_line,"-I- f_stc error register service at portserver");
1472  break;
1473  case TPS__EWTOPORTS :
1474  sprintf(c_line,"-I- f_stc error write buffer to portserver");
1475  break;
1476  case TPS__ERMFRPORTS :
1477  sprintf(c_line,"-I- f_stc error read status message from portserver");
1478  break;
1479  case TPS__EGSERVICE :
1480  sprintf(c_line,"-I- f_stc error get spec. info from portserver");
1481  break;
1482  default:
1483  sprintf(c_line,"-I- f_stc unknown message id %d",i_error);
1484  if(i_out==0)printf("%s\n",c_line);
1485  if(i_out==1)strcpy(c_dest,c_line);
1486  return STC__FAILURE;
1487  } /* end switch( i_error ) */
1488 
1489  if(i_out==0) printf("%s\n",c_line);
1490  if(i_out==1) strcpy(c_dest,c_line);
1491 
1492  return STC__SUCCESS;
1493 } /* 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:1093
#define EAFNOSUPPORT
Definition: typedefs_nt.h:32
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:1255
CHARS c_msg[80]
Definition: f_stccomm.c:21
#define STC__CONNTOUT
Definition: f_stccomm.h:383
#define ENETUNREACH
Definition: typedefs_nt.h:52
INTS4 f_stc_write(void *p_buffer, INTS4 i_buflen, INTS4 i_channel)
Definition: f_stccomm.c:339
#define ECONNRESET
Definition: typedefs_nt.h:24
#define ETIMEDOUT
Definition: typedefs_nt.h:48
#define STC__EINTR
Definition: f_stccomm.h:395
#define ENOTSOCK
Definition: typedefs_nt.h:28
INTS4 f_stc_disperror(INTS4 i_error, CHARS *c_dest, INTS4 i_out)
Definition: f_stccomm.c:1401
#define EISCONN
Definition: typedefs_nt.h:44
#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:1174
#define EADDRINUSE
Definition: typedefs_nt.h:56
#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:36
#define STC__SOCKNSUP
Definition: f_stccomm.h:378
#define ECONNREFUSED
Definition: typedefs_nt.h:60
#define STC__INVSOCK
Definition: f_stccomm.h:370
#define ENOBUFS
Definition: typedefs_nt.h:40
#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:20
#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:183
char CHARS
Definition: typedefs.h:21