fixing RMR messages with negative size
[ric-plt/lib/rmr.git] / src / rmr / si / src / si95 / siestablish.c
index a62490d..f2bb752 100644 (file)
        Returns a transport struct which is the main context for the listener.
 */
 extern struct tp_blk *SIlisten_prep( int type, char* abuf, int family ) {
-       struct tp_blk *tptr;         //  pointer at new tp block
-       int status = SI_OK;          //  processing status
+       struct tp_blk *tptr;        //  pointer at new tp block
        struct sockaddr *addr;          //  IP address we are requesting
-       int protocol;                //  protocol for socket call
        int optval = 0;
        int alen = 0;
+       int status = SI_OK;          //  processing status
+       int protocol;                //  protocol for socket call
 
-       tptr = (struct tp_blk *) SInew( TP_BLK );     //  new transport info block
+       tptr = (struct tp_blk *) SInew( TP_BLK );     // transport info
 
-       if( tptr != NULL )
-       {
+       if( tptr != NULL ) {
                addr = NULL;
 
-               switch( type )                  //  things specifc to tcp or udp
-               {
-                       case UDP_DEVICE:
-                               tptr->type = SOCK_DGRAM;
-                               protocol = IPPROTO_UDP;
-                               break;
-
-                       case TCP_DEVICE:
-                       default:
-                               tptr->type = SOCK_STREAM;
-                               protocol = IPPROTO_TCP;
+               if( type == UDP_DEVICE ) {
+                       tptr->type = SOCK_DGRAM;
+                       protocol = IPPROTO_UDP;
+               } else {
+                       tptr->type = SOCK_STREAM;
+                       protocol = IPPROTO_TCP;
                }
 
                alen = SIgenaddr( abuf, protocol, family, tptr->type, &addr );  //  family == 0 for type that suits the address passed in
@@ -96,6 +90,7 @@ extern struct tp_blk *SIlisten_prep( int type, char* abuf, int family ) {
                        if( addr != NULL ) {
                                free( addr );           // not needed, but scanners complain if we don't overtly do this
                        }
+                       free( tptr );
                        return NULL;
                }
 
@@ -195,6 +190,7 @@ extern struct tp_blk *SIconn_prep( struct ginfo_blk *gptr, int type, char *abuf,
                        if( addr != NULL ) {            // not needed, but scanners complain if we don't overtly do this
                                free( addr );
                        }
+                       free( tptr );
                        return NULL;
                }
 
@@ -218,6 +214,17 @@ extern struct tp_blk *SIconn_prep( struct ginfo_blk *gptr, int type, char *abuf,
                        }
                        SETSOCKOPT( tptr->fd, SOL_TCP, TCP_QUICKACK, (void *)&optval, sizeof( optval) ) ;
 
+                       if( gptr->tcp_flags & SI_TF_QUICK ) {
+                               optval = 1;
+                               SETSOCKOPT( tptr->fd, SOL_SOCKET, SO_KEEPALIVE, (void *)&optval, sizeof( optval) ) ;
+                               optval = 1;
+                               SETSOCKOPT( tptr->fd, IPPROTO_TCP, TCP_KEEPIDLE, (void *)&optval, sizeof( optval) ) ;
+                               optval = 1;
+                               SETSOCKOPT( tptr->fd, IPPROTO_TCP, TCP_KEEPINTVL, (void *)&optval, sizeof( optval) ) ;
+                               optval = 5;
+                               SETSOCKOPT( tptr->fd, IPPROTO_TCP, TCP_KEEPCNT, (void *)&optval, sizeof( optval) ) ;
+                       }
+
                        tptr->paddr = addr;                             // tuck the remote peer address away
                        if( need_smartc( abuf ) ) {
                                tptr->flags |= TPF_SAFEC;