0b74ba0018a3a5dc70ed03866500fc5cf7b87830
[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: This routine will terminate a session based on the tp_blk
25 *            that is passed into the routine. The transport session block
26 *            is released and removed from the ginfo list. The session is
27 *            terminated by issuing a t_unbind call (if the unbind flag is
28 *            on in the tpptr block), and then issuing a t_close.
29 *  Parms:    gptr - Pointer to the global information block
30 *            tpptr - Pointer to tp block that defines the open fd.
31 *  Returns:  Nothing.
32 *  Date:     18 January 1995
33 *  Author:   E. Scott Daniels
34 *
35 **************************************************************************
36 */
37 #include "sisetup.h"     //  get the setup stuff 
38 #include "sitransport.h"
39
40 extern void SIterm( struct ginfo_blk* gptr, struct tp_blk *tpptr ) {
41
42         if( tpptr != NULL ) {
43                 if( tpptr->fd >= 0 ) {
44                         CLOSE( tpptr->fd );    
45                         if( tpptr->fd < MAX_FDS ) {
46                                 gptr->tp_map[tpptr->fd] = NULL;         // drop reference
47                         }
48                 }
49
50                 if( tpptr->prev != NULL ) {            //  remove from the list 
51                         tpptr->prev->next = tpptr->next;    //  point previous at the next 
52                 } else {
53                         gptr->tplist = tpptr->next;        //  this was head, make next new head 
54                 }
55
56                 if( tpptr->next != NULL ) {
57                         tpptr->next->prev = tpptr->prev;  //  point next one back behind this one 
58                 }
59
60                 free( tpptr->addr );             //  release the address bufers 
61                 free( tpptr->paddr );
62                 free( tpptr );                   //  and release the block 
63         }
64 }