More changes for scan corrections and unit test coverage
[ric-plt/lib/rmr.git] / src / rmr / si / src / si95 / sipoll.c
index df71eae..6c8915a 100644 (file)
 
 extern int SIpoll( struct ginfo_blk *gptr, int msdelay )
 {
- //extern int deaths;       //  number of children that died and are zombies
- //extern int sigflags;     //  flags set by the signal handler routine
-
  int fd;                       //  file descriptor for use in this routine
  int ((*cbptr)());             //  pointer to callback routine to call
  int status = SI_OK;              //  return status
- int addrlen;                  //  length of address from recvfrom call
- char *buf;                   //  work buffer pointer
+ int addrlen = 0;              //  length of address from recvfrom call
+ char *buf;                           //  work buffer pointer
  char ibuf[1025];
  int i;                        //  loop index
  struct tp_blk *tpptr;         //  pointer at tp stuff
- struct tp_blk *nextone;        //  pointer at next block to process
+ struct tp_blk *nextone = NULL;        //  pointer at next block to process
  int pstat;                    //  poll status
  int kstat;                    //  keyboard status
  struct timeval  delay;        //  delay to use on select call
  struct sockaddr *uaddr;       //  pointer to udp address
 
- gptr->sierr = SI_ERR_SHUTD;
-
  if( gptr->flags & GIF_SHUTDOWN )     //  cannot do if we should shutdown
   return( SI_ERROR );                    //  so just get out
 
 
- gptr->sierr = SI_ERR_HANDLE;
-
  if( gptr->magicnum != MAGICNUM )     //  if not a valid ginfo block
   return( SI_ERROR );
 
@@ -81,36 +74,12 @@ extern int SIpoll( struct ginfo_blk *gptr, int msdelay )
     pstat = select( gptr->fdcount, &gptr->readfds, &gptr->writefds,
                                &gptr->execpfds, &delay );
 
-   if( (pstat < 0 && errno != EINTR)  )
+   if( pstat < 0 && errno != EINTR  )
     {                             //  poll fail or termination signal rcvd
      gptr->fdcount = 0;           //  prevent trying to look at a session
      gptr->flags |= GIF_SHUTDOWN; //  cause cleanup and exit at end
-     //deaths = 0;                  //  dont need to issue waits on dead child
-     //sigflags = 0;                //  who cares about signals now too
     }
 
-/*
-   while( deaths > 0 )  //  there have been death(s) - keep the dead
-    {                   //  from being zombies - send them to heaven
-     wait( NULL );                       //  issue wait on child
-     deaths--;
-    }                   //  end while dead children to send to heaven
-*/
-
-/*
-  if( sigflags &&        //  if signal received and processing them
-     (cbptr = gptr->cbtab[SI_CB_SIGNAL].cbrtn) != NULL )
-   {
-    while( sigflags != 0 )
-     {
-      i = sigflags;                  //  hold for call
-      sigflags = 0;                  //  incase we are interrupted while away
-      status = (*cbptr)( gptr->cbtab[SI_CB_SIGNAL].cbdata, i );
-      SIcbstat( gptr, status, SI_CB_SIGNAL );    //  handle status
-     }                                           //  end while
-   }
-*/
-
    if( pstat > 0  &&  (! (gptr->flags & GIF_SHUTDOWN)) )
     {
      if( FD_ISSET( 0, &gptr->readfds ) )       //  check for keybd input
@@ -123,10 +92,9 @@ extern int SIpoll( struct ginfo_blk *gptr, int msdelay )
         }                                 //  end if call back was defined
       }
 
-     // for( tpptr = gptr->tplist; tpptr != NULL; tpptr = tpptr->next )
-     for( tpptr = gptr->tplist; tpptr != NULL; tpptr = nextone )
-      {
-       nextone = tpptr->next;                                  //  prevent coredump if we delete the session
+       tpptr = gptr->tplist; 
+       while( tpptr != NULL ) {
+               nextone = tpptr->next;                                  //  allow for a delete in loop
 
        if( tpptr->squeue != NULL && (FD_ISSET( tpptr->fd, &gptr->writefds )) )
         SIsend( gptr, tpptr );              //  send if clear to send
@@ -142,7 +110,7 @@ extern int SIpoll( struct ginfo_blk *gptr, int msdelay )
 
          if( tpptr->flags & TPF_LISTENFD )     //  listen port setup by init?
           {                                    //  yes-assume new session req
-           status = SInewsession( gptr, tpptr );    //  make new session
+           SInewsession( gptr, tpptr );                   //  cannot do anything about failure, so ignore status
           }
          else                              //  data received on a regular port
           if( tpptr->type == SOCK_DGRAM )          //  udp socket?
@@ -156,7 +124,8 @@ extern int SIpoll( struct ginfo_blk *gptr, int msdelay )
                 SIaddress( uaddr, (void **) &buf, AC_TODOT );
                 status = (*cbptr)( gptr->cbtab[SI_CB_RDATA].cbdata, gptr->rbuf, status, buf );
                 SIcbstat( gptr, status, SI_CB_RDATA );    //  handle status
-               free( buf );
+                               free( buf );
+                               buf = NULL;                                             // just to be safe
                }                              //  end if call back was defined
              }                                //  end if status was ok
             free( uaddr );
@@ -184,13 +153,14 @@ extern int SIpoll( struct ginfo_blk *gptr, int msdelay )
             }
            }                                                //  end tcp read
         }                    //  end if event on this fd
+
+               tpptr = nextone;
       }                      //  end for each fd in the list
     }                        //  end if not in shutdown
 
 
  if( gptr->flags & GIF_SHUTDOWN )      //  we need to stop for some reason
   {
-   gptr->sierr = SI_ERR_SHUTD;        //  indicate error exit status
    status = SI_ERROR;                //  status should indicate to user to die
    SIshutdown( gptr );            //  clean things up
   }