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->cbtab = (struct callback_blk *) malloc(
66 (sizeof( struct callback_blk ) * MAX_CBS ) );
67 if( gptr->cbtab != NULL ) {
68 for( i = 0; i < MAX_CBS; i++ ) { // initialize callback table
69 gptr->cbtab[i].cbdata = NULL; // no data and no functions
70 gptr->cbtab[i].cbrtn = NULL;
72 } else { // if call back table allocation failed - error off
73 SIshutdown( gptr ); // clean up any open fds
75 gptr = NULL; // dont allow them to continue
77 } // end if gen infor block allocated successfully
80 memset( &sact, 0, sizeof( sact ) );
81 sact.sa_handler = SIG_IGN;
82 sigaction( SIGPIPE, &sact, NULL ); // ignore pipe signals as for some bloody reason linux sets this off if write to closed socket
84 return gptr; // all's well that ends well
88 This will set all of the tcp oriented flags in mask (SI_TF_* constants).
90 extern void SIset_tflags( struct ginfo_blk* gp, int mask ) {
92 gp->tcp_flags |= mask;
97 This will clear all tcp oriented flags set in mask.
99 extern void SIclr_tflags( struct ginfo_blk* gp, int mask ) {
101 gp->tcp_flags &= ~mask;
106 Dump stats to stderr.
108 NOTE: the receive stats are the number of times that wait popped for
109 a file descriptor and NOT the actual number of RMR messages which
110 were contained. Thus it is VERY likely that the receive count
111 reported will not match the number of actual messages sent. These
112 counts should be used only to track activity on a socket.
114 extern void SItp_stats( void *vgp ) {
115 struct ginfo_blk* gp;
118 if( (gp = (struct ginfo_blk *) vgp) != NULL ) {
119 for( tp = gp->tplist; tp != NULL; tp = tp->next ) {
120 rmr_vlog( RMR_VL_DEBUG, "si95: tp: fd=%d sent=%lld rcvd=%lld qc=%lld\n", tp->fd, tp->sent, tp->rcvd, tp->qcount );