1 // vim: noet sw=4 ts=4:
3 ==================================================================================
4 Copyright (c) 2020 Nokia
5 Copyright (c) 2020 AT&T Intellectual Property.
7 Licensed under the Apache License, Version 2.0 (the "License");
8 you may not use this file except in compliance with the License.
9 You may obtain a copy of the License at
11 http://www.apache.org/licenses/LICENSE-2.0
13 Unless required by applicable law or agreed to in writing, software
14 distributed under the License is distributed on an "AS IS" BASIS,
15 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 See the License for the specific language governing permissions and
17 limitations under the License.
18 ==================================================================================
22 **************************************************************************
23 * Mnemonic: SIinitialise
24 * Abstract: Initialisation and other context management functions.
27 * Author: E. Scott Daniels
29 * Mod: 17 FEB 2002 - To convert to a globally managed gpointer
30 * 09 Mar 2007 - To allow for ipv6 (added SIinitialise() to
32 **************************************************************************
34 #include "sisetup.h" // get the setup stuff
37 Initialise the SI environment. Specifically:
38 allocate the global info block (context)
40 Returns a pointer to the block or nil on failure.
41 On failure errno should indicate the problem.
43 extern struct ginfo_blk* SIinitialise( int opts )
45 struct ginfo_blk *gptr = NULL; // pointer at gen info blk
46 int status = SI_OK; // status of internal processing
47 struct tp_blk *tpptr; // pointer at tp stuff
48 struct sigaction sact; // signal action block
50 int signals = SI_DEF_SIGS; // signals to be set in SIsetsig
54 if( (gptr = SInew( GI_BLK )) != NULL ) { // make our context
55 gptr->rbuf = (char *) malloc( MAX_RBUF ); // get rcv buffer
56 gptr->rbuflen = MAX_RBUF;
57 gptr->tp_map = (struct tp_blk **) malloc( sizeof( struct tp_blk *) * MAX_FDS );
58 if( gptr->tp_map == NULL ) {
59 fprintf( stderr, "SIinit: unable to initialise tp_map: no memory\n" );
63 memset( gptr->tp_map, 0, sizeof( struct tp_blk *) * MAX_FDS );
65 gptr->sierr = SI_ERR_TPORT;
67 gptr->cbtab = (struct callback_blk *) malloc(
68 (sizeof( struct callback_blk ) * MAX_CBS ) );
69 if( gptr->cbtab != NULL ) {
70 for( i = 0; i < MAX_CBS; i++ ) { // initialize callback table
71 gptr->cbtab[i].cbdata = NULL; // no data and no functions
72 gptr->cbtab[i].cbrtn = NULL;
74 } else { // if call back table allocation failed - error off
75 SIshutdown( gptr ); // clean up any open fds
77 gptr = NULL; // dont allow them to continue
81 } // end if gen infor block allocated successfully
84 memset( &sact, 0, sizeof( sact ) );
85 sact.sa_handler = SIG_IGN;
86 sigaction( SIGPIPE, &sact, NULL ); // ignore pipe signals as for some bloody reason linux sets this off if write to closed socket
88 return gptr; // all's well that ends well
92 This will set all of the tcp oriented flags in mask (SI_TF_* constants).
94 extern void SIset_tflags( struct ginfo_blk* gp, int mask ) {
96 gp->tcp_flags |= mask;
101 This will clear all tcp oriented flags set in mask.
103 extern void SIclr_tflags( struct ginfo_blk* gp, int mask ) {
105 gp->tcp_flags &= ~mask;
110 Dump stats to stderr.
112 NOTE: the receive stats are the number of times that wait popped for
113 a file descriptor and NOT the actual number of RMR messages which
114 were contained. Thus it is VERY likely that the receive count
115 reported will not match the number of actual messages sent. These
116 counts should be used only to track activity on a socket.
118 extern void SItp_stats( void *vgp ) {
119 struct ginfo_blk* gp;
122 if( (gp = (struct ginfo_blk *) vgp) != NULL ) {
123 for( tp = gp->tplist; tp != NULL; tp = tp->next ) {
124 rmr_vlog( RMR_VL_DEBUG, "si95: tp: fd=%d sent=%lld rcvd=%lld qc=%lld\n", tp->fd, tp->sent, tp->rcvd, tp->qcount );