5b50fcc0dda0bcb3ba9c8f70e492914b75955774
[ric-plt/lib/rmr.git] / src / rmr / si / src / si95 / sibldpoll.c
1 // vim: noet sw=4 ts=4:
2 /*
3 ==================================================================================
4     Copyright (c) 2020 Nokia
5     Copyright (c) 2020 AT&T Intellectual Property.
6
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
10
11        http://www.apache.org/licenses/LICENSE-2.0
12
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 ==================================================================================
19 */
20
21 /*
22 *****************************************************************************
23 *  Mnemonic: SIbldpoll
24 *  Abstract: This routine will fill in the read and write fdsets in the
25 *            general info struct based on the current transport provider
26 *            list. Those tb blocks that have something queued to send will
27 *            be added to the write fdset. The fdcount variable will be set to
28 *            the highest sid + 1 and it can be passed to the select system
29 *            call when it is made.
30 *
31 *  Parms:    gptr  - Pointer to the general info structure
32 *  Returns:  Nothing
33 *  Date:     26 March 1995
34 *  Author:   E. Scott Daniels
35 *
36 ***************************************************************************
37 */
38 #include "sisetup.h"      //  get definitions etc 
39 #include "sitransport.h"
40
41 extern void SIbldpoll( struct ginfo_blk* gptr  ) {
42         struct tp_blk *tpptr;                                   //  pointer into tp list 
43         struct tp_blk *nextb;                                   //  pointer into tp list 
44
45
46         gptr->fdcount = -1;                                     //  reset largest sid found 
47
48         FD_ZERO( &gptr->readfds );                      //  reset the read and write sets 
49         FD_ZERO( &gptr->writefds );
50         FD_ZERO( &gptr->execpfds );
51
52         for( tpptr = gptr->tplist; tpptr != NULL; tpptr = nextb ) {
53                 nextb = tpptr->next;
54                 if( tpptr->flags & TPF_DELETE ) {
55                         if( tpptr->fd >= 0 ) {                                          // wasn't closed for some reason
56                                 SIterm( gptr, tpptr );
57                         }
58                         SIrm_tpb( gptr, tpptr );                                        // safe to remove the block from the list in this thread
59                 } else {
60                         if( tpptr->fd >= 0 ) {                       //  if valid file descriptor 
61                                 if( tpptr->fd >= gptr->fdcount ) {      
62                                         gptr->fdcount = tpptr->fd + 1;     //  save largest fd (+1) for select 
63                                 }
64
65                                 FD_SET( tpptr->fd, &gptr->execpfds );     //  set all fds for execpts 
66
67                                 if( !(tpptr->flags & TPF_DRAIN) ) {                  //  if not draining 
68                                         FD_SET( tpptr->fd, &gptr->readfds );       //  set test for data flag 
69                                 }
70
71                                 if( tpptr->squeue != NULL ) {                  //  stuff pending to send ? 
72                                         FD_SET( tpptr->fd, &gptr->writefds );   //  set flag to see if writable 
73                                 }
74                         }
75                 }
76         }
77 }