8b732f6daa2db1eeebb1ae1396cf94a7aa221878
[ric-plt/lib/rmr.git] / src / rmr / si / src / si95 / siterm.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:    SIterm
24 *  Abstract:    Manage the transport provider block information relating to
25 *                               the need to terminate the session. The block is left in the
26 *                               list; it is unsafe to clean the lsit up outside of the SIwait 
27 *                               thread.  When safe, the SIrm_tpb() function can be called to
28 *                               do the rest of the work that was originally done by SIterm.
29 *
30 *  Date:        18 January 1995
31 *  Author:              E. Scott Daniels
32 *
33 **************************************************************************
34 */
35 #include "sisetup.h"     //  get the setup stuff 
36 #include "sitransport.h"
37
38 /*
39         Close the FD and mark the transport block as unusable/closed.
40         Removal of the block from the list is safe only from the siwait
41         thread.
42 */
43 extern void SIterm( struct ginfo_blk* gptr, struct tp_blk *tpptr ) {
44
45         if( tpptr != NULL ) {
46                 if( tpptr->fd >= 0 ) {
47                         CLOSE( tpptr->fd );    
48                         if( tpptr->fd < MAX_FDS ) {
49                                 gptr->tp_map[tpptr->fd] = NULL;         // drop reference
50                         }
51                 }
52
53                 tpptr->fd = -1;                                                         // prevent future sends etc.
54                 tpptr->flags |= TPF_DELETE;                                     // signal block deletion needed when safe
55         }
56 }
57
58 /*
59         It is safe to remove the block from the list; if it was in the list
60         in the first place. 
61 */
62 extern void SIrm_tpb( struct ginfo_blk *gptr, struct tp_blk *tpptr ) {
63
64         if( tpptr != NULL ) {
65                 if( tpptr->prev != NULL || tpptr->next != NULL ) {      // in the list
66                         if( tpptr->prev != NULL ) {            //  remove from the list 
67                                 tpptr->prev->next = tpptr->next;    //  point previous at the next 
68                         } else {
69                                 gptr->tplist = tpptr->next;        //  this was head, make next new head 
70                         }
71         
72                         if( tpptr->next != NULL ) {
73                                 tpptr->next->prev = tpptr->prev;  //  point next one back behind this one 
74                         }
75                 }
76
77                 free( tpptr->addr );             //  release the address bufers 
78                 free( tpptr->paddr );
79                 free( tpptr );                   //  and release the block 
80         }
81 }