Address multi-threading issues in SI95
[ric-plt/lib/rmr.git] / src / rmr / si / src / si95 / sisend.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 *
24 *  Mnemonic: SIsend
25 *  Abstract: This routine is called to send a buffer of data to a partner
26 *            if the buffer has been queued waiting for the session to
27 *            unblock. The top qio block is removed from the tp block's
28 *            queue and is sent. It is assumed that for UDP data the
29 *            unit data structure was created and contains the buffer and
30 *            address and is pointed to by the qio block. The block and
31 *            associated buffers are then freed.
32 *  Parms:
33 *            tpptr- Pointer to the tp block
34 *
35 *  Returns:     Nothing.
36 *  Date:        27 March 1995
37 *  Author:      E. Scott Daniels
38 *  Mod:         22 Feb 2002 - To support sendqueue tail 
39 *
40 ******************************************************************************
41 */
42 #include "sisetup.h"      //  get include files etc 
43 #include "sitransport.h"
44
45 extern void SIsend( struct ginfo_blk *gptr, struct tp_blk *tpptr ) {
46         struct t_unitdata *udata;      //  pointer at UDP unit data 
47         struct ioq_blk *qptr;          //  pointer at qio block for free 
48         int status;
49
50         if( tpptr->squeue == NULL )    //  who knows why we were called 
51                 return;                        //  nothing queued - just leave 
52
53 /*
54         if( tpptr->type == SOCK_DGRAM ) {                                //  udp send?  
55                 sendto( tpptr->fd, tpptr->squeue->data, tpptr->squeue->dlen, 0, tpptr->squeue->addr, sizeof( struct sockaddr ) );
56                 if( tpptr->squeue->addr != NULL )
57                         free( tpptr->squeue->data );
58                 tpptr->squeue->addr = NULL;
59         } else {
60 */
61                 status= SEND( tpptr->fd, tpptr->squeue->data, tpptr->squeue->dlen, 0 );
62 /*
63         }
64 */
65
66         free( tpptr->squeue->data );           //  trash buffer or the udp block 
67         qptr = tpptr->squeue;                  //  hold pointer for free 
68         tpptr->squeue = tpptr->squeue->next;   //  next in queue becommes head 
69         if( !tpptr->squeue )
70                 tpptr->sqtail = NULL;           //  no tail left either 
71
72         free( qptr );
73
74         if( (tpptr->flags & TPF_DRAIN) && tpptr->squeue == NULL )  //  done w/ drain? 
75         {
76                 SIterm( gptr, tpptr );     //  close the session and mark the block for delte
77         }
78 }                      //  SIsend