GSI Object Oriented Online Offline (Go4) GO4-6.4.0
Loading...
Searching...
No Matches
f_stccomm.c
Go to the documentation of this file.
1// $Id$
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
134INTS4 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
339INTS4 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
494INTS4 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 wVersionRequested = MAKEWORD( 2, 2 );
509 //err = WSAStartup( wVersionRequested, &wsaData );
510 if (WSAStartup( wVersionRequested, &wsaData) != 0) {
511 printf("WinSock NOT found");
512 /* Tell the user that we could not find a usable */
513 /* WinSock DLL. */
514 }
515
516 if ( LOBYTE( wsaData.wVersion ) != 2 ||
517 HIBYTE( wsaData.wVersion ) != 2 ) {
518 /* Tell the user that we could not find a usable */
519 /* WinSock DLL.
520 */
521 printf("WinSock %d.%d",LOBYTE( wsaData.wVersion ),HIBYTE( wsaData.wVersion ));
522 WSACleanup( );
523 }
524
525#endif
526
527 s_client.socket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
528
529 *ps_client = s_client;
530 *pi_channel = s_client.socket; /* save channel also in case of error */
531 /* 17.7.95, H.G. */
532 switch( s_client.socket )
533 {
534 case -1:
535 switch( errno )
536 {
537 case EAFNOSUPPORT : return STC__INVADDRF;
538 case ESOCKTNOSUPPORT : return STC__SOCKNSUP;
539 case EPROTONOSUPPORT : return STC__INVPROTO;
540 case EMFILE : return STC__SOCKTABF;
541 case ENOBUFS : return STC__SOCKSPAF;
542 default : return STC__FAILURE;
543 } /* switch( errno ) */
544 } /* switch( s_client.socket) */
545
546
547 if(( s_client.hostentptr = gethostbyname(c_node)) == NULL)
548 {
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 /* printf("--E--f_stc_connectserver(): error gethostbyname: >%s<\n",c_node);*/
557 return STC__FAILURE;
558 }
559
560
561 s_client.hostentstruct = *s_client.hostentptr;
562 s_client.sock.sin_family = s_client.hostentstruct.h_addrtype;
563 s_client.sock.sin_port = htons(l_port);
564 s_client.sock.sin_addr =
565 * ((struct in_addr *) s_client.hostentstruct.h_addr);
566
567 retval = connect( s_client.socket,
568 ( struct sockaddr *) &s_client.sock,
569 sizeof(s_client.sock));
570 if( retval == -1)
571 {
572#ifdef GSI__WINNT
573 closesocket(s_client.socket); /* Mohammad Al-Turany 31.07.00*/
574#else
575 close(s_client.socket); /* close socket here and in any case! */
576 /* H.G., 17.7.95 */
577#endif
578 switch( errno )
579 {
580 case EBADF : return STC__INVSOCK;
581 case ENOTSOCK : return STC__NOTSOCK;
582 case EISCONN : return STC__SOCKISC;
583 case ETIMEDOUT : return STC__CONNTOUT;
584 case ENETUNREACH : return STC__NETUNREA;
585 case EADDRINUSE : return STC__PORTINUS;
586 case ECONNREFUSED : return STC__ECONNREF;
587 default : return STC__FAILURE;
588 } /* switch( errno ) */
589 }
590
591 *ps_client = s_client;
592
593 return STC__SUCCESS;
594
595} /* f_stc_connectserver() */
596
597/* %%+HEAD: */
598/*****************+***********+****************************************/
599/* */
600/* GSI, Gesellschaft fuer Schwerionenforschung mbH */
601/* Postfach 11 05 41 */
602/* D-6100 Darmstadt 11 */
603/* */
604/*1+ PLI Main ****************+****************************************/
605/* */
606/*+ Module : f_stc_acceptclient */
607/* */
608/*--------------------------------------------------------------------*/
609/*+ CALLING : f_stc_acceptclient( struct s_tcpcomm s_server , */
610/* INTS4 pi_channel ) */
611/*--------------------------------------------------------------------*/
612/* */
613/*+ PURPOSE : f_stc_acceptclient. completes a connection between */
614/* server and client. */
615/* f_stc_acceptclient() modify the */
616/* channel Id from the accepted */
617/* client. The channel Id is */
618/* required to read and write data */
619/* to the client. */
620/* */
621/*+ ARGUMENTS : */
622/* */
623/*+ s_server : Pointer to structure s_tcpcomm. */
624/* */
625/*+ pi_channel : Id from the connected client. */
626/* i_channel specifies the address that will be filled */
627/* in with the actual client socket Id. */
628/* */
629/*+ Return type : integer. */
630/* */
631/*2+DESCRIPTION***+***********+****************************************/
632/* */
633/*+ CALLING : f_stc_acceptclient( struct s_tcpcomm s_server , */
634/* INTS4 pi_channel ) */
635/* */
636/*+ PURPOSE : f_stc_acceptclient. completes a connection between */
637/* server and client. */
638/* f_stc_acceptclient() modify the */
639/* channel Id from the accepted */
640/* client. The channel Id is */
641/* required to read and write data */
642/* to the client. */
643/* */
644/*+ ARGUMENTS : */
645/* */
646/*+ s_server : Pointer to structure s_tcpcomm. */
647/* */
648/*+ pi_channel : Id from the connected client. */
649/* i_channel specifies the address that will be filled */
650/* in with the actual client socket id. */
651/* */
652/*+ Return type : integer. */
653/* */
654/*+ REMARKS : - */
655/* */
656/*2+IMPLEMENTATION************+****************************************/
657/* */
658/*+ Input/Output: SYS$INPUT, SYS$OUTPUT */
659/*+ Return type : INTEGER */
660/*+ Status codes: Status of last command */
661/*- STC__SUCCESS : success. */
662/*- STC__FAILURE : failure. */
663/*- STC__INVSOCK : invalid socket number. */
664/*- STC__NOTSOCK : socket number points to a file not */
665/* a socket. */
666/*+ File name : GOO$EXAMPLES: */
667/*+ Version : 1.01 */
668/*+ Author : R.Fritzsche */
669/*+ Last Update : 25-Jan-1994 */
670/* */
671/*2+UPDATES*******+***********+****************************************/
672/* */
673/*+ Updates : Date Purpose */
674/* */
675/*2+INTERNALS*****+***********+****************************************/
676/* */
677/*+ Utility : EXAMPLES */
678/*+ Compile lib.: GOOINC.TLB */
679/*+ Home direct.: GOO$EXAMPLES */
680/*+ Created : 15-Jan-1994 */
681/* */
682/*1- PLI Main ****************+****************************************/
683/* %%-HEAD: */
684
685INTS4 f_stc_acceptclient(struct s_tcpcomm *ps_server, INTS4 *pi_channel)
686{
687#ifdef GSI__AIX
688 *pi_channel = accept( ps_server->sock_rw,
689 ( struct sockaddr *) &ps_server->sock_name,
690 (socklen_t *) &ps_server->namelength);
691#else
692#ifdef GSI__WINNT
693 *pi_channel = accept( ps_server->sock_rw,
694 ( struct sockaddr *) &ps_server->sock_name,
695 (int *) &ps_server->namelength);
696#else
697 *pi_channel = accept( ps_server->sock_rw,
698 ( struct sockaddr *) &ps_server->sock_name,
699 (socklen_t *) &ps_server->namelength);
700#endif
701#endif
702if( *pi_channel == -1)
703{
704 switch( errno )
705 {
706 case EBADF : return STC__INVSOCK;
707 case ENOTSOCK : return STC__NOTSOCK;
708 default : return STC__FAILURE;
709 } /* switch( errno ) */
710}
711
712/*
713 hostname of remote node.
714 he = gethostbyaddr( ps_server->sock_name.sin_addr.s_addr,
715 sizeof(ps_server->sock_name.sin_addr.s_addr),
716 AF_INET );
717
718 if( he != NULL )
719 printf("name of client: %s\n",he->h_name);
720 */
721
722 return STC__SUCCESS;
723} /* end f_stc_acceptclient() */
724
725/* %%+HEAD: */
726/*****************+***********+****************************************/
727/* */
728/* GSI, Gesellschaft fuer Schwerionenforschung mbH */
729/* Postfach 11 05 41 */
730/* D-6100 Darmstadt 11 */
731/* */
732/*1+ PLI Main ****************+****************************************/
733/* */
734/*+ Module : f_stc_createserver */
735/* */
736/*--------------------------------------------------------------------*/
737/*+ CALLING : f_stc_createserver( INTS4 pl_port , */
738/* struct s_tcpcomm ps_server ) */
739/*--------------------------------------------------------------------*/
740/* */
741/*+ PURPOSE : f_stc_createserver creates an endpoint for */
742/* client-server communications. */
743/* The endpoint of communication */
744/* data is not the process name. */
745/* The client-server communication */
746/* use portnumbers as endpoints of */
747/* communications. */
748/* The port numbers in the range */
749/* 1 to 1023 are privileged ports. */
750/* User can use ports in the range */
751/* 1024 to 65535. */
752/* also you can use portnumber 0, */
753/* then f_stc_createserver() search*/
754/* for a free portnumber and modify*/
755/* the value from l_port, */
756/* else f_stc_createserver() */
757/* returns 0 */
758/* */
759/*+ ARGUMENTS : */
760/* */
761/*+ l_port : Pointer to Portnumber. ( 1024 - 65535 ) or ( 0 ). */
762/* */
763/*+ s_server : Pointer to structure s_tcpcomm */
764/* s_server specifies the address that will be filled */
765/* in with the actual communication values. */
766/* */
767/*+ Return type : integer. */
768/* */
769/*2+DESCRIPTION***+***********+****************************************/
770/* */
771/*+ CALLING : f_stc_createserver( INTS4 l_port , */
772/* struct s_tcpcomm s_server) */
773/* */
774/*+ ARGUMENTS : */
775/* */
776/*+ l_port : Pointer to Portnumber. ( 1024 - 65535 ) or ( 0 ). */
777/* l_port specifies the address that will be filled */
778/* in with the actual server portnumber. */
779/* */
780/*+ S_SERVER : Pointer to structure s_tcpcomm */
781/* s_server specifies the address that will be filled */
782/* in with the actual communication values. */
783/* */
784/*+ FUNCTION : f_stc_createserver creates an endpoint for */
785/* client - server communications. */
786/* The endpoint of communication for */
787/* data is not the a process name. */
788/* The client - server communication */
789/* use portnumbers as endpoints of */
790/* communications. */
791/* The port numbers in the range */
792/* 1 to 1023 are privileged ports. */
793/* User can use ports in the range */
794/* 1024 to 65535. */
795/* also you can use portnumber 0, */
796/* then f_stc_createserver() search */
797/* for a free portnumber and write */
798/* the free portnumber to l_port, */
799/* else f_stc_createserver() */
800/* returns 0 */
801/* */
802/*+ REMARKS : - */
803/* */
804/*2+IMPLEMENTATION************+****************************************/
805/* */
806/*+ Input/Output: SYS$INPUT, SYS$OUTPUT */
807/*+ Return type : INTEGER */
808/*+ Status codes: */
809/*- STC__SUCCESS : success. */
810/*- STC__FAILURE : failure. */
811/*- STC__INVADDRF : The specified address family is not */
812/* supported. */
813/*- STC__SOCKNSUP : The specified socket type is not */
814/* supported. */
815/*- STC__INVPROTO : The specified protocol is not */
816/* supported. */
817/*- STC__SOCKTABF : The per-process descriptor table */
818/* is full. */
819/*- STC__SOCKSPAF : No buffer space is available. */
820/* The socket can't be created. */
821/*- STC__INVSOCK : invalid socket number. */
822/*- STC__NOTSOCK : socket number points to a file not */
823/* a socket. */
824/*- STC__PORTINUS : The specified Internet Address */
825/* and port is already in use. */
826/*- STC__SOCKISC : socket is already connected. */
827/*- STC__SOCKISP : socket address is protected and the */
828/* current user has inadequate */
829/* permission to access it. */
830/*+ File name : */
831/*+ Version : 1.01 */
832/*+ Author : R.Fritzsche */
833/*+ Last Update : 25-Jan-1994 */
834/* */
835/*2+UPDATES*******+***********+****************************************/
836/* */
837/*+ Updates : Date Purpose */
838/* */
839/*2+INTERNALS*****+***********+****************************************/
840/* */
841/*+ Utility : EXAMPLES */
842/*+ Compile lib.: GOOINC.TLB */
843/*+ Home direct.: GOO$EXAMPLES */
844/*+ Created : 25-Jan-1994 */
845/* */
846/*1- PLI Main ****************+****************************************/
847/* %%-HEAD: */
848
849INTS4 f_stc_createserver(INTS4 *pl_port, struct s_tcpcomm *ps_server)
850{
851
852 INTS4 retval , retry;
853 struct s_tcpcomm s_server;
854
855
856#ifdef GSI__WINNT
857 WORD wVersionRequested;
858 WSADATA wsaData;
859 wVersionRequested = MAKEWORD( 2, 2 );
860 //err = WSAStartup( wVersionRequested, &wsaData );
861 if (WSAStartup( wVersionRequested, &wsaData) != 0) {
862 printf("WinSock NOT found");
863 /* Tell the user that we could not find a usable */
864 /* WinSock DLL. */
865 }
866
867 if ( LOBYTE( wsaData.wVersion ) != 2 ||
868 HIBYTE( wsaData.wVersion ) != 2 ) {
869 /* Tell the user that we could not find a usable */
870 /* WinSock DLL.
871 */
872 printf("WinSock %d.%d",LOBYTE( wsaData.wVersion ),HIBYTE( wsaData.wVersion ));
873 WSACleanup( );
874 }
875
876#endif
877
878 if( *pl_port == 0 ) {
879 retry = 1 ;
880 *pl_port = 1024;
881 }
882 else
883 retry = 0;
884
885 s_server.sock_rw = socket (AF_INET, SOCK_STREAM, IPPROTO_TCP);
886
887 switch( s_server.sock_rw )
888 {
889 case -1:
890 switch( errno )
891 {
892 case EAFNOSUPPORT : return STC__INVADDRF;
893 case ESOCKTNOSUPPORT : return STC__SOCKNSUP;
894 case EPROTONOSUPPORT : return STC__INVPROTO;
895 case EMFILE : return STC__SOCKTABF;
896 case ENOBUFS : return STC__SOCKSPAF;
897 default : return STC__FAILURE;
898 } /* switch( errno ) */
899 } /* switch( s_server.sock_rw) */
900
901
902 retval = gethostname(s_server.hostname,sizeof(s_server.hostname));
903 if(retval)
904 {
905 printf("--E--f_stc_createserver() error get local hostname\n");
906 return STC__FAILURE;
907 }
908
909 if((s_server.hostentptr = gethostbyname (s_server.hostname)) == NULL)
910 {
911 printf("--E--f_stc_createserver() error get local Internet address\n");
912 return STC__FAILURE;
913 }
914
915 bzero( (CHARS *) &s_server.sock_name , sizeof( s_server.sock_name ) );
916 s_server.sock_name.sin_family = AF_INET;
917 s_server.sock_name.sin_addr.s_addr = htonl(INADDR_ANY);
918 s_server.sock_name.sin_port = htons(*pl_port);
919
920 retval = bind( s_server.sock_rw,
921 (struct sockaddr *) &s_server.sock_name,
922 sizeof(s_server.sock_name));
923
924 if( retval == -1 && retry == 0 )
925 {
926 close( s_server.sock_rw );
927
928 switch( errno )
929 {
930 case EBADF : return STC__INVSOCK;
931 case ENOTSOCK : return STC__NOTSOCK;
932 case EADDRINUSE : return STC__PORTINUS;
933 case EINVAL : return STC__SOCKISC;
934 case EACCES : return STC__SOCKISP;
935 default : return STC__FAILURE;
936 }
937 }
938
939 retval = -1;
940
941 while ( retval == -1 && retry == 1 )
942 {
943
944 s_server.sock_rw = socket (AF_INET, SOCK_STREAM, IPPROTO_TCP);
945
946 switch( s_server.sock_rw )
947 {
948 case -1:
949 switch( errno )
950 {
951 case EAFNOSUPPORT : return STC__INVADDRF;
952 case ESOCKTNOSUPPORT : return STC__SOCKNSUP;
953 case EPROTONOSUPPORT : return STC__INVPROTO;
954 case EMFILE : return STC__SOCKTABF;
955 case ENOBUFS : return STC__SOCKSPAF;
956 default : return STC__FAILURE;
957 }
958 }
959
960 retval = gethostname(s_server.hostname,sizeof(s_server.hostname));
961 if(retval)
962 {
963 printf("--E--f_stc_createserver() error get local hostname\n");
964 return STC__FAILURE;
965 }
966
967
968 if((s_server.hostentptr = gethostbyname (s_server.hostname)) == NULL)
969 {
970 printf("--E--f_stc_createserver() error get local Internet address\n");
971 return STC__FAILURE;
972 }
973
974 retval = -1;
975
976 bzero( (CHARS *) &s_server.sock_name , sizeof( s_server.sock_name ) );
977 s_server.sock_name.sin_family = AF_INET;
978 s_server.sock_name.sin_addr.s_addr = htonl(INADDR_ANY);
979 s_server.sock_name.sin_port = htons(*pl_port);
980
981 retval = bind( s_server.sock_rw,
982 (struct sockaddr *) &s_server.sock_name,
983 sizeof(s_server.sock_name));
984 if( retval == -1 )
985 {
986 close( s_server.sock_rw );
987
988 *pl_port += 1;
989
990 if( *pl_port > 65535 )
991 {
992 printf("--E--f_stc_createserver() portnumber exceeded > 655535\n");
993
994 switch( errno )
995 {
996 case EBADF : return STC__INVSOCK;
997 case ENOTSOCK : return STC__NOTSOCK;
998 case EADDRINUSE : return STC__PORTINUS;
999 case EINVAL : return STC__SOCKISC;
1000 case EACCES : return STC__SOCKISP;
1001 default : return STC__FAILURE;
1002 } /* end switch( errno ) */
1003
1004 } /* end if *pl_port > ... ) */
1005
1006 } /* end if (retval == -1 ) */
1007
1008
1009 }
1010
1011 retval = listen(s_server.sock_rw,5);
1012 if( retval == -1 )
1013 {
1014 switch( errno )
1015 {
1016 case EBADF : return STC__INVSOCK;
1017 case ENOTSOCK : return STC__NOTSOCK;
1018 default : return STC__FAILURE;
1019 }
1020 }
1021
1022 s_server.namelength = sizeof( s_server.sock_name);
1023
1024 *ps_server = s_server;
1025
1026 return STC__SUCCESS;
1027} /* end f_stc_createserver() */
1028
1029/* %%+HEAD: */
1030/*****************+***********+****************************************/
1031/* */
1032/* GSI, Gesellschaft fuer Schwerionenforschung mbH */
1033/* Postfach 11 05 41 */
1034/* D-6100 Darmstadt 11 */
1035/* */
1036/*1+ PLI Main ****************+****************************************/
1037/* */
1038/*+ Module : f_stc_close */
1039/* */
1040/*--------------------------------------------------------------------*/
1041/*+ CALLING : f_stc_close( struct s_tcpcomm ps_tcp ) */
1042/*--------------------------------------------------------------------*/
1043/* */
1044/*+ PURPOSE : f_stc_close close the client server */
1045/* communication. */
1046/* */
1047/*+ ARGUMENTS : */
1048/* */
1049/*+ S_TCP : Pointer to structure s_tcpcomm. */
1050/* */
1051/*+ Return type : integer. */
1052/* */
1053/*2+DESCRIPTION***+***********+****************************************/
1054/* */
1055/*+ CALLING : f_stc_close( struct s_tcpcomm ps_tcp ) */
1056/* */
1057/*+ ARGUMENTS : */
1058/* */
1059/*+ FUNCTION : f_stc_close close the client server */
1060/* communication. */
1061/* */
1062/*+ S_TCP : Pointer to structure s_tcpcomm. */
1063/* */
1064/*+ REMARKS : - */
1065/* */
1066/*2+IMPLEMENTATION************+****************************************/
1067/* */
1068/*+ Input/Output: SYS$INPUT, SYS$OUTPUT */
1069/*+ Return type : INTEGER */
1070/*+ File name : */
1071/*+ Version : 1.01 */
1072/*+ Author : R.Fritzsche */
1073/*+ Last Update : 25-Jan-1994 */
1074/* */
1075/*2+UPDATES*******+***********+****************************************/
1076/* */
1077/*+ Updates : Date Purpose */
1078/* */
1079/*2+INTERNALS*****+***********+****************************************/
1080/* */
1081/*+ Utility : EXAMPLES */
1082/*+ Compile lib.: GOOCINC.TLB */
1083/*+ Home direct.: GOO$EXAMPLES */
1084/*+ Created : 25-Jan-1994 */
1085/* */
1086/*1- PLI Main ****************+****************************************/
1087/* %%-HEAD: */
1088
1090{
1091 INTS4 retval;
1092
1093 if( ps_tcp->socket )
1094 {
1095 retval = shutdown( ps_tcp->socket,2);
1096 if(retval == -1) {
1097 return STC__FAILURE;
1098 }
1099 retval = close(ps_tcp->socket);
1100 if(retval == -1) {
1101 return STC__FAILURE;
1102 }
1103
1104 return STC__SUCCESS;
1105 }
1106
1107 return STC__FAILURE;
1108} /* f_stc_close() */
1109
1110/* %%+HEAD: */
1111/*****************+***********+****************************************/
1112/* */
1113/* GSI, Gesellschaft fuer Schwerionenforschung mbH */
1114/* Postfach 11 05 41 */
1115/* D-6100 Darmstadt 11 */
1116/* */
1117/*1+ PLI Main ****************+****************************************/
1118/* */
1119/*+ Module : f_stc_discclient */
1120/* */
1121/*--------------------------------------------------------------------*/
1122/*+ CALLING : f_stc_discclient( INTS4 i_channel ) */
1123/*--------------------------------------------------------------------*/
1124/* */
1125/*+ PURPOSE : f_stc_discclient close the specified client */
1126/* server communication. */
1127/* */
1128/*+ ARGUMENTS : */
1129/* */
1130/*+ I_CHANNEL : Channel Id from the specified client. */
1131/* */
1132/*+ Return type : integer. */
1133/* */
1134/*2+DESCRIPTION***+***********+****************************************/
1135/* */
1136/*+ CALLING : f_stc_discclient( INTS4 i_channel ) */
1137/* */
1138/*+ ARGUMENTS : */
1139/* */
1140/*+ FUNCTION : f_stc_discclient close the specified client */
1141/* server communication. */
1142/* */
1143/*+ I_CHANNEL : Channel Id from the specified client. */
1144/* */
1145/*+ REMARKS : - */
1146/* */
1147/*2+IMPLEMENTATION************+****************************************/
1148/* */
1149/*+ Input/Output: SYS$INPUT, SYS$OUTPUT */
1150/*+ Return type : INTEGER */
1151/*+ File name : */
1152/*+ Version : 1.01 */
1153/*+ Author : R.Fritzsche */
1154/*+ Last Update : 01-Mar-1994 */
1155/* */
1156/*2+UPDATES*******+***********+****************************************/
1157/* */
1158/*+ Updates : Date Purpose */
1159/* */
1160/*2+INTERNALS*****+***********+****************************************/
1161/* */
1162/*+ Utility : EXAMPLES */
1163/*+ Compile lib.: */
1164/*+ Home direct.: */
1165/*+ Created : 01-Mar-1994 */
1166/* */
1167/*1- PLI Main ****************+****************************************/
1168/* %%-HEAD: */
1169
1171{
1172 INTS4 retval;
1173
1174 /* call of shutdown removed 17.7.95, H.G. */
1175 retval = close( i_channel );
1176 if(retval == -1)
1177 return STC__FAILURE;
1178
1179 return STC__SUCCESS;
1180} /* f_stc_discclient() */
1181
1182/* %%+HEAD: */
1183/*****************+***********+****************************************/
1184/* */
1185/* GSI, Gesellschaft fuer Schwerionenforschung mbH */
1186/* Postfach 11 05 41 */
1187/* D-6100 Darmstadt 11 */
1188/* */
1189/*1+ PLI Main ****************+****************************************/
1190/* */
1191/*+ Module : f_stc_listenserver */
1192/* */
1193/*--------------------------------------------------------------------*/
1194/*+ CALLING : f_stc_listenserver( struct s_tcpcomm ps_server ) */
1195/*--------------------------------------------------------------------*/
1196/* */
1197/*+ PURPOSE : f_stc_listenserver look for a pending client */
1198/* connection on the specified */
1199/* server. */
1200/* */
1201/*+ ARGUMENTS : */
1202/* */
1203/*+ PS_SERVER : Pointer to structure s_tcpcomm. */
1204/* */
1205/*+ Return type : integer. */
1206/* */
1207/*2+DESCRIPTION***+***********+****************************************/
1208/* */
1209/*+ CALLING : f_stc_listenserver( struct s_tcpcomm ps_server ) */
1210/* */
1211/*+ ARGUMENTS : */
1212/* */
1213/*+ FUNCTION : f_stc_listenserver look for a pending client */
1214/* connection on the specified */
1215/* server. */
1216/* */
1217/*+ PS_SERVER : Pointer to structure s_tcpcomm. */
1218/* */
1219/*+ REMARKS : - */
1220/* */
1221/*2+IMPLEMENTATION************+****************************************/
1222/* */
1223/*+ Input/Output: SYS$INPUT, SYS$OUTPUT */
1224/*+ Return type : INTEGER */
1225/*+ Status codes: */
1226/*- STC__SUCCESS : success. */
1227/*- STC__FAIlURE : failure. */
1228/*- STC__INVSOCK : invalid socket number. */
1229/*- STC__TIMEOUT : timeout. */
1230/*- STC__INVTIME : time limit is unacceptable */
1231/* negativ or to long. */
1232/*+ File name : */
1233/*+ Version : 1.01 */
1234/*+ Author : R.Fritzsche */
1235/*+ Last Update : 25-Jan-1994 */
1236/* */
1237/*2+UPDATES*******+***********+****************************************/
1238/* */
1239/*+ Updates : Date Purpose */
1240/* */
1241/*2+INTERNALS*****+***********+****************************************/
1242/* */
1243/*+ Utility : EXAMPLES */
1244/*+ Compile lib.: GOOCINC.TLB */
1245/*+ Home direct.: GOO$EXAMPLES */
1246/*+ Created : 25-Jan-1994 */
1247/* */
1248/*1- PLI Main ****************+****************************************/
1249/* %%-HEAD: */
1250
1252{
1253 struct timeval read_timeout;
1254 fd_set rset , allset , wset , eset;
1255 INTS4 listenfd , maxfd , sts;
1256
1257 read_timeout.tv_sec = 0;
1258 read_timeout.tv_usec = 0;
1259
1260 listenfd = ps_server->sock_rw;
1261
1262 FD_ZERO(&rset);
1263 FD_ZERO(&wset);
1264 FD_ZERO(&eset);
1265 FD_ZERO(&allset);
1266 FD_SET(listenfd,&rset);
1267 FD_SET(listenfd,&wset);
1268 FD_SET(listenfd,&eset);
1269 maxfd = listenfd;
1270
1271 sts = select( maxfd + 1 , &rset ,
1272 &wset ,
1273 &eset , &read_timeout);
1274 switch( sts )
1275 {
1276 case -1:
1277 switch( errno )
1278 {
1279 case EBADF : return STC__INVSOCK;
1280 case EINVAL : return STC__INVTIME;
1281 default : return STC__FAILURE;
1282 } /* switch( errno ) */
1283
1284 case 0: return STC__TIMEOUT;
1285
1286 } /* end switch( sts ) */
1287
1288 if( FD_ISSET(listenfd,&eset)) {
1289 return STC__SUCCESS;
1290 }
1291
1292 if( FD_ISSET(listenfd,&rset)) {
1293 return STC__SUCCESS;
1294 }
1295
1296 if( FD_ISSET(listenfd,&wset)) {
1297 return STC__SUCCESS;
1298 }
1299
1300 return STC__FAILURE;
1301}
1302
1303
1304/* %%+HEAD: */
1305/*****************+***********+****************************************/
1306/* */
1307/* GSI, Gesellschaft fuer Schwerionenforschung mbH */
1308/* Postfach 11 05 41 */
1309/* D-6100 Darmstadt 11 */
1310/* */
1311/*1+ PLI Main ****************+****************************************/
1312/* */
1313/*+ Module : f_stc_disperror */
1314/* */
1315/*--------------------------------------------------------------------*/
1316/*+ CALLING : f_stc_disperror( INTS4 i_error , CHARS c_string[256], */
1317/* INTS4 i_out ) */
1318/*--------------------------------------------------------------------*/
1319/* */
1320/*+ PURPOSE : f_stc_disperror displays the error message for the */
1321/* error id ( i_error ) */
1322/* if i_out = 1 the error message is */
1323/* copied into c_string, else */
1324/* f_stc_disperror() print the message */
1325/* on the terminal. */
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 */
1337/* the string. */
1338/*- I_OUT = 0 : the error message is printed on */
1339/* the terminal. */
1340/* */
1341/*+ Return type : integer. */
1342/* */
1343/*2+DESCRIPTION***+***********+****************************************/
1344/* */
1345/*+ CALLING : f_stc_disperror( INTS4 i_error , CHARS c_string[256], */
1346/* INTS4 i_out ) */
1347/* */
1348/*+ ARGUMENTS : */
1349/* */
1350/*+ I_ERROR : The error id. */
1351/* */
1352/*+ C_STRING : The string into f_stc_disperror() copies the */
1353/* message. */
1354/* */
1355/*+ I_OUT : specifies the output device for the error message. */
1356/* */
1357/*- I_OUT = 1 : the error message is copied into the */
1358/* string. */
1359/*- I_OUT = 0 : the error message is printed on the */
1360/* terminal. */
1361/* */
1362/*+ FUNCTION : f_stc_disperror displays the error message for the */
1363/* error id ( i_error ) */
1364/* if i_out = 1 the error message is */
1365/* copied into c_string, else */
1366/* f_stc_disperror() print the message */
1367/* on the terminal. */
1368/* */
1369/*+ REMARKS : - */
1370/* */
1371/*2+IMPLEMENTATION************+****************************************/
1372/* */
1373/*+ Input/Output: SYS$INPUT, SYS$OUTPUT */
1374/*+ Return type : INTEGER */
1375/*+ Status codes: */
1376/*- STC__SUCCESS : success. */
1377/*- STC__FAIlURE : failure. */
1378/*+ File name : */
1379/*+ Version : 1.01 */
1380/*+ Author : R.Fritzsche */
1381/*+ Last Update : 28-Jan-1994 */
1382/* */
1383/*2+UPDATES*******+***********+****************************************/
1384/* */
1385/*+ Updates : Date Purpose */
1386/* */
1387/*2+INTERNALS*****+***********+****************************************/
1388/* */
1389/*+ Utility : EXAMPLES */
1390/*+ Compile lib.: GOOCINC.TLB */
1391/*+ Home direct.: GOO$EXAMPLES */
1392/*+ Created : 28-Jan-1994 */
1393/* */
1394/*1- PLI Main ****************+****************************************/
1395/* %%-HEAD: */
1396
1397INTS4 f_stc_disperror(INTS4 i_error, CHARS *c_dest, INTS4 i_out)
1398{
1399 CHARS c_line[80];
1400
1401 switch( i_error )
1402 {
1403 case STC__FAILURE :
1404 sprintf(c_line,"-I- f_stc failure");
1405 break;
1406 case STC__SUCCESS :
1407 sprintf(c_line,"-I- f_stc failure");
1408 break;
1409 case STC__INVSOCK :
1410 sprintf(c_line,"-I- f_stc invalid socket number");
1411 break;
1412 case STC__INVBUF :
1413 sprintf(c_line,"-I- f_stc buffer points outside allocated address space");
1414 break;
1415 case STC__NGBUFSIZE :
1416 sprintf(c_line,"-I- f_stc buffer length is negative");
1417 break;
1418 case STC__INVTIME :
1419 sprintf(c_line,"-I- f_stc time limit is negativ or to long");
1420 break;
1421 case STC__TIMEOUT :
1422 sprintf(c_line,"-I- f_stc timeout read data from socket");
1423 break;
1424 case STC__NOTSOCK :
1425 sprintf(c_line,"-I- f_stc socket number points to a file not a socket");
1426 break;
1427 case STC__INVADDR :
1428 sprintf(c_line,"-I- f_stc invalid address specified in parameter");
1429 break;
1430 case STC__INVADDRF :
1431 sprintf(c_line,"-I- f_stc the specified address family is not supported");
1432 break;
1433 case STC__SOCKNSUP :
1434 sprintf(c_line,"-I- f_stc The specified socket type is not supported.");
1435 break;
1436 case STC__INVPROTO :
1437 sprintf(c_line,"-I- f_stc The specified protocol is not supported.");
1438 break;
1439 case STC__SOCKTABF :
1440 sprintf(c_line,"-I- f_stc The per-process descriptor table is full.");
1441 break;
1442 case STC__SOCKSPAF :
1443 sprintf(c_line,"-I- f_stc No buffer space is available. The socket can't be created");
1444 break;
1445 case STC__SOCKISC :
1446 sprintf(c_line,"-I- f_stc socket is already connected.");
1447 break;
1448 case STC__CONNTOUT :
1449 sprintf(c_line,"-I- f_stc connection timed out without establishing a connection.");
1450 break;
1451 case STC__NETUNREA :
1452 sprintf(c_line,"-I- f_stc The network is not reachable from this host.");
1453 break;
1454 case STC__PORTINUS :
1455 sprintf(c_line,"-I- f_stc The specified Internet Address and port is already in use.");
1456 break;
1457 case STC__SOCKISP :
1458 sprintf(c_line,"-I- f_stc socket address is protected.");
1459 break;
1460 case STC__ECONNREF : /* added 17.7.95, H.G. */
1461 sprintf(c_line,"-I- f_stc connection refused.");
1462 break;
1463 case TPS__ECPORTS :
1464 sprintf(c_line,"-I- f_stc error connect portserver");
1465 break;
1466 case TPS__EREGSERV :
1467 sprintf(c_line,"-I- f_stc error register service at portserver");
1468 break;
1469 case TPS__EWTOPORTS :
1470 sprintf(c_line,"-I- f_stc error write buffer to portserver");
1471 break;
1472 case TPS__ERMFRPORTS :
1473 sprintf(c_line,"-I- f_stc error read status message from portserver");
1474 break;
1475 case TPS__EGSERVICE :
1476 sprintf(c_line,"-I- f_stc error get spec. info from portserver");
1477 break;
1478 default:
1479 sprintf(c_line,"-I- f_stc unknown message id %d",i_error);
1480 if(i_out == 0) printf("%s\n",c_line);
1481 if(i_out == 1) strcpy(c_dest,c_line);
1482 return STC__FAILURE;
1483 } /* end switch( i_error ) */
1484
1485 if(i_out==0) printf("%s\n",c_line);
1486 if(i_out==1) strcpy(c_dest,c_line);
1487
1488 return STC__SUCCESS;
1489} /* f_stc_disperror() */
int i_channel
Definition f_evcli.c:167
INTS4 f_stc_write(void *p_buffer, INTS4 i_buflen, INTS4 i_channel)
Definition f_stccomm.c:339
INTS4 f_stc_read(void *p_buffer, INTS4 i_buflen, INTS4 i_channel, INTS4 i_timeout)
Definition f_stccomm.c:134
INTS4 f_stc_listenserver(struct s_tcpcomm *ps_server)
Definition f_stccomm.c:1251
CHARS c_msg[80]
Definition f_stccomm.c:21
INTS4 f_stc_connectserver(CHARS *c_node, INTS4 l_port, INTS4 *pi_channel, struct s_tcpcomm *ps_client)
Definition f_stccomm.c:494
INTS4 f_stc_discclient(INTS4 i_channel)
Definition f_stccomm.c:1170
INTS4 f_stc_createserver(INTS4 *pl_port, struct s_tcpcomm *ps_server)
Definition f_stccomm.c:849
INTS4 f_stc_acceptclient(struct s_tcpcomm *ps_server, INTS4 *pi_channel)
Definition f_stccomm.c:685
INTS4 f_stc_close(struct s_tcpcomm *ps_tcp)
Definition f_stccomm.c:1089
INTS4 f_stc_disperror(INTS4 i_error, CHARS *c_dest, INTS4 i_out)
Definition f_stccomm.c:1397
#define STC__SUCCESS
Definition f_stccomm.h:369
#define STC__NOTSOCK
Definition f_stccomm.h:375
#define STC__FAILURE
Definition f_stccomm.h:368
#define STC__NETUNREA
Definition f_stccomm.h:384
#define STC__PORTINUS
Definition f_stccomm.h:385
#define STC__SOCKISP
Definition f_stccomm.h:386
#define STC__INVBUF
Definition f_stccomm.h:371
#define STC__TIMEOUT
Definition f_stccomm.h:374
#define STC__SOCKTABF
Definition f_stccomm.h:380
#define TPS__EGSERVICE
Definition f_stccomm.h:391
#define TPS__EREGSERV
Definition f_stccomm.h:388
#define STC__EINTR
Definition f_stccomm.h:395
#define TPS__ERMFRPORTS
Definition f_stccomm.h:390
#define STC__CONNTOUT
Definition f_stccomm.h:383
#define STC__ECONNRES
Definition f_stccomm.h:396
#define STC__INVSOCK
Definition f_stccomm.h:370
#define STC__SOCKISC
Definition f_stccomm.h:382
#define TPS__EWTOPORTS
Definition f_stccomm.h:389
#define STC__INVADDRF
Definition f_stccomm.h:377
#define STC__NGBUFSIZE
Definition f_stccomm.h:372
#define TPS__ECPORTS
Definition f_stccomm.h:387
#define STC__INVADDR
Definition f_stccomm.h:376
#define STC__INVTIME
Definition f_stccomm.h:373
#define STC__INVPROTO
Definition f_stccomm.h:379
#define STC__SOCKSPAF
Definition f_stccomm.h:381
#define STC__ECONNREF
Definition f_stccomm.h:394
#define STC__NODATA
Definition f_stccomm.h:393
#define STC__SOCKNSUP
Definition f_stccomm.h:378
INTS1 hostname[256]
Definition f_stccomm.h:310
INTS4 sock_rw
Definition f_stccomm.h:305
struct hostent * hostentptr
Definition f_stccomm.h:309
INTS4 socket
Definition f_stccomm.h:305
INTS4 namelength
Definition f_stccomm.h:305
struct hostent hostentstruct
Definition f_stccomm.h:308
struct sockaddr_in sock sock_name
Definition f_stccomm.h:307
int INTS4
Definition typedefs.h:28
char INTS1
Definition typedefs.h:24
char CHARS
Definition typedefs.h:21
#define EISCONN
Definition typedefs_nt.h:46
#define ENETUNREACH
Definition typedefs_nt.h:54
#define EAFNOSUPPORT
Definition typedefs_nt.h:34
#define ETIMEDOUT
Definition typedefs_nt.h:50
#define EADDRINUSE
Definition typedefs_nt.h:58
#define ESOCKTNOSUPPORT
Definition typedefs_nt.h:22
#define ENOBUFS
Definition typedefs_nt.h:42
#define ECONNREFUSED
Definition typedefs_nt.h:62
#define EPROTONOSUPPORT
Definition typedefs_nt.h:38
#define ECONNRESET
Definition typedefs_nt.h:26
#define ENOTSOCK
Definition typedefs_nt.h:30