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