Mercurial > hg > freeDiameter
annotate libfdproto/sessions.c @ 1562:6219359a36a9 default tip
Merge latest changes from proposed branch
author | Sebastien Decugis <sdecugis@freediameter.net> |
---|---|
date | Mon, 21 Jun 2021 19:08:18 +0800 |
parents | 566bb46cc73f |
children |
rev | line source |
---|---|
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
1 /********************************************************************************************************* |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
2 * Software License Agreement (BSD License) * |
740
4a9f08d6b6ba
Updated my mail address
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
706
diff
changeset
|
3 * Author: Sebastien Decugis <sdecugis@freediameter.net> * |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
4 * * |
1554
566bb46cc73f
Updated copyright information
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1376
diff
changeset
|
5 * Copyright (c) 2019, WIDE Project and NICT * |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
6 * All rights reserved. * |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
7 * * |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
8 * Redistribution and use of this software in source and binary forms, with or without modification, are * |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
9 * permitted provided that the following conditions are met: * |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
10 * * |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
11 * * Redistributions of source code must retain the above * |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
12 * copyright notice, this list of conditions and the * |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
13 * following disclaimer. * |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
14 * * |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
15 * * Redistributions in binary form must reproduce the above * |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
16 * copyright notice, this list of conditions and the * |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
17 * following disclaimer in the documentation and/or other * |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
18 * materials provided with the distribution. * |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
19 * * |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
20 * * Neither the name of the WIDE Project or NICT nor the * |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
21 * names of its contributors may be used to endorse or * |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
22 * promote products derived from this software without * |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
23 * specific prior written permission of WIDE Project and * |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
24 * NICT. * |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
25 * * |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
26 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED * |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
27 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
28 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR * |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
29 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
30 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
31 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR * |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
32 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
33 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
34 *********************************************************************************************************/ |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
35 |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
36 /* Sessions module. |
1369
f1bbcab403a6
Clean up trailing whitespace in sessions.c
Thomas Klausner <tk@giga.or.at>
parents:
1093
diff
changeset
|
37 * |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
38 * Basic functionalities to help implementing User sessions state machines from RFC3588. |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
39 */ |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
40 |
658
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
639
diff
changeset
|
41 #include "fdproto-internal.h" |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
42 |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
43 /*********************** Parameters **********************/ |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
44 |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
45 /* Size of the hash table containing the session objects (pow of 2. ex: 6 => 2^6 = 64). must be between 0 and 31. */ |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
46 #ifndef SESS_HASH_SIZE |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
47 #define SESS_HASH_SIZE 6 |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
48 #endif /* SESS_HASH_SIZE */ |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
49 |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
50 /* Default lifetime of a session, in seconds. (31 days = 2678400 seconds) */ |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
51 #ifndef SESS_DEFAULT_LIFETIME |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
52 #define SESS_DEFAULT_LIFETIME 2678400 |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
53 #endif /* SESS_DEFAULT_LIFETIME */ |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
54 |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
55 /********************** /Parameters **********************/ |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
56 |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
57 /* Eyescatchers definitions */ |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
58 #define SH_EYEC 0x53554AD1 |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
59 #define SD_EYEC 0x5355D474 |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
60 #define SI_EYEC 0x53551D |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
61 |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
62 /* Macro to check an object is valid */ |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
63 #define VALIDATE_SH( _obj ) ( ((_obj) != NULL) && ( ((struct session_handler *)(_obj))->eyec == SH_EYEC) ) |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
64 #define VALIDATE_SI( _obj ) ( ((_obj) != NULL) && ( ((struct session *)(_obj))->eyec == SI_EYEC) ) |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
65 |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
66 |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
67 /* Handlers registered by users of the session module */ |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
68 struct session_handler { |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
69 int eyec; /* An eye catcher also used to ensure the object is valid, must be SH_EYEC */ |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
70 int id; /* A unique integer to identify this handler */ |
1088
1d1a20a0779d
Second part of changeset 1083, now the code compiles again. Still missing some functions implementation, though
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1085
diff
changeset
|
71 void (*cleanup)(struct sess_state *, os0_t, void *); /* The cleanup function to be called for cleaning a state */ |
1d1a20a0779d
Second part of changeset 1083, now the code compiles again. Still missing some functions implementation, though
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1085
diff
changeset
|
72 session_state_dump state_dump; /* dumper function */ |
639
95a784729cac
Added new opaque pointer to fd_sess_handler_create and fd_disp_register for usability. Bumped API version number.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
557
diff
changeset
|
73 void *opaque; /* a value that is passed as is to the cleanup callback */ |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
74 }; |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
75 |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
76 static int hdl_id = 0; /* A global counter to initialize the id field */ |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
77 static pthread_mutex_t hdl_lock = PTHREAD_MUTEX_INITIALIZER; /* lock to protect hdl_id; we could use atomic operations otherwise (less portable) */ |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
78 |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
79 |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
80 /* Data structures linked from the sessions, containing the applications states */ |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
81 struct state { |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
82 int eyec; /* Must be SD_EYEC */ |
1088
1d1a20a0779d
Second part of changeset 1083, now the code compiles again. Still missing some functions implementation, though
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1085
diff
changeset
|
83 struct sess_state *state; /* The state registered by the application, never NULL (or the whole object is deleted) */ |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
84 struct fd_list chain; /* Chaining in the list of session's states ordered by hdl->id */ |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
85 union { |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
86 struct session_handler *hdl; /* The handler for which this state was registered */ |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
87 os0_t sid; /* For deleted state, the sid of the session it belong to */ |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
88 }; |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
89 }; |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
90 |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
91 /* Session object, one for each value of Session-Id AVP */ |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
92 struct session { |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
93 int eyec; /* Eyecatcher, SI_EYEC */ |
1369
f1bbcab403a6
Clean up trailing whitespace in sessions.c
Thomas Klausner <tk@giga.or.at>
parents:
1093
diff
changeset
|
94 |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
95 os0_t sid; /* The \0-terminated Session-Id */ |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
96 size_t sidlen; /* cached length of sid */ |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
97 uint32_t hash; /* computed hash of sid */ |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
98 struct fd_list chain_h;/* chaining in the hash table of sessions. */ |
1369
f1bbcab403a6
Clean up trailing whitespace in sessions.c
Thomas Klausner <tk@giga.or.at>
parents:
1093
diff
changeset
|
99 |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
100 struct timespec timeout;/* Timeout date for the session */ |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
101 struct fd_list expire; /* List of expiring sessions, ordered by timeouts. */ |
1369
f1bbcab403a6
Clean up trailing whitespace in sessions.c
Thomas Klausner <tk@giga.or.at>
parents:
1093
diff
changeset
|
102 |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
103 pthread_mutex_t stlock; /* A lock to protect the list of states associated with this session */ |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
104 struct fd_list states; /* Sentinel for the list of states of this session. */ |
557
85ab58cc427c
Committed this by error
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
556
diff
changeset
|
105 int msg_cnt;/* Reference counter for the messages pointing to this session */ |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
106 int is_destroyed; /* boolean telling if fd_sess_detroy has been called on this */ |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
107 }; |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
108 |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
109 /* Sessions hash table, to allow fast sid to session retrieval */ |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
110 static struct { |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
111 struct fd_list sentinel; /* sentinel element for this sublist. The sublist is ordered by hash value, then fd_os_cmp(sid). */ |
557
85ab58cc427c
Committed this by error
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
556
diff
changeset
|
112 pthread_mutex_t lock; /* the mutex for this sublist -- we might probably change it to rwlock for a little optimization */ |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
113 } sess_hash [ 1 << SESS_HASH_SIZE ] ; |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
114 #define H_MASK( __hash ) ((__hash) & (( 1 << SESS_HASH_SIZE ) - 1)) |
557
85ab58cc427c
Committed this by error
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
556
diff
changeset
|
115 #define H_LIST( _hash ) (&(sess_hash[H_MASK(_hash)].sentinel)) |
85ab58cc427c
Committed this by error
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
556
diff
changeset
|
116 #define H_LOCK( _hash ) (&(sess_hash[H_MASK(_hash)].lock )) |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
117 |
778
003df4a9ade2
Added two new interfaces on Zach requests http://lists.freediameter.net/pipermail/help/2012-January/000312.html and http://lists.freediameter.net/pipermail/help/2012-January/000311.html
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
118 static uint32_t sess_cnt = 0; /* counts all active session (that are in the expiry list) */ |
003df4a9ade2
Added two new interfaces on Zach requests http://lists.freediameter.net/pipermail/help/2012-January/000312.html and http://lists.freediameter.net/pipermail/help/2012-January/000311.html
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
119 |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
120 /* The following are used to generate sid values that are eternaly unique */ |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
121 static uint32_t sid_h; /* initialized to the current time in fd_sess_init */ |
7
e5af94b04946
Added dispatch module and tests
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
6
diff
changeset
|
122 static uint32_t sid_l; /* incremented each time a session id is created */ |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
123 static pthread_mutex_t sid_lock = PTHREAD_MUTEX_INITIALIZER; |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
124 |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
125 /* Expiring sessions management */ |
14
14cf6daf716d
Some progress on peers module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
7
diff
changeset
|
126 static struct fd_list exp_sentinel = FD_LIST_INITIALIZER(exp_sentinel); /* list of sessions ordered by their timeout date */ |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
127 static pthread_mutex_t exp_lock = PTHREAD_MUTEX_INITIALIZER; /* lock protecting the list. */ |
1369
f1bbcab403a6
Clean up trailing whitespace in sessions.c
Thomas Klausner <tk@giga.or.at>
parents:
1093
diff
changeset
|
128 static pthread_cond_t exp_cond = PTHREAD_COND_INITIALIZER; /* condvar used by the expiry mechainsm. */ |
686
f83d9878bf66
Fixed in case of termination of several modules (before initialization completed)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
129 static pthread_t exp_thr = (pthread_t)NULL; /* The expiry thread that handles cleanup of expired sessions */ |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
130 |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
131 /* Hierarchy of the locks, to avoid deadlocks: |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
132 * hash lock > state lock > expiry lock |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
133 * i.e. state lock can be taken while holding the hash lock, but not while holding the expiry lock. |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
134 * As well, the hash lock cannot be taken while holding a state lock. |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
135 */ |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
136 |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
137 /********************************************************************************************************/ |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
138 |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
139 /* Initialize a session object. It is not linked now. sid must be already malloc'ed. The hash has already been computed. */ |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
140 static struct session * new_session(os0_t sid, size_t sidlen, uint32_t hash) |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
141 { |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
142 struct session * sess; |
1369
f1bbcab403a6
Clean up trailing whitespace in sessions.c
Thomas Klausner <tk@giga.or.at>
parents:
1093
diff
changeset
|
143 |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
144 TRACE_ENTRY("%p %zd", sid, sidlen); |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
145 CHECK_PARAMS_DO( sid && sidlen, return NULL ); |
1369
f1bbcab403a6
Clean up trailing whitespace in sessions.c
Thomas Klausner <tk@giga.or.at>
parents:
1093
diff
changeset
|
146 |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
147 CHECK_MALLOC_DO( sess = malloc(sizeof(struct session)), return NULL ); |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
148 memset(sess, 0, sizeof(struct session)); |
1369
f1bbcab403a6
Clean up trailing whitespace in sessions.c
Thomas Klausner <tk@giga.or.at>
parents:
1093
diff
changeset
|
149 |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
150 sess->eyec = SI_EYEC; |
1369
f1bbcab403a6
Clean up trailing whitespace in sessions.c
Thomas Klausner <tk@giga.or.at>
parents:
1093
diff
changeset
|
151 |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
152 sess->sid = sid; |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
153 sess->sidlen = sidlen; |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
154 sess->hash = hash; |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
155 fd_list_init(&sess->chain_h, sess); |
1369
f1bbcab403a6
Clean up trailing whitespace in sessions.c
Thomas Klausner <tk@giga.or.at>
parents:
1093
diff
changeset
|
156 |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
157 CHECK_SYS_DO( clock_gettime(CLOCK_REALTIME, &sess->timeout), return NULL ); |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
158 sess->timeout.tv_sec += SESS_DEFAULT_LIFETIME; |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
159 fd_list_init(&sess->expire, sess); |
1369
f1bbcab403a6
Clean up trailing whitespace in sessions.c
Thomas Klausner <tk@giga.or.at>
parents:
1093
diff
changeset
|
160 |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
161 CHECK_POSIX_DO( pthread_mutex_init(&sess->stlock, NULL), return NULL ); |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
162 fd_list_init(&sess->states, sess); |
1369
f1bbcab403a6
Clean up trailing whitespace in sessions.c
Thomas Klausner <tk@giga.or.at>
parents:
1093
diff
changeset
|
163 |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
164 return sess; |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
165 } |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
166 |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
167 /* destroy the session object. It should really be already unlinked... */ |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
168 static void del_session(struct session * s) |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
169 { |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
170 ASSERT(FD_IS_LIST_EMPTY(&s->states)); |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
171 free(s->sid); |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
172 fd_list_unlink(&s->chain_h); |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
173 fd_list_unlink(&s->expire); |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
174 CHECK_POSIX_DO( pthread_mutex_destroy(&s->stlock), /* continue */ ); |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
175 free(s); |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
176 } |
1369
f1bbcab403a6
Clean up trailing whitespace in sessions.c
Thomas Klausner <tk@giga.or.at>
parents:
1093
diff
changeset
|
177 |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
178 /* The expiry thread */ |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
179 static void * exp_fct(void * arg) |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
180 { |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
181 fd_log_threadname ( "Session/expire" ); |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
182 TRACE_ENTRY( "" ); |
1369
f1bbcab403a6
Clean up trailing whitespace in sessions.c
Thomas Klausner <tk@giga.or.at>
parents:
1093
diff
changeset
|
183 |
f1bbcab403a6
Clean up trailing whitespace in sessions.c
Thomas Klausner <tk@giga.or.at>
parents:
1093
diff
changeset
|
184 |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
185 do { |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
186 struct timespec now; |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
187 struct session * first; |
1369
f1bbcab403a6
Clean up trailing whitespace in sessions.c
Thomas Klausner <tk@giga.or.at>
parents:
1093
diff
changeset
|
188 |
203
536b1dde8761
Some cleanups in the cnxctx module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
136
diff
changeset
|
189 CHECK_POSIX_DO( pthread_mutex_lock(&exp_lock), break ); |
536b1dde8761
Some cleanups in the cnxctx module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
136
diff
changeset
|
190 pthread_cleanup_push( fd_cleanup_mutex, &exp_lock ); |
1369
f1bbcab403a6
Clean up trailing whitespace in sessions.c
Thomas Klausner <tk@giga.or.at>
parents:
1093
diff
changeset
|
191 again: |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
192 /* Check if there are expiring sessions available */ |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
193 if (FD_IS_LIST_EMPTY(&exp_sentinel)) { |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
194 /* Just wait for a change or cancelation */ |
691
78b665400097
Cleanup all pthread_cleanup_push / pop pairs so that pop is always called after push, or ASSERT(0) is some grave errors
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
686
diff
changeset
|
195 CHECK_POSIX_DO( pthread_cond_wait( &exp_cond, &exp_lock ), break /* this might not pop the cleanup handler, but since we ASSERT(0), it is not the big issue... */ ); |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
196 /* Restart the loop on wakeup */ |
203
536b1dde8761
Some cleanups in the cnxctx module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
136
diff
changeset
|
197 goto again; |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
198 } |
1369
f1bbcab403a6
Clean up trailing whitespace in sessions.c
Thomas Klausner <tk@giga.or.at>
parents:
1093
diff
changeset
|
199 |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
200 /* Get the pointer to the session that expires first */ |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
201 first = (struct session *)(exp_sentinel.next->o); |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
202 ASSERT( VALIDATE_SI(first) ); |
1369
f1bbcab403a6
Clean up trailing whitespace in sessions.c
Thomas Klausner <tk@giga.or.at>
parents:
1093
diff
changeset
|
203 |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
204 /* Get the current time */ |
203
536b1dde8761
Some cleanups in the cnxctx module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
136
diff
changeset
|
205 CHECK_SYS_DO( clock_gettime(CLOCK_REALTIME, &now), break ); |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
206 |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
207 /* If first session is not expired, we just wait until it happens */ |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
208 if ( TS_IS_INFERIOR( &now, &first->timeout ) ) { |
1376
b8afaf63f65a
Handle case where pthread_cond_timedwait returns EINVAL if abstime
Thomas Klausner <tk@giga.or.at>
parents:
1373
diff
changeset
|
209 int ret; |
1369
f1bbcab403a6
Clean up trailing whitespace in sessions.c
Thomas Klausner <tk@giga.or.at>
parents:
1093
diff
changeset
|
210 |
1376
b8afaf63f65a
Handle case where pthread_cond_timedwait returns EINVAL if abstime
Thomas Klausner <tk@giga.or.at>
parents:
1373
diff
changeset
|
211 ret = pthread_cond_timedwait(&exp_cond, &exp_lock, &first->timeout); |
b8afaf63f65a
Handle case where pthread_cond_timedwait returns EINVAL if abstime
Thomas Klausner <tk@giga.or.at>
parents:
1373
diff
changeset
|
212 switch (ret) { |
b8afaf63f65a
Handle case where pthread_cond_timedwait returns EINVAL if abstime
Thomas Klausner <tk@giga.or.at>
parents:
1373
diff
changeset
|
213 case 0: |
b8afaf63f65a
Handle case where pthread_cond_timedwait returns EINVAL if abstime
Thomas Klausner <tk@giga.or.at>
parents:
1373
diff
changeset
|
214 case ETIMEDOUT: |
b8afaf63f65a
Handle case where pthread_cond_timedwait returns EINVAL if abstime
Thomas Klausner <tk@giga.or.at>
parents:
1373
diff
changeset
|
215 /* on wakeup or time-out, loop */ |
b8afaf63f65a
Handle case where pthread_cond_timedwait returns EINVAL if abstime
Thomas Klausner <tk@giga.or.at>
parents:
1373
diff
changeset
|
216 goto again; |
b8afaf63f65a
Handle case where pthread_cond_timedwait returns EINVAL if abstime
Thomas Klausner <tk@giga.or.at>
parents:
1373
diff
changeset
|
217 case EINVAL: |
b8afaf63f65a
Handle case where pthread_cond_timedwait returns EINVAL if abstime
Thomas Klausner <tk@giga.or.at>
parents:
1373
diff
changeset
|
218 if (clock_gettime(CLOCK_REALTIME, &now) < 0) { |
b8afaf63f65a
Handle case where pthread_cond_timedwait returns EINVAL if abstime
Thomas Klausner <tk@giga.or.at>
parents:
1373
diff
changeset
|
219 break; |
b8afaf63f65a
Handle case where pthread_cond_timedwait returns EINVAL if abstime
Thomas Klausner <tk@giga.or.at>
parents:
1373
diff
changeset
|
220 } |
b8afaf63f65a
Handle case where pthread_cond_timedwait returns EINVAL if abstime
Thomas Klausner <tk@giga.or.at>
parents:
1373
diff
changeset
|
221 if (TS_IS_INFERIOR(&now, &first->timeout)) { |
b8afaf63f65a
Handle case where pthread_cond_timedwait returns EINVAL if abstime
Thomas Klausner <tk@giga.or.at>
parents:
1373
diff
changeset
|
222 TRACE_DEBUG(FULL, "'pthread_cond_timedwait(&exp_cond, &exp_lock, &first->timeout)' : timer expired before loop could start"); |
b8afaf63f65a
Handle case where pthread_cond_timedwait returns EINVAL if abstime
Thomas Klausner <tk@giga.or.at>
parents:
1373
diff
changeset
|
223 goto again; |
b8afaf63f65a
Handle case where pthread_cond_timedwait returns EINVAL if abstime
Thomas Klausner <tk@giga.or.at>
parents:
1373
diff
changeset
|
224 } |
b8afaf63f65a
Handle case where pthread_cond_timedwait returns EINVAL if abstime
Thomas Klausner <tk@giga.or.at>
parents:
1373
diff
changeset
|
225 /* FALLTHROUGH */ |
b8afaf63f65a
Handle case where pthread_cond_timedwait returns EINVAL if abstime
Thomas Klausner <tk@giga.or.at>
parents:
1373
diff
changeset
|
226 default: |
b8afaf63f65a
Handle case where pthread_cond_timedwait returns EINVAL if abstime
Thomas Klausner <tk@giga.or.at>
parents:
1373
diff
changeset
|
227 TRACE_ERROR("ERROR: in 'pthread_cond_timedwait(&exp_cond, &exp_lock, &first->timeout)' :\t%s", strerror(ret)); |
b8afaf63f65a
Handle case where pthread_cond_timedwait returns EINVAL if abstime
Thomas Klausner <tk@giga.or.at>
parents:
1373
diff
changeset
|
228 break; |
b8afaf63f65a
Handle case where pthread_cond_timedwait returns EINVAL if abstime
Thomas Klausner <tk@giga.or.at>
parents:
1373
diff
changeset
|
229 } |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
230 } |
1369
f1bbcab403a6
Clean up trailing whitespace in sessions.c
Thomas Klausner <tk@giga.or.at>
parents:
1093
diff
changeset
|
231 |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
232 /* Now, the first session in the list is expired; destroy it */ |
203
536b1dde8761
Some cleanups in the cnxctx module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
136
diff
changeset
|
233 pthread_cleanup_pop( 0 ); |
536b1dde8761
Some cleanups in the cnxctx module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
136
diff
changeset
|
234 CHECK_POSIX_DO( pthread_mutex_unlock(&exp_lock), break ); |
1369
f1bbcab403a6
Clean up trailing whitespace in sessions.c
Thomas Klausner <tk@giga.or.at>
parents:
1093
diff
changeset
|
235 |
203
536b1dde8761
Some cleanups in the cnxctx module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
136
diff
changeset
|
236 CHECK_FCT_DO( fd_sess_destroy( &first ), break ); |
1369
f1bbcab403a6
Clean up trailing whitespace in sessions.c
Thomas Klausner <tk@giga.or.at>
parents:
1093
diff
changeset
|
237 |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
238 } while (1); |
1369
f1bbcab403a6
Clean up trailing whitespace in sessions.c
Thomas Klausner <tk@giga.or.at>
parents:
1093
diff
changeset
|
239 |
691
78b665400097
Cleanup all pthread_cleanup_push / pop pairs so that pop is always called after push, or ASSERT(0) is some grave errors
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
686
diff
changeset
|
240 TRACE_DEBUG(INFO, "A system error occurred in session module! Expiry thread is terminating..."); |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
241 ASSERT(0); |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
242 return NULL; |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
243 } |
1369
f1bbcab403a6
Clean up trailing whitespace in sessions.c
Thomas Klausner <tk@giga.or.at>
parents:
1093
diff
changeset
|
244 |
f1bbcab403a6
Clean up trailing whitespace in sessions.c
Thomas Klausner <tk@giga.or.at>
parents:
1093
diff
changeset
|
245 |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
246 |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
247 /********************************************************************************************************/ |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
248 |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
249 /* Initialize the session module */ |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
250 int fd_sess_init(void) |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
251 { |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
252 int i; |
1369
f1bbcab403a6
Clean up trailing whitespace in sessions.c
Thomas Klausner <tk@giga.or.at>
parents:
1093
diff
changeset
|
253 |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
254 TRACE_ENTRY( "" ); |
1369
f1bbcab403a6
Clean up trailing whitespace in sessions.c
Thomas Klausner <tk@giga.or.at>
parents:
1093
diff
changeset
|
255 |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
256 /* Initialize the global counters */ |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
257 sid_h = (uint32_t) time(NULL); |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
258 sid_l = 0; |
1369
f1bbcab403a6
Clean up trailing whitespace in sessions.c
Thomas Klausner <tk@giga.or.at>
parents:
1093
diff
changeset
|
259 |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
260 /* Initialize the hash table */ |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
261 for (i = 0; i < sizeof(sess_hash) / sizeof(sess_hash[0]); i++) { |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
262 fd_list_init( &sess_hash[i].sentinel, NULL ); |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
263 CHECK_POSIX( pthread_mutex_init(&sess_hash[i].lock, NULL) ); |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
264 } |
1369
f1bbcab403a6
Clean up trailing whitespace in sessions.c
Thomas Klausner <tk@giga.or.at>
parents:
1093
diff
changeset
|
265 |
453
9a8b3178a7a7
Postpone the creation of session expiry thread to allow some global variables to be set (debug level, etc)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
452
diff
changeset
|
266 return 0; |
9a8b3178a7a7
Postpone the creation of session expiry thread to allow some global variables to be set (debug level, etc)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
452
diff
changeset
|
267 } |
9a8b3178a7a7
Postpone the creation of session expiry thread to allow some global variables to be set (debug level, etc)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
452
diff
changeset
|
268 |
9a8b3178a7a7
Postpone the creation of session expiry thread to allow some global variables to be set (debug level, etc)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
452
diff
changeset
|
269 /* Run this when initializations are complete. */ |
9a8b3178a7a7
Postpone the creation of session expiry thread to allow some global variables to be set (debug level, etc)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
452
diff
changeset
|
270 int fd_sess_start(void) |
9a8b3178a7a7
Postpone the creation of session expiry thread to allow some global variables to be set (debug level, etc)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
452
diff
changeset
|
271 { |
14
14cf6daf716d
Some progress on peers module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
7
diff
changeset
|
272 /* Start session garbage collector (expiry) */ |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
273 CHECK_POSIX( pthread_create(&exp_thr, NULL, exp_fct, NULL) ); |
1369
f1bbcab403a6
Clean up trailing whitespace in sessions.c
Thomas Klausner <tk@giga.or.at>
parents:
1093
diff
changeset
|
274 |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
275 return 0; |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
276 } |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
277 |
235
8773740401a5
Centralized signal handlers management in the library
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
203
diff
changeset
|
278 /* Terminate */ |
8773740401a5
Centralized signal handlers management in the library
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
203
diff
changeset
|
279 void fd_sess_fini(void) |
8773740401a5
Centralized signal handlers management in the library
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
203
diff
changeset
|
280 { |
8773740401a5
Centralized signal handlers management in the library
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
203
diff
changeset
|
281 TRACE_ENTRY(""); |
8773740401a5
Centralized signal handlers management in the library
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
203
diff
changeset
|
282 CHECK_FCT_DO( fd_thr_term(&exp_thr), /* continue */ ); |
1369
f1bbcab403a6
Clean up trailing whitespace in sessions.c
Thomas Klausner <tk@giga.or.at>
parents:
1093
diff
changeset
|
283 |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
284 /* Destroy all sessions in the hash table, and the hash table itself? -- How to do it without a race condition ? */ |
1369
f1bbcab403a6
Clean up trailing whitespace in sessions.c
Thomas Klausner <tk@giga.or.at>
parents:
1093
diff
changeset
|
285 |
235
8773740401a5
Centralized signal handlers management in the library
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
203
diff
changeset
|
286 return; |
8773740401a5
Centralized signal handlers management in the library
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
203
diff
changeset
|
287 } |
8773740401a5
Centralized signal handlers management in the library
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
203
diff
changeset
|
288 |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
289 /* Create a new handler */ |
1088
1d1a20a0779d
Second part of changeset 1083, now the code compiles again. Still missing some functions implementation, though
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1085
diff
changeset
|
290 int fd_sess_handler_create ( struct session_handler ** handler, void (*cleanup)(struct sess_state *, os0_t, void *), session_state_dump dumper, void * opaque ) |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
291 { |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
292 struct session_handler *new; |
1369
f1bbcab403a6
Clean up trailing whitespace in sessions.c
Thomas Klausner <tk@giga.or.at>
parents:
1093
diff
changeset
|
293 |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
294 TRACE_ENTRY("%p %p", handler, cleanup); |
1369
f1bbcab403a6
Clean up trailing whitespace in sessions.c
Thomas Klausner <tk@giga.or.at>
parents:
1093
diff
changeset
|
295 |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
296 CHECK_PARAMS( handler && cleanup ); |
1369
f1bbcab403a6
Clean up trailing whitespace in sessions.c
Thomas Klausner <tk@giga.or.at>
parents:
1093
diff
changeset
|
297 |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
298 CHECK_MALLOC( new = malloc(sizeof(struct session_handler)) ); |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
299 memset(new, 0, sizeof(struct session_handler)); |
1369
f1bbcab403a6
Clean up trailing whitespace in sessions.c
Thomas Klausner <tk@giga.or.at>
parents:
1093
diff
changeset
|
300 |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
301 CHECK_POSIX( pthread_mutex_lock(&hdl_lock) ); |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
302 new->id = ++hdl_id; |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
303 CHECK_POSIX( pthread_mutex_unlock(&hdl_lock) ); |
1369
f1bbcab403a6
Clean up trailing whitespace in sessions.c
Thomas Klausner <tk@giga.or.at>
parents:
1093
diff
changeset
|
304 |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
305 new->eyec = SH_EYEC; |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
306 new->cleanup = cleanup; |
1085
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1027
diff
changeset
|
307 new->state_dump = dumper; |
639
95a784729cac
Added new opaque pointer to fd_sess_handler_create and fd_disp_register for usability. Bumped API version number.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
557
diff
changeset
|
308 new->opaque = opaque; |
1369
f1bbcab403a6
Clean up trailing whitespace in sessions.c
Thomas Klausner <tk@giga.or.at>
parents:
1093
diff
changeset
|
309 |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
310 *handler = new; |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
311 return 0; |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
312 } |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
313 |
1369
f1bbcab403a6
Clean up trailing whitespace in sessions.c
Thomas Klausner <tk@giga.or.at>
parents:
1093
diff
changeset
|
314 /* Destroy a handler, and all states attached to this handler. This operation is very slow but we don't care since it's rarely used. |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
315 * Note that it's better to call this function after all sessions have been deleted... */ |
639
95a784729cac
Added new opaque pointer to fd_sess_handler_create and fd_disp_register for usability. Bumped API version number.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
557
diff
changeset
|
316 int fd_sess_handler_destroy ( struct session_handler ** handler, void ** opaque ) |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
317 { |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
318 struct session_handler * del; |
14
14cf6daf716d
Some progress on peers module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
7
diff
changeset
|
319 /* place to save the list of states to be cleaned up. We do it after finding them to avoid deadlocks. the "o" field becomes a copy of the sid. */ |
14cf6daf716d
Some progress on peers module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
7
diff
changeset
|
320 struct fd_list deleted_states = FD_LIST_INITIALIZER( deleted_states ); |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
321 int i; |
1369
f1bbcab403a6
Clean up trailing whitespace in sessions.c
Thomas Klausner <tk@giga.or.at>
parents:
1093
diff
changeset
|
322 |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
323 TRACE_ENTRY("%p", handler); |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
324 CHECK_PARAMS( handler && VALIDATE_SH(*handler) ); |
1369
f1bbcab403a6
Clean up trailing whitespace in sessions.c
Thomas Klausner <tk@giga.or.at>
parents:
1093
diff
changeset
|
325 |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
326 del = *handler; |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
327 *handler = NULL; |
1369
f1bbcab403a6
Clean up trailing whitespace in sessions.c
Thomas Klausner <tk@giga.or.at>
parents:
1093
diff
changeset
|
328 |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
329 del->eyec = 0xdead; /* The handler is not valid anymore for any other operation */ |
1369
f1bbcab403a6
Clean up trailing whitespace in sessions.c
Thomas Klausner <tk@giga.or.at>
parents:
1093
diff
changeset
|
330 |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
331 /* Now find all sessions with data registered for this handler, and move this data to the deleted_states list. */ |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
332 for (i = 0; i < sizeof(sess_hash) / sizeof(sess_hash[0]); i++) { |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
333 struct fd_list * li_si; |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
334 CHECK_POSIX( pthread_mutex_lock(&sess_hash[i].lock) ); |
1369
f1bbcab403a6
Clean up trailing whitespace in sessions.c
Thomas Klausner <tk@giga.or.at>
parents:
1093
diff
changeset
|
335 |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
336 for (li_si = sess_hash[i].sentinel.next; li_si != &sess_hash[i].sentinel; li_si = li_si->next) { /* for each session in the hash line */ |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
337 struct fd_list * li_st; |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
338 struct session * sess = (struct session *)(li_si->o); |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
339 CHECK_POSIX( pthread_mutex_lock(&sess->stlock) ); |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
340 for (li_st = sess->states.next; li_st != &sess->states; li_st = li_st->next) { /* for each state in this session */ |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
341 struct state * st = (struct state *)(li_st->o); |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
342 /* The list is ordered */ |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
343 if (st->hdl->id < del->id) |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
344 continue; |
5
c2d2729e3603
Completed new session module tests; some bugs fixed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
4
diff
changeset
|
345 if (st->hdl->id == del->id) { |
c2d2729e3603
Completed new session module tests; some bugs fixed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
4
diff
changeset
|
346 /* This state belongs to the handler we are deleting, move the item to the deleted_states list */ |
c2d2729e3603
Completed new session module tests; some bugs fixed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
4
diff
changeset
|
347 fd_list_unlink(&st->chain); |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
348 st->sid = sess->sid; |
5
c2d2729e3603
Completed new session module tests; some bugs fixed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
4
diff
changeset
|
349 fd_list_insert_before(&deleted_states, &st->chain); |
c2d2729e3603
Completed new session module tests; some bugs fixed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
4
diff
changeset
|
350 } |
c2d2729e3603
Completed new session module tests; some bugs fixed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
4
diff
changeset
|
351 break; |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
352 } |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
353 CHECK_POSIX( pthread_mutex_unlock(&sess->stlock) ); |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
354 } |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
355 CHECK_POSIX( pthread_mutex_unlock(&sess_hash[i].lock) ); |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
356 } |
1369
f1bbcab403a6
Clean up trailing whitespace in sessions.c
Thomas Klausner <tk@giga.or.at>
parents:
1093
diff
changeset
|
357 |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
358 /* Now, delete all states after calling their cleanup handler */ |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
359 while (!FD_IS_LIST_EMPTY(&deleted_states)) { |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
360 struct state * st = (struct state *)(deleted_states.next->o); |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
361 TRACE_DEBUG(FULL, "Calling cleanup handler for session '%s' and data %p", st->sid, st->state); |
639
95a784729cac
Added new opaque pointer to fd_sess_handler_create and fd_disp_register for usability. Bumped API version number.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
557
diff
changeset
|
362 (*del->cleanup)(st->state, st->sid, del->opaque); |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
363 fd_list_unlink(&st->chain); |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
364 free(st); |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
365 } |
1369
f1bbcab403a6
Clean up trailing whitespace in sessions.c
Thomas Klausner <tk@giga.or.at>
parents:
1093
diff
changeset
|
366 |
639
95a784729cac
Added new opaque pointer to fd_sess_handler_create and fd_disp_register for usability. Bumped API version number.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
557
diff
changeset
|
367 if (opaque) |
95a784729cac
Added new opaque pointer to fd_sess_handler_create and fd_disp_register for usability. Bumped API version number.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
557
diff
changeset
|
368 *opaque = del->opaque; |
1369
f1bbcab403a6
Clean up trailing whitespace in sessions.c
Thomas Klausner <tk@giga.or.at>
parents:
1093
diff
changeset
|
369 |
452
2b36eccbe426
Free unfreed memory
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
403
diff
changeset
|
370 /* Free the handler */ |
2b36eccbe426
Free unfreed memory
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
403
diff
changeset
|
371 free(del); |
1369
f1bbcab403a6
Clean up trailing whitespace in sessions.c
Thomas Klausner <tk@giga.or.at>
parents:
1093
diff
changeset
|
372 |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
373 return 0; |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
374 } |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
375 |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
376 |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
377 |
924
877592751fee
Fix (tentative) for invalid handling of sessions fast creation/destruction as pointed by Yusuke Okura -- http://lists.freediameter.net/pipermail/help/2013-February/000584.html and http://lists.freediameter.net/pipermail/help/2013-February/000589.html -- Thank you very much
Sebastien Decugis <sdecugis@freediameter.net>
parents:
788
diff
changeset
|
378 /* Create a new session object with the default timeout value, and link it. The refcount is increased by 1, whether the session existed or not */ |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
379 int fd_sess_new ( struct session ** session, DiamId_t diamid, size_t diamidlen, uint8_t * opt, size_t optlen ) |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
380 { |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
381 os0_t sid = NULL; |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
382 size_t sidlen; |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
383 uint32_t hash; |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
384 struct session * sess; |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
385 struct fd_list * li; |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
386 int found = 0; |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
387 int ret = 0; |
1369
f1bbcab403a6
Clean up trailing whitespace in sessions.c
Thomas Klausner <tk@giga.or.at>
parents:
1093
diff
changeset
|
388 |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
389 TRACE_ENTRY("%p %p %zd %p %zd", session, diamid, diamidlen, opt, optlen); |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
390 CHECK_PARAMS( session && (diamid || opt) ); |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
391 |
1369
f1bbcab403a6
Clean up trailing whitespace in sessions.c
Thomas Klausner <tk@giga.or.at>
parents:
1093
diff
changeset
|
392 if (diamid) { |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
393 if (!diamidlen) { |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
394 diamidlen = strlen(diamid); |
1369
f1bbcab403a6
Clean up trailing whitespace in sessions.c
Thomas Klausner <tk@giga.or.at>
parents:
1093
diff
changeset
|
395 } |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
396 /* We check if the string is a valid DiameterIdentity */ |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
397 CHECK_PARAMS( fd_os_is_valid_DiameterIdentity((uint8_t *)diamid, diamidlen) ); |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
398 } else { |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
399 diamidlen = 0; |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
400 } |
1369
f1bbcab403a6
Clean up trailing whitespace in sessions.c
Thomas Klausner <tk@giga.or.at>
parents:
1093
diff
changeset
|
401 if (opt) { |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
402 if (!optlen) { |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
403 optlen = strlen((char *)opt); |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
404 } else { |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
405 CHECK_PARAMS( fd_os_is_valid_os0(opt, optlen) ); |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
406 } |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
407 } else { |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
408 optlen = 0; |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
409 } |
1369
f1bbcab403a6
Clean up trailing whitespace in sessions.c
Thomas Klausner <tk@giga.or.at>
parents:
1093
diff
changeset
|
410 |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
411 /* Ok, first create the identifier for the string */ |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
412 if (diamid == NULL) { |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
413 /* opt is the full string */ |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
414 CHECK_MALLOC( sid = os0dup(opt, optlen) ); |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
415 sidlen = optlen; |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
416 } else { |
203
536b1dde8761
Some cleanups in the cnxctx module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
136
diff
changeset
|
417 uint32_t sid_h_cpy; |
536b1dde8761
Some cleanups in the cnxctx module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
136
diff
changeset
|
418 uint32_t sid_l_cpy; |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
419 /* "<diamId>;<high32>;<low32>[;opt]" */ |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
420 sidlen = diamidlen; |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
421 sidlen += 22; /* max size of ';<high32>;<low32>' */ |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
422 if (opt) |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
423 sidlen += 1 + optlen; /* ';opt' */ |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
424 sidlen++; /* space for the final \0 also */ |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
425 CHECK_MALLOC( sid = malloc(sidlen) ); |
1369
f1bbcab403a6
Clean up trailing whitespace in sessions.c
Thomas Klausner <tk@giga.or.at>
parents:
1093
diff
changeset
|
426 |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
427 CHECK_POSIX( pthread_mutex_lock(&sid_lock) ); |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
428 if ( ++sid_l == 0 ) /* overflow */ |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
429 ++sid_h; |
203
536b1dde8761
Some cleanups in the cnxctx module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
136
diff
changeset
|
430 sid_h_cpy = sid_h; |
536b1dde8761
Some cleanups in the cnxctx module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
136
diff
changeset
|
431 sid_l_cpy = sid_l; |
536b1dde8761
Some cleanups in the cnxctx module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
136
diff
changeset
|
432 CHECK_POSIX( pthread_mutex_unlock(&sid_lock) ); |
1369
f1bbcab403a6
Clean up trailing whitespace in sessions.c
Thomas Klausner <tk@giga.or.at>
parents:
1093
diff
changeset
|
433 |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
434 if (opt) { |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
435 sidlen = snprintf((char*)sid, sidlen, "%.*s;%u;%u;%.*s", (int)diamidlen, diamid, sid_h_cpy, sid_l_cpy, (int)optlen, opt); |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
436 } else { |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
437 sidlen = snprintf((char*)sid, sidlen, "%.*s;%u;%u", (int)diamidlen, diamid, sid_h_cpy, sid_l_cpy); |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
438 } |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
439 } |
1369
f1bbcab403a6
Clean up trailing whitespace in sessions.c
Thomas Klausner <tk@giga.or.at>
parents:
1093
diff
changeset
|
440 |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
441 hash = fd_os_hash(sid, sidlen); |
1369
f1bbcab403a6
Clean up trailing whitespace in sessions.c
Thomas Klausner <tk@giga.or.at>
parents:
1093
diff
changeset
|
442 |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
443 /* Now find the place to add this object in the hash table. */ |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
444 CHECK_POSIX( pthread_mutex_lock( H_LOCK(hash) ) ); |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
445 pthread_cleanup_push( fd_cleanup_mutex, H_LOCK(hash) ); |
1369
f1bbcab403a6
Clean up trailing whitespace in sessions.c
Thomas Klausner <tk@giga.or.at>
parents:
1093
diff
changeset
|
446 |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
447 for (li = H_LIST(hash)->next; li != H_LIST(hash); li = li->next) { |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
448 int cmp; |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
449 struct session * s = (struct session *)(li->o); |
1369
f1bbcab403a6
Clean up trailing whitespace in sessions.c
Thomas Klausner <tk@giga.or.at>
parents:
1093
diff
changeset
|
450 |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
451 /* The list is ordered by hash and sid (in case of collisions) */ |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
452 if (s->hash < hash) |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
453 continue; |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
454 if (s->hash > hash) |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
455 break; |
1369
f1bbcab403a6
Clean up trailing whitespace in sessions.c
Thomas Klausner <tk@giga.or.at>
parents:
1093
diff
changeset
|
456 |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
457 cmp = fd_os_cmp(s->sid, s->sidlen, sid, sidlen); |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
458 if (cmp < 0) |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
459 continue; |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
460 if (cmp > 0) |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
461 break; |
1369
f1bbcab403a6
Clean up trailing whitespace in sessions.c
Thomas Klausner <tk@giga.or.at>
parents:
1093
diff
changeset
|
462 |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
463 /* A session with the same sid was already in the hash table */ |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
464 found = 1; |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
465 *session = s; |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
466 break; |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
467 } |
1369
f1bbcab403a6
Clean up trailing whitespace in sessions.c
Thomas Klausner <tk@giga.or.at>
parents:
1093
diff
changeset
|
468 |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
469 /* If the session did not exist, we can create it & link it in global tables */ |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
470 if (!found) { |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
471 CHECK_MALLOC_DO(sess = new_session(sid, sidlen, hash), |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
472 { |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
473 ret = ENOMEM; |
785
e780452c6b55
Fix possible memory leaks
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
778
diff
changeset
|
474 free(sid); |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
475 goto out; |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
476 } ); |
1369
f1bbcab403a6
Clean up trailing whitespace in sessions.c
Thomas Klausner <tk@giga.or.at>
parents:
1093
diff
changeset
|
477 |
5
c2d2729e3603
Completed new session module tests; some bugs fixed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
4
diff
changeset
|
478 fd_list_insert_before(li, &sess->chain_h); /* hash table */ |
924
877592751fee
Fix (tentative) for invalid handling of sessions fast creation/destruction as pointed by Yusuke Okura -- http://lists.freediameter.net/pipermail/help/2013-February/000584.html and http://lists.freediameter.net/pipermail/help/2013-February/000589.html -- Thank you very much
Sebastien Decugis <sdecugis@freediameter.net>
parents:
788
diff
changeset
|
479 sess->msg_cnt++; |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
480 } else { |
785
e780452c6b55
Fix possible memory leaks
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
778
diff
changeset
|
481 free(sid); |
1369
f1bbcab403a6
Clean up trailing whitespace in sessions.c
Thomas Klausner <tk@giga.or.at>
parents:
1093
diff
changeset
|
482 |
f1bbcab403a6
Clean up trailing whitespace in sessions.c
Thomas Klausner <tk@giga.or.at>
parents:
1093
diff
changeset
|
483 CHECK_POSIX( pthread_mutex_lock(&(*session)->stlock) ); |
924
877592751fee
Fix (tentative) for invalid handling of sessions fast creation/destruction as pointed by Yusuke Okura -- http://lists.freediameter.net/pipermail/help/2013-February/000584.html and http://lists.freediameter.net/pipermail/help/2013-February/000589.html -- Thank you very much
Sebastien Decugis <sdecugis@freediameter.net>
parents:
788
diff
changeset
|
484 (*session)->msg_cnt++; |
1369
f1bbcab403a6
Clean up trailing whitespace in sessions.c
Thomas Klausner <tk@giga.or.at>
parents:
1093
diff
changeset
|
485 CHECK_POSIX( pthread_mutex_unlock(&(*session)->stlock) ); |
f1bbcab403a6
Clean up trailing whitespace in sessions.c
Thomas Klausner <tk@giga.or.at>
parents:
1093
diff
changeset
|
486 |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
487 /* it was found: was it previously destroyed? */ |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
488 if ((*session)->is_destroyed == 0) { |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
489 ret = EALREADY; |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
490 goto out; |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
491 } else { |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
492 /* the session was marked destroyed, let's re-activate it. */ |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
493 sess = *session; |
924
877592751fee
Fix (tentative) for invalid handling of sessions fast creation/destruction as pointed by Yusuke Okura -- http://lists.freediameter.net/pipermail/help/2013-February/000584.html and http://lists.freediameter.net/pipermail/help/2013-February/000589.html -- Thank you very much
Sebastien Decugis <sdecugis@freediameter.net>
parents:
788
diff
changeset
|
494 sess->is_destroyed = 0; |
1369
f1bbcab403a6
Clean up trailing whitespace in sessions.c
Thomas Klausner <tk@giga.or.at>
parents:
1093
diff
changeset
|
495 |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
496 /* update the expiry time */ |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
497 CHECK_SYS_DO( clock_gettime(CLOCK_REALTIME, &sess->timeout), { ASSERT(0); } ); |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
498 sess->timeout.tv_sec += SESS_DEFAULT_LIFETIME; |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
499 } |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
500 } |
1369
f1bbcab403a6
Clean up trailing whitespace in sessions.c
Thomas Klausner <tk@giga.or.at>
parents:
1093
diff
changeset
|
501 |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
502 /* We must insert in the expiry list */ |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
503 CHECK_POSIX( pthread_mutex_lock( &exp_lock ) ); |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
504 pthread_cleanup_push( fd_cleanup_mutex, &exp_lock ); |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
505 |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
506 /* Find the position in that list. We take it in reverse order */ |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
507 for (li = exp_sentinel.prev; li != &exp_sentinel; li = li->prev) { |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
508 struct session * s = (struct session *)(li->o); |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
509 if (TS_IS_INFERIOR( &s->timeout, &sess->timeout ) ) |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
510 break; |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
511 } |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
512 fd_list_insert_after( li, &sess->expire ); |
778
003df4a9ade2
Added two new interfaces on Zach requests http://lists.freediameter.net/pipermail/help/2012-January/000312.html and http://lists.freediameter.net/pipermail/help/2012-January/000311.html
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
513 sess_cnt++; |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
514 |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
515 /* We added a new expiring element, we must signal */ |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
516 if (li == &exp_sentinel) { |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
517 CHECK_POSIX_DO( pthread_cond_signal(&exp_cond), { ASSERT(0); } ); /* if it fails, we might not pop the cleanup handlers, but this should not happen -- and we'd have a serious problem otherwise */ |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
518 } |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
519 |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
520 /* We're done with the locked part */ |
203
536b1dde8761
Some cleanups in the cnxctx module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
136
diff
changeset
|
521 pthread_cleanup_pop(0); |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
522 CHECK_POSIX_DO( pthread_mutex_unlock( &exp_lock ), { ASSERT(0); } ); /* if it fails, we might not pop the cleanup handler, but this should not happen -- and we'd have a serious problem otherwise */ |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
523 |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
524 out: |
924
877592751fee
Fix (tentative) for invalid handling of sessions fast creation/destruction as pointed by Yusuke Okura -- http://lists.freediameter.net/pipermail/help/2013-February/000584.html and http://lists.freediameter.net/pipermail/help/2013-February/000589.html -- Thank you very much
Sebastien Decugis <sdecugis@freediameter.net>
parents:
788
diff
changeset
|
525 ; |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
526 pthread_cleanup_pop(0); |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
527 CHECK_POSIX( pthread_mutex_unlock( H_LOCK(hash) ) ); |
1369
f1bbcab403a6
Clean up trailing whitespace in sessions.c
Thomas Klausner <tk@giga.or.at>
parents:
1093
diff
changeset
|
528 |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
529 if (ret) /* in case of error */ |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
530 return ret; |
1369
f1bbcab403a6
Clean up trailing whitespace in sessions.c
Thomas Klausner <tk@giga.or.at>
parents:
1093
diff
changeset
|
531 |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
532 *session = sess; |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
533 return 0; |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
534 } |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
535 |
924
877592751fee
Fix (tentative) for invalid handling of sessions fast creation/destruction as pointed by Yusuke Okura -- http://lists.freediameter.net/pipermail/help/2013-February/000584.html and http://lists.freediameter.net/pipermail/help/2013-February/000589.html -- Thank you very much
Sebastien Decugis <sdecugis@freediameter.net>
parents:
788
diff
changeset
|
536 /* Find or create a session -- the msg refcount is increased */ |
877592751fee
Fix (tentative) for invalid handling of sessions fast creation/destruction as pointed by Yusuke Okura -- http://lists.freediameter.net/pipermail/help/2013-February/000584.html and http://lists.freediameter.net/pipermail/help/2013-February/000589.html -- Thank you very much
Sebastien Decugis <sdecugis@freediameter.net>
parents:
788
diff
changeset
|
537 int fd_sess_fromsid_msg ( uint8_t * sid, size_t len, struct session ** session, int * new) |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
538 { |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
539 int ret; |
1369
f1bbcab403a6
Clean up trailing whitespace in sessions.c
Thomas Klausner <tk@giga.or.at>
parents:
1093
diff
changeset
|
540 |
1027
0117a7746b21
Fix a number of errors and warnings introduced/highlighted by recent commits
Sebastien Decugis <sdecugis@freediameter.net>
parents:
979
diff
changeset
|
541 TRACE_ENTRY("%p %zd %p %p", sid, len, session, new); |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
542 CHECK_PARAMS( sid && session ); |
1369
f1bbcab403a6
Clean up trailing whitespace in sessions.c
Thomas Klausner <tk@giga.or.at>
parents:
1093
diff
changeset
|
543 |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
544 if (!fd_os_is_valid_os0(sid,len)) { |
1027
0117a7746b21
Fix a number of errors and warnings introduced/highlighted by recent commits
Sebastien Decugis <sdecugis@freediameter.net>
parents:
979
diff
changeset
|
545 TRACE_DEBUG(INFO, "Warning: a Session-Id value contains \\0 chars... (len:%zd, begin:'%.*s') => Debug messages may be truncated.", len, (int)len, sid); |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
546 } |
1369
f1bbcab403a6
Clean up trailing whitespace in sessions.c
Thomas Klausner <tk@giga.or.at>
parents:
1093
diff
changeset
|
547 |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
548 /* All the work is done in sess_new */ |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
549 ret = fd_sess_new ( session, NULL, 0, sid, len ); |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
550 switch (ret) { |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
551 case 0: |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
552 case EALREADY: |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
553 break; |
1369
f1bbcab403a6
Clean up trailing whitespace in sessions.c
Thomas Klausner <tk@giga.or.at>
parents:
1093
diff
changeset
|
554 |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
555 default: |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
556 CHECK_FCT(ret); |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
557 } |
1369
f1bbcab403a6
Clean up trailing whitespace in sessions.c
Thomas Klausner <tk@giga.or.at>
parents:
1093
diff
changeset
|
558 |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
559 if (new) |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
560 *new = ret ? 0 : 1; |
1369
f1bbcab403a6
Clean up trailing whitespace in sessions.c
Thomas Klausner <tk@giga.or.at>
parents:
1093
diff
changeset
|
561 |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
562 return 0; |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
563 } |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
564 |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
565 /* Get the sid of a session */ |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
566 int fd_sess_getsid ( struct session * session, os0_t * sid, size_t * sidlen ) |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
567 { |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
568 TRACE_ENTRY("%p %p", session, sid); |
1369
f1bbcab403a6
Clean up trailing whitespace in sessions.c
Thomas Klausner <tk@giga.or.at>
parents:
1093
diff
changeset
|
569 |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
570 CHECK_PARAMS( VALIDATE_SI(session) && sid ); |
1369
f1bbcab403a6
Clean up trailing whitespace in sessions.c
Thomas Klausner <tk@giga.or.at>
parents:
1093
diff
changeset
|
571 |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
572 *sid = session->sid; |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
573 if (sidlen) |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
574 *sidlen = session->sidlen; |
1369
f1bbcab403a6
Clean up trailing whitespace in sessions.c
Thomas Klausner <tk@giga.or.at>
parents:
1093
diff
changeset
|
575 |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
576 return 0; |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
577 } |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
578 |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
579 /* Change the timeout value of a session */ |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
580 int fd_sess_settimeout( struct session * session, const struct timespec * timeout ) |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
581 { |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
582 struct fd_list * li; |
1369
f1bbcab403a6
Clean up trailing whitespace in sessions.c
Thomas Klausner <tk@giga.or.at>
parents:
1093
diff
changeset
|
583 |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
584 TRACE_ENTRY("%p %p", session, timeout); |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
585 CHECK_PARAMS( VALIDATE_SI(session) && timeout ); |
1369
f1bbcab403a6
Clean up trailing whitespace in sessions.c
Thomas Klausner <tk@giga.or.at>
parents:
1093
diff
changeset
|
586 |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
587 /* Lock -- do we need to lock the hash table as well? I don't think so... */ |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
588 CHECK_POSIX( pthread_mutex_lock( &exp_lock ) ); |
203
536b1dde8761
Some cleanups in the cnxctx module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
136
diff
changeset
|
589 pthread_cleanup_push( fd_cleanup_mutex, &exp_lock ); |
1369
f1bbcab403a6
Clean up trailing whitespace in sessions.c
Thomas Klausner <tk@giga.or.at>
parents:
1093
diff
changeset
|
590 |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
591 /* Update the timeout */ |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
592 fd_list_unlink(&session->expire); |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
593 memcpy(&session->timeout, timeout, sizeof(struct timespec)); |
1369
f1bbcab403a6
Clean up trailing whitespace in sessions.c
Thomas Klausner <tk@giga.or.at>
parents:
1093
diff
changeset
|
594 |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
595 /* Find the new position in expire list. We take it in normal order */ |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
596 for (li = exp_sentinel.next; li != &exp_sentinel; li = li->next) { |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
597 struct session * s = (struct session *)(li->o); |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
598 |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
599 if (TS_IS_INFERIOR( &s->timeout, &session->timeout ) ) |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
600 continue; |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
601 |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
602 break; |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
603 } |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
604 fd_list_insert_before( li, &session->expire ); |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
605 |
14
14cf6daf716d
Some progress on peers module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
7
diff
changeset
|
606 /* We added a new expiring element, we must signal if it was in first position */ |
14cf6daf716d
Some progress on peers module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
7
diff
changeset
|
607 if (session->expire.prev == &exp_sentinel) { |
691
78b665400097
Cleanup all pthread_cleanup_push / pop pairs so that pop is always called after push, or ASSERT(0) is some grave errors
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
686
diff
changeset
|
608 CHECK_POSIX_DO( pthread_cond_signal(&exp_cond), { ASSERT(0); /* so that we don't have a pending cancellation handler */ } ); |
14
14cf6daf716d
Some progress on peers module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
7
diff
changeset
|
609 } |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
610 |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
611 /* We're done */ |
203
536b1dde8761
Some cleanups in the cnxctx module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
136
diff
changeset
|
612 pthread_cleanup_pop(0); |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
613 CHECK_POSIX( pthread_mutex_unlock( &exp_lock ) ); |
1369
f1bbcab403a6
Clean up trailing whitespace in sessions.c
Thomas Klausner <tk@giga.or.at>
parents:
1093
diff
changeset
|
614 |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
615 return 0; |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
616 } |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
617 |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
618 /* Destroy the states associated to a session, and mark it destroyed. */ |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
619 int fd_sess_destroy ( struct session ** session ) |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
620 { |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
621 struct session * sess; |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
622 int destroy_now; |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
623 os0_t sid; |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
624 int ret = 0; |
1369
f1bbcab403a6
Clean up trailing whitespace in sessions.c
Thomas Klausner <tk@giga.or.at>
parents:
1093
diff
changeset
|
625 |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
626 /* place to save the list of states to be cleaned up. We do it after finding them to avoid deadlocks. the "o" field becomes a copy of the sid. */ |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
627 struct fd_list deleted_states = FD_LIST_INITIALIZER( deleted_states ); |
1369
f1bbcab403a6
Clean up trailing whitespace in sessions.c
Thomas Klausner <tk@giga.or.at>
parents:
1093
diff
changeset
|
628 |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
629 TRACE_ENTRY("%p", session); |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
630 CHECK_PARAMS( session && VALIDATE_SI(*session) ); |
1369
f1bbcab403a6
Clean up trailing whitespace in sessions.c
Thomas Klausner <tk@giga.or.at>
parents:
1093
diff
changeset
|
631 |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
632 sess = *session; |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
633 *session = NULL; |
1369
f1bbcab403a6
Clean up trailing whitespace in sessions.c
Thomas Klausner <tk@giga.or.at>
parents:
1093
diff
changeset
|
634 |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
635 /* Lock the hash line */ |
691
78b665400097
Cleanup all pthread_cleanup_push / pop pairs so that pop is always called after push, or ASSERT(0) is some grave errors
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
686
diff
changeset
|
636 CHECK_POSIX( pthread_mutex_lock( H_LOCK(sess->hash) ) ); |
203
536b1dde8761
Some cleanups in the cnxctx module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
136
diff
changeset
|
637 pthread_cleanup_push( fd_cleanup_mutex, H_LOCK(sess->hash) ); |
1369
f1bbcab403a6
Clean up trailing whitespace in sessions.c
Thomas Klausner <tk@giga.or.at>
parents:
1093
diff
changeset
|
638 |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
639 /* Unlink from the expiry list */ |
691
78b665400097
Cleanup all pthread_cleanup_push / pop pairs so that pop is always called after push, or ASSERT(0) is some grave errors
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
686
diff
changeset
|
640 CHECK_POSIX_DO( pthread_mutex_lock( &exp_lock ), { ASSERT(0); /* otherwise cleanup handler is not pop'd */ } ); |
1369
f1bbcab403a6
Clean up trailing whitespace in sessions.c
Thomas Klausner <tk@giga.or.at>
parents:
1093
diff
changeset
|
641 pthread_cleanup_push( fd_cleanup_mutex, &exp_lock ); |
778
003df4a9ade2
Added two new interfaces on Zach requests http://lists.freediameter.net/pipermail/help/2012-January/000312.html and http://lists.freediameter.net/pipermail/help/2012-January/000311.html
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
642 if (!FD_IS_LIST_EMPTY(&sess->expire)) { |
003df4a9ade2
Added two new interfaces on Zach requests http://lists.freediameter.net/pipermail/help/2012-January/000312.html and http://lists.freediameter.net/pipermail/help/2012-January/000311.html
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
643 sess_cnt--; |
003df4a9ade2
Added two new interfaces on Zach requests http://lists.freediameter.net/pipermail/help/2012-January/000312.html and http://lists.freediameter.net/pipermail/help/2012-January/000311.html
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
644 fd_list_unlink( &sess->expire ); /* no need to signal the condition here */ |
003df4a9ade2
Added two new interfaces on Zach requests http://lists.freediameter.net/pipermail/help/2012-January/000312.html and http://lists.freediameter.net/pipermail/help/2012-January/000311.html
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
645 } |
1369
f1bbcab403a6
Clean up trailing whitespace in sessions.c
Thomas Klausner <tk@giga.or.at>
parents:
1093
diff
changeset
|
646 pthread_cleanup_pop(0); |
691
78b665400097
Cleanup all pthread_cleanup_push / pop pairs so that pop is always called after push, or ASSERT(0) is some grave errors
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
686
diff
changeset
|
647 CHECK_POSIX_DO( pthread_mutex_unlock( &exp_lock ), { ASSERT(0); /* otherwise cleanup handler is not pop'd */ } ); |
1369
f1bbcab403a6
Clean up trailing whitespace in sessions.c
Thomas Klausner <tk@giga.or.at>
parents:
1093
diff
changeset
|
648 |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
649 /* Now move all states associated to this session into deleted_states */ |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
650 CHECK_POSIX_DO( pthread_mutex_lock( &sess->stlock ), { ASSERT(0); /* otherwise cleanup handler is not pop'd */ } ); |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
651 while (!FD_IS_LIST_EMPTY(&sess->states)) { |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
652 struct state * st = (struct state *)(sess->states.next->o); |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
653 fd_list_unlink(&st->chain); |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
654 fd_list_insert_before(&deleted_states, &st->chain); |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
655 } |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
656 CHECK_POSIX_DO( pthread_mutex_unlock( &sess->stlock ), { ASSERT(0); /* otherwise cleanup handler is not pop'd */ } ); |
1369
f1bbcab403a6
Clean up trailing whitespace in sessions.c
Thomas Klausner <tk@giga.or.at>
parents:
1093
diff
changeset
|
657 |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
658 /* Mark the session as destroyed */ |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
659 destroy_now = (sess->msg_cnt == 0); |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
660 if (destroy_now) { |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
661 fd_list_unlink( &sess->chain_h ); |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
662 sid = sess->sid; |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
663 } else { |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
664 sess->is_destroyed = 1; |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
665 CHECK_MALLOC_DO( sid = os0dup(sess->sid, sess->sidlen), ret = ENOMEM ); |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
666 } |
203
536b1dde8761
Some cleanups in the cnxctx module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
136
diff
changeset
|
667 pthread_cleanup_pop(0); |
691
78b665400097
Cleanup all pthread_cleanup_push / pop pairs so that pop is always called after push, or ASSERT(0) is some grave errors
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
686
diff
changeset
|
668 CHECK_POSIX( pthread_mutex_unlock( H_LOCK(sess->hash) ) ); |
1369
f1bbcab403a6
Clean up trailing whitespace in sessions.c
Thomas Klausner <tk@giga.or.at>
parents:
1093
diff
changeset
|
669 |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
670 if (ret) |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
671 return ret; |
1369
f1bbcab403a6
Clean up trailing whitespace in sessions.c
Thomas Klausner <tk@giga.or.at>
parents:
1093
diff
changeset
|
672 |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
673 /* Now, really delete the states */ |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
674 while (!FD_IS_LIST_EMPTY(&deleted_states)) { |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
675 struct state * st = (struct state *)(deleted_states.next->o); |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
676 fd_list_unlink(&st->chain); |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
677 TRACE_DEBUG(FULL, "Calling handler %p cleanup for state %p registered with session '%s'", st->hdl, st, sid); |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
678 (*st->hdl->cleanup)(st->state, sid, st->hdl->opaque); |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
679 free(st); |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
680 } |
1369
f1bbcab403a6
Clean up trailing whitespace in sessions.c
Thomas Klausner <tk@giga.or.at>
parents:
1093
diff
changeset
|
681 |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
682 /* Finally, destroy the session itself, if it is not referrenced by any message anymore */ |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
683 if (destroy_now) { |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
684 del_session(sess); |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
685 } else { |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
686 free(sid); |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
687 } |
1369
f1bbcab403a6
Clean up trailing whitespace in sessions.c
Thomas Klausner <tk@giga.or.at>
parents:
1093
diff
changeset
|
688 |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
689 return 0; |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
690 } |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
691 |
6
b0d377c79d80
Progress on dispatch API spec; added fd_sess_reclaim function and test
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
5
diff
changeset
|
692 /* Destroy a session if it is not used */ |
b0d377c79d80
Progress on dispatch API spec; added fd_sess_reclaim function and test
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
5
diff
changeset
|
693 int fd_sess_reclaim ( struct session ** session ) |
b0d377c79d80
Progress on dispatch API spec; added fd_sess_reclaim function and test
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
5
diff
changeset
|
694 { |
b0d377c79d80
Progress on dispatch API spec; added fd_sess_reclaim function and test
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
5
diff
changeset
|
695 struct session * sess; |
293
ec67c5096eeb
Fix small issue with access to freed memory
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
291
diff
changeset
|
696 uint32_t hash; |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
697 int destroy_now = 0; |
1369
f1bbcab403a6
Clean up trailing whitespace in sessions.c
Thomas Klausner <tk@giga.or.at>
parents:
1093
diff
changeset
|
698 |
6
b0d377c79d80
Progress on dispatch API spec; added fd_sess_reclaim function and test
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
5
diff
changeset
|
699 TRACE_ENTRY("%p", session); |
b0d377c79d80
Progress on dispatch API spec; added fd_sess_reclaim function and test
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
5
diff
changeset
|
700 CHECK_PARAMS( session && VALIDATE_SI(*session) ); |
1369
f1bbcab403a6
Clean up trailing whitespace in sessions.c
Thomas Klausner <tk@giga.or.at>
parents:
1093
diff
changeset
|
701 |
6
b0d377c79d80
Progress on dispatch API spec; added fd_sess_reclaim function and test
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
5
diff
changeset
|
702 sess = *session; |
293
ec67c5096eeb
Fix small issue with access to freed memory
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
291
diff
changeset
|
703 hash = sess->hash; |
6
b0d377c79d80
Progress on dispatch API spec; added fd_sess_reclaim function and test
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
5
diff
changeset
|
704 *session = NULL; |
1369
f1bbcab403a6
Clean up trailing whitespace in sessions.c
Thomas Klausner <tk@giga.or.at>
parents:
1093
diff
changeset
|
705 |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
706 CHECK_POSIX( pthread_mutex_lock( H_LOCK(hash) ) ); |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
707 pthread_cleanup_push( fd_cleanup_mutex, H_LOCK(hash) ); |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
708 CHECK_POSIX_DO( pthread_mutex_lock( &sess->stlock ), { ASSERT(0); /* otherwise, cleanup not poped on FreeBSD */ } ); |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
709 pthread_cleanup_push( fd_cleanup_mutex, &sess->stlock ); |
691
78b665400097
Cleanup all pthread_cleanup_push / pop pairs so that pop is always called after push, or ASSERT(0) is some grave errors
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
686
diff
changeset
|
710 CHECK_POSIX_DO( pthread_mutex_lock( &exp_lock ), { ASSERT(0); /* otherwise, cleanup not poped on FreeBSD */ } ); |
1369
f1bbcab403a6
Clean up trailing whitespace in sessions.c
Thomas Klausner <tk@giga.or.at>
parents:
1093
diff
changeset
|
711 pthread_cleanup_push( fd_cleanup_mutex, &exp_lock ); |
f1bbcab403a6
Clean up trailing whitespace in sessions.c
Thomas Klausner <tk@giga.or.at>
parents:
1093
diff
changeset
|
712 |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
713 /* We only do something if the states list is empty */ |
6
b0d377c79d80
Progress on dispatch API spec; added fd_sess_reclaim function and test
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
5
diff
changeset
|
714 if (FD_IS_LIST_EMPTY(&sess->states)) { |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
715 /* In this case, we do as in destroy */ |
6
b0d377c79d80
Progress on dispatch API spec; added fd_sess_reclaim function and test
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
5
diff
changeset
|
716 fd_list_unlink( &sess->expire ); |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
717 destroy_now = (sess->msg_cnt == 0); |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
718 if (destroy_now) { |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
719 fd_list_unlink(&sess->chain_h); |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
720 } else { |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
721 /* just mark it as destroyed, it will be freed when the last message stops referencing it */ |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
722 sess->is_destroyed = 1; |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
723 } |
6
b0d377c79d80
Progress on dispatch API spec; added fd_sess_reclaim function and test
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
5
diff
changeset
|
724 } |
1369
f1bbcab403a6
Clean up trailing whitespace in sessions.c
Thomas Klausner <tk@giga.or.at>
parents:
1093
diff
changeset
|
725 |
f1bbcab403a6
Clean up trailing whitespace in sessions.c
Thomas Klausner <tk@giga.or.at>
parents:
1093
diff
changeset
|
726 pthread_cleanup_pop(0); |
691
78b665400097
Cleanup all pthread_cleanup_push / pop pairs so that pop is always called after push, or ASSERT(0) is some grave errors
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
686
diff
changeset
|
727 CHECK_POSIX_DO( pthread_mutex_unlock( &exp_lock ), { ASSERT(0); /* otherwise, cleanup not poped on FreeBSD */ } ); |
203
536b1dde8761
Some cleanups in the cnxctx module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
136
diff
changeset
|
728 pthread_cleanup_pop(0); |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
729 CHECK_POSIX_DO( pthread_mutex_unlock( &sess->stlock ), { ASSERT(0); /* otherwise, cleanup not poped on FreeBSD */ } ); |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
730 pthread_cleanup_pop(0); |
293
ec67c5096eeb
Fix small issue with access to freed memory
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
291
diff
changeset
|
731 CHECK_POSIX( pthread_mutex_unlock( H_LOCK(hash) ) ); |
1369
f1bbcab403a6
Clean up trailing whitespace in sessions.c
Thomas Klausner <tk@giga.or.at>
parents:
1093
diff
changeset
|
732 |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
733 if (destroy_now) |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
734 del_session(sess); |
1369
f1bbcab403a6
Clean up trailing whitespace in sessions.c
Thomas Klausner <tk@giga.or.at>
parents:
1093
diff
changeset
|
735 |
6
b0d377c79d80
Progress on dispatch API spec; added fd_sess_reclaim function and test
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
5
diff
changeset
|
736 return 0; |
b0d377c79d80
Progress on dispatch API spec; added fd_sess_reclaim function and test
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
5
diff
changeset
|
737 } |
b0d377c79d80
Progress on dispatch API spec; added fd_sess_reclaim function and test
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
5
diff
changeset
|
738 |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
739 /* Save a state information with a session */ |
1088
1d1a20a0779d
Second part of changeset 1083, now the code compiles again. Still missing some functions implementation, though
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1085
diff
changeset
|
740 int fd_sess_state_store ( struct session_handler * handler, struct session * session, struct sess_state ** state ) |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
741 { |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
742 struct state *new; |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
743 struct fd_list * li; |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
744 int already = 0; |
691
78b665400097
Cleanup all pthread_cleanup_push / pop pairs so that pop is always called after push, or ASSERT(0) is some grave errors
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
686
diff
changeset
|
745 int ret = 0; |
1369
f1bbcab403a6
Clean up trailing whitespace in sessions.c
Thomas Klausner <tk@giga.or.at>
parents:
1093
diff
changeset
|
746 |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
747 TRACE_ENTRY("%p %p %p", handler, session, state); |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
748 CHECK_PARAMS( handler && VALIDATE_SH(handler) && session && VALIDATE_SI(session) && (!session->is_destroyed) && state ); |
1369
f1bbcab403a6
Clean up trailing whitespace in sessions.c
Thomas Klausner <tk@giga.or.at>
parents:
1093
diff
changeset
|
749 |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
750 /* Lock the session state list */ |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
751 CHECK_POSIX( pthread_mutex_lock(&session->stlock) ); |
203
536b1dde8761
Some cleanups in the cnxctx module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
136
diff
changeset
|
752 pthread_cleanup_push( fd_cleanup_mutex, &session->stlock ); |
1369
f1bbcab403a6
Clean up trailing whitespace in sessions.c
Thomas Klausner <tk@giga.or.at>
parents:
1093
diff
changeset
|
753 |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
754 /* Create the new state object */ |
691
78b665400097
Cleanup all pthread_cleanup_push / pop pairs so that pop is always called after push, or ASSERT(0) is some grave errors
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
686
diff
changeset
|
755 CHECK_MALLOC_DO(new = malloc(sizeof(struct state)), { ret = ENOMEM; goto out; } ); |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
756 memset(new, 0, sizeof(struct state)); |
1369
f1bbcab403a6
Clean up trailing whitespace in sessions.c
Thomas Klausner <tk@giga.or.at>
parents:
1093
diff
changeset
|
757 |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
758 new->eyec = SD_EYEC; |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
759 new->state= *state; |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
760 fd_list_init(&new->chain, new); |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
761 new->hdl = handler; |
1369
f1bbcab403a6
Clean up trailing whitespace in sessions.c
Thomas Klausner <tk@giga.or.at>
parents:
1093
diff
changeset
|
762 |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
763 /* find place for this state in the list */ |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
764 for (li = session->states.next; li != &session->states; li = li->next) { |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
765 struct state * st = (struct state *)(li->o); |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
766 /* The list is ordered by handler's id */ |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
767 if (st->hdl->id < handler->id) |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
768 continue; |
1369
f1bbcab403a6
Clean up trailing whitespace in sessions.c
Thomas Klausner <tk@giga.or.at>
parents:
1093
diff
changeset
|
769 |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
770 if (st->hdl->id == handler->id) { |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
771 TRACE_DEBUG(INFO, "A state was already stored for session '%s' and handler '%p', at location %p", session->sid, st->hdl, st->state); |
691
78b665400097
Cleanup all pthread_cleanup_push / pop pairs so that pop is always called after push, or ASSERT(0) is some grave errors
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
686
diff
changeset
|
772 already = EALREADY; |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
773 } |
1369
f1bbcab403a6
Clean up trailing whitespace in sessions.c
Thomas Klausner <tk@giga.or.at>
parents:
1093
diff
changeset
|
774 |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
775 break; |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
776 } |
1369
f1bbcab403a6
Clean up trailing whitespace in sessions.c
Thomas Klausner <tk@giga.or.at>
parents:
1093
diff
changeset
|
777 |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
778 if (!already) { |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
779 fd_list_insert_before(li, &new->chain); |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
780 *state = NULL; |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
781 } else { |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
782 free(new); |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
783 } |
691
78b665400097
Cleanup all pthread_cleanup_push / pop pairs so that pop is always called after push, or ASSERT(0) is some grave errors
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
686
diff
changeset
|
784 out: |
1369
f1bbcab403a6
Clean up trailing whitespace in sessions.c
Thomas Klausner <tk@giga.or.at>
parents:
1093
diff
changeset
|
785 ; |
203
536b1dde8761
Some cleanups in the cnxctx module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
136
diff
changeset
|
786 pthread_cleanup_pop(0); |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
787 CHECK_POSIX( pthread_mutex_unlock(&session->stlock) ); |
1369
f1bbcab403a6
Clean up trailing whitespace in sessions.c
Thomas Klausner <tk@giga.or.at>
parents:
1093
diff
changeset
|
788 |
691
78b665400097
Cleanup all pthread_cleanup_push / pop pairs so that pop is always called after push, or ASSERT(0) is some grave errors
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
686
diff
changeset
|
789 return ret ?: already; |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
790 } |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
791 |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
792 /* Get the data back */ |
1088
1d1a20a0779d
Second part of changeset 1083, now the code compiles again. Still missing some functions implementation, though
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1085
diff
changeset
|
793 int fd_sess_state_retrieve ( struct session_handler * handler, struct session * session, struct sess_state ** state ) |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
794 { |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
795 struct fd_list * li; |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
796 struct state * st = NULL; |
1369
f1bbcab403a6
Clean up trailing whitespace in sessions.c
Thomas Klausner <tk@giga.or.at>
parents:
1093
diff
changeset
|
797 |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
798 TRACE_ENTRY("%p %p %p", handler, session, state); |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
799 CHECK_PARAMS( handler && VALIDATE_SH(handler) && session && VALIDATE_SI(session) && state ); |
1369
f1bbcab403a6
Clean up trailing whitespace in sessions.c
Thomas Klausner <tk@giga.or.at>
parents:
1093
diff
changeset
|
800 |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
801 *state = NULL; |
1369
f1bbcab403a6
Clean up trailing whitespace in sessions.c
Thomas Klausner <tk@giga.or.at>
parents:
1093
diff
changeset
|
802 |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
803 /* Lock the session state list */ |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
804 CHECK_POSIX( pthread_mutex_lock(&session->stlock) ); |
203
536b1dde8761
Some cleanups in the cnxctx module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
136
diff
changeset
|
805 pthread_cleanup_push( fd_cleanup_mutex, &session->stlock ); |
1369
f1bbcab403a6
Clean up trailing whitespace in sessions.c
Thomas Klausner <tk@giga.or.at>
parents:
1093
diff
changeset
|
806 |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
807 /* find the state in the list */ |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
808 for (li = session->states.next; li != &session->states; li = li->next) { |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
809 st = (struct state *)(li->o); |
1369
f1bbcab403a6
Clean up trailing whitespace in sessions.c
Thomas Klausner <tk@giga.or.at>
parents:
1093
diff
changeset
|
810 |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
811 /* The list is ordered by handler's id */ |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
812 if (st->hdl->id > handler->id) |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
813 break; |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
814 } |
1369
f1bbcab403a6
Clean up trailing whitespace in sessions.c
Thomas Klausner <tk@giga.or.at>
parents:
1093
diff
changeset
|
815 |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
816 /* If we found the state */ |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
817 if (st && (st->hdl == handler)) { |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
818 fd_list_unlink(&st->chain); |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
819 *state = st->state; |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
820 free(st); |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
821 } |
1369
f1bbcab403a6
Clean up trailing whitespace in sessions.c
Thomas Klausner <tk@giga.or.at>
parents:
1093
diff
changeset
|
822 |
203
536b1dde8761
Some cleanups in the cnxctx module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
136
diff
changeset
|
823 pthread_cleanup_pop(0); |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
824 CHECK_POSIX( pthread_mutex_unlock(&session->stlock) ); |
1369
f1bbcab403a6
Clean up trailing whitespace in sessions.c
Thomas Klausner <tk@giga.or.at>
parents:
1093
diff
changeset
|
825 |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
826 return 0; |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
827 } |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
828 |
85
e5fcd672caff
Added new function to retrieve messages sessions easily
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
829 /* For the messages module */ |
924
877592751fee
Fix (tentative) for invalid handling of sessions fast creation/destruction as pointed by Yusuke Okura -- http://lists.freediameter.net/pipermail/help/2013-February/000584.html and http://lists.freediameter.net/pipermail/help/2013-February/000589.html -- Thank you very much
Sebastien Decugis <sdecugis@freediameter.net>
parents:
788
diff
changeset
|
830 int fd_sess_fromsid ( uint8_t * sid, size_t len, struct session ** session, int * new) |
85
e5fcd672caff
Added new function to retrieve messages sessions easily
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
831 { |
e5fcd672caff
Added new function to retrieve messages sessions easily
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
832 TRACE_ENTRY("%p %zd %p %p", sid, len, session, new); |
102
69e2b33ee817
Removed stupid check
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
85
diff
changeset
|
833 CHECK_PARAMS( sid && len && session ); |
1369
f1bbcab403a6
Clean up trailing whitespace in sessions.c
Thomas Klausner <tk@giga.or.at>
parents:
1093
diff
changeset
|
834 |
85
e5fcd672caff
Added new function to retrieve messages sessions easily
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
835 /* Get the session object */ |
924
877592751fee
Fix (tentative) for invalid handling of sessions fast creation/destruction as pointed by Yusuke Okura -- http://lists.freediameter.net/pipermail/help/2013-February/000584.html and http://lists.freediameter.net/pipermail/help/2013-February/000589.html -- Thank you very much
Sebastien Decugis <sdecugis@freediameter.net>
parents:
788
diff
changeset
|
836 CHECK_FCT( fd_sess_fromsid_msg ( sid, len, session, new) ); |
1369
f1bbcab403a6
Clean up trailing whitespace in sessions.c
Thomas Klausner <tk@giga.or.at>
parents:
1093
diff
changeset
|
837 |
924
877592751fee
Fix (tentative) for invalid handling of sessions fast creation/destruction as pointed by Yusuke Okura -- http://lists.freediameter.net/pipermail/help/2013-February/000584.html and http://lists.freediameter.net/pipermail/help/2013-February/000589.html -- Thank you very much
Sebastien Decugis <sdecugis@freediameter.net>
parents:
788
diff
changeset
|
838 /* Decrease the refcount */ |
877592751fee
Fix (tentative) for invalid handling of sessions fast creation/destruction as pointed by Yusuke Okura -- http://lists.freediameter.net/pipermail/help/2013-February/000584.html and http://lists.freediameter.net/pipermail/help/2013-February/000589.html -- Thank you very much
Sebastien Decugis <sdecugis@freediameter.net>
parents:
788
diff
changeset
|
839 CHECK_POSIX( pthread_mutex_lock(&(*session)->stlock) ); |
877592751fee
Fix (tentative) for invalid handling of sessions fast creation/destruction as pointed by Yusuke Okura -- http://lists.freediameter.net/pipermail/help/2013-February/000584.html and http://lists.freediameter.net/pipermail/help/2013-February/000589.html -- Thank you very much
Sebastien Decugis <sdecugis@freediameter.net>
parents:
788
diff
changeset
|
840 (*session)->msg_cnt--; /* was increased in fd_sess_new */ |
877592751fee
Fix (tentative) for invalid handling of sessions fast creation/destruction as pointed by Yusuke Okura -- http://lists.freediameter.net/pipermail/help/2013-February/000584.html and http://lists.freediameter.net/pipermail/help/2013-February/000589.html -- Thank you very much
Sebastien Decugis <sdecugis@freediameter.net>
parents:
788
diff
changeset
|
841 CHECK_POSIX( pthread_mutex_unlock(&(*session)->stlock) ); |
1369
f1bbcab403a6
Clean up trailing whitespace in sessions.c
Thomas Klausner <tk@giga.or.at>
parents:
1093
diff
changeset
|
842 |
85
e5fcd672caff
Added new function to retrieve messages sessions easily
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
843 /* Done */ |
e5fcd672caff
Added new function to retrieve messages sessions easily
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
844 return 0; |
e5fcd672caff
Added new function to retrieve messages sessions easily
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
845 } |
e5fcd672caff
Added new function to retrieve messages sessions easily
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
846 |
291
2d3a799ad29c
Cache the session pointer in answers when it was present in queries
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
258
diff
changeset
|
847 int fd_sess_ref_msg ( struct session * session ) |
2d3a799ad29c
Cache the session pointer in answers when it was present in queries
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
258
diff
changeset
|
848 { |
2d3a799ad29c
Cache the session pointer in answers when it was present in queries
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
258
diff
changeset
|
849 TRACE_ENTRY("%p", session); |
2d3a799ad29c
Cache the session pointer in answers when it was present in queries
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
258
diff
changeset
|
850 CHECK_PARAMS( VALIDATE_SI(session) ); |
2d3a799ad29c
Cache the session pointer in answers when it was present in queries
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
258
diff
changeset
|
851 |
2d3a799ad29c
Cache the session pointer in answers when it was present in queries
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
258
diff
changeset
|
852 /* Update the msg refcount */ |
2d3a799ad29c
Cache the session pointer in answers when it was present in queries
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
258
diff
changeset
|
853 CHECK_POSIX( pthread_mutex_lock(&session->stlock) ); |
2d3a799ad29c
Cache the session pointer in answers when it was present in queries
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
258
diff
changeset
|
854 session->msg_cnt++; |
2d3a799ad29c
Cache the session pointer in answers when it was present in queries
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
258
diff
changeset
|
855 CHECK_POSIX( pthread_mutex_unlock(&session->stlock) ); |
1369
f1bbcab403a6
Clean up trailing whitespace in sessions.c
Thomas Klausner <tk@giga.or.at>
parents:
1093
diff
changeset
|
856 |
291
2d3a799ad29c
Cache the session pointer in answers when it was present in queries
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
258
diff
changeset
|
857 return 0; |
2d3a799ad29c
Cache the session pointer in answers when it was present in queries
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
258
diff
changeset
|
858 } |
2d3a799ad29c
Cache the session pointer in answers when it was present in queries
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
258
diff
changeset
|
859 |
85
e5fcd672caff
Added new function to retrieve messages sessions easily
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
860 int fd_sess_reclaim_msg ( struct session ** session ) |
e5fcd672caff
Added new function to retrieve messages sessions easily
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
861 { |
e5fcd672caff
Added new function to retrieve messages sessions easily
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
862 int reclaim; |
924
877592751fee
Fix (tentative) for invalid handling of sessions fast creation/destruction as pointed by Yusuke Okura -- http://lists.freediameter.net/pipermail/help/2013-February/000584.html and http://lists.freediameter.net/pipermail/help/2013-February/000589.html -- Thank you very much
Sebastien Decugis <sdecugis@freediameter.net>
parents:
788
diff
changeset
|
863 uint32_t hash; |
1369
f1bbcab403a6
Clean up trailing whitespace in sessions.c
Thomas Klausner <tk@giga.or.at>
parents:
1093
diff
changeset
|
864 |
85
e5fcd672caff
Added new function to retrieve messages sessions easily
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
865 TRACE_ENTRY("%p", session); |
e5fcd672caff
Added new function to retrieve messages sessions easily
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
866 CHECK_PARAMS( session && VALIDATE_SI(*session) ); |
1369
f1bbcab403a6
Clean up trailing whitespace in sessions.c
Thomas Klausner <tk@giga.or.at>
parents:
1093
diff
changeset
|
867 |
924
877592751fee
Fix (tentative) for invalid handling of sessions fast creation/destruction as pointed by Yusuke Okura -- http://lists.freediameter.net/pipermail/help/2013-February/000584.html and http://lists.freediameter.net/pipermail/help/2013-February/000589.html -- Thank you very much
Sebastien Decugis <sdecugis@freediameter.net>
parents:
788
diff
changeset
|
868 /* Lock the hash line to avoid possibility that session is freed while we are reclaiming */ |
877592751fee
Fix (tentative) for invalid handling of sessions fast creation/destruction as pointed by Yusuke Okura -- http://lists.freediameter.net/pipermail/help/2013-February/000584.html and http://lists.freediameter.net/pipermail/help/2013-February/000589.html -- Thank you very much
Sebastien Decugis <sdecugis@freediameter.net>
parents:
788
diff
changeset
|
869 hash = (*session)->hash; |
877592751fee
Fix (tentative) for invalid handling of sessions fast creation/destruction as pointed by Yusuke Okura -- http://lists.freediameter.net/pipermail/help/2013-February/000584.html and http://lists.freediameter.net/pipermail/help/2013-February/000589.html -- Thank you very much
Sebastien Decugis <sdecugis@freediameter.net>
parents:
788
diff
changeset
|
870 CHECK_POSIX( pthread_mutex_lock( H_LOCK(hash)) ); |
1369
f1bbcab403a6
Clean up trailing whitespace in sessions.c
Thomas Klausner <tk@giga.or.at>
parents:
1093
diff
changeset
|
871 pthread_cleanup_push( fd_cleanup_mutex, H_LOCK(hash) ); |
924
877592751fee
Fix (tentative) for invalid handling of sessions fast creation/destruction as pointed by Yusuke Okura -- http://lists.freediameter.net/pipermail/help/2013-February/000584.html and http://lists.freediameter.net/pipermail/help/2013-February/000589.html -- Thank you very much
Sebastien Decugis <sdecugis@freediameter.net>
parents:
788
diff
changeset
|
872 |
85
e5fcd672caff
Added new function to retrieve messages sessions easily
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
873 /* Update the msg refcount */ |
e5fcd672caff
Added new function to retrieve messages sessions easily
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
874 CHECK_POSIX( pthread_mutex_lock(&(*session)->stlock) ); |
e5fcd672caff
Added new function to retrieve messages sessions easily
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
875 reclaim = (*session)->msg_cnt; |
e5fcd672caff
Added new function to retrieve messages sessions easily
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
876 (*session)->msg_cnt = reclaim - 1; |
e5fcd672caff
Added new function to retrieve messages sessions easily
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
877 CHECK_POSIX( pthread_mutex_unlock(&(*session)->stlock) ); |
1369
f1bbcab403a6
Clean up trailing whitespace in sessions.c
Thomas Klausner <tk@giga.or.at>
parents:
1093
diff
changeset
|
878 |
924
877592751fee
Fix (tentative) for invalid handling of sessions fast creation/destruction as pointed by Yusuke Okura -- http://lists.freediameter.net/pipermail/help/2013-February/000584.html and http://lists.freediameter.net/pipermail/help/2013-February/000589.html -- Thank you very much
Sebastien Decugis <sdecugis@freediameter.net>
parents:
788
diff
changeset
|
879 /* Ok, now unlock the hash line */ |
877592751fee
Fix (tentative) for invalid handling of sessions fast creation/destruction as pointed by Yusuke Okura -- http://lists.freediameter.net/pipermail/help/2013-February/000584.html and http://lists.freediameter.net/pipermail/help/2013-February/000589.html -- Thank you very much
Sebastien Decugis <sdecugis@freediameter.net>
parents:
788
diff
changeset
|
880 pthread_cleanup_pop( 0 ); |
877592751fee
Fix (tentative) for invalid handling of sessions fast creation/destruction as pointed by Yusuke Okura -- http://lists.freediameter.net/pipermail/help/2013-February/000584.html and http://lists.freediameter.net/pipermail/help/2013-February/000589.html -- Thank you very much
Sebastien Decugis <sdecugis@freediameter.net>
parents:
788
diff
changeset
|
881 CHECK_POSIX( pthread_mutex_unlock( H_LOCK(hash) ) ); |
1369
f1bbcab403a6
Clean up trailing whitespace in sessions.c
Thomas Klausner <tk@giga.or.at>
parents:
1093
diff
changeset
|
882 |
924
877592751fee
Fix (tentative) for invalid handling of sessions fast creation/destruction as pointed by Yusuke Okura -- http://lists.freediameter.net/pipermail/help/2013-February/000584.html and http://lists.freediameter.net/pipermail/help/2013-February/000589.html -- Thank you very much
Sebastien Decugis <sdecugis@freediameter.net>
parents:
788
diff
changeset
|
883 /* and reclaim if no message references the session anymore */ |
85
e5fcd672caff
Added new function to retrieve messages sessions easily
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
884 if (reclaim == 1) { |
e5fcd672caff
Added new function to retrieve messages sessions easily
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
885 CHECK_FCT(fd_sess_reclaim ( session )); |
e5fcd672caff
Added new function to retrieve messages sessions easily
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
886 } else { |
e5fcd672caff
Added new function to retrieve messages sessions easily
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
887 *session = NULL; |
e5fcd672caff
Added new function to retrieve messages sessions easily
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
888 } |
e5fcd672caff
Added new function to retrieve messages sessions easily
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
889 return 0; |
e5fcd672caff
Added new function to retrieve messages sessions easily
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
890 } |
e5fcd672caff
Added new function to retrieve messages sessions easily
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
891 |
e5fcd672caff
Added new function to retrieve messages sessions easily
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
892 |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
893 |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
894 /* Dump functions */ |
1085
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1027
diff
changeset
|
895 DECLARE_FD_DUMP_PROTOTYPE(fd_sess_dump, struct session * session, int with_states) |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
896 { |
1093
44f3e48dfe27
Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1088
diff
changeset
|
897 FD_DUMP_HANDLE_OFFSET(); |
1369
f1bbcab403a6
Clean up trailing whitespace in sessions.c
Thomas Klausner <tk@giga.or.at>
parents:
1093
diff
changeset
|
898 |
1085
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1027
diff
changeset
|
899 CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, "{session}(@%p): ", session), return NULL); |
1369
f1bbcab403a6
Clean up trailing whitespace in sessions.c
Thomas Klausner <tk@giga.or.at>
parents:
1093
diff
changeset
|
900 |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
901 if (!VALIDATE_SI(session)) { |
1093
44f3e48dfe27
Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1088
diff
changeset
|
902 CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, "INVALID/NULL"), return NULL); |
5
c2d2729e3603
Completed new session module tests; some bugs fixed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
4
diff
changeset
|
903 } else { |
1085
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1027
diff
changeset
|
904 char timebuf[30]; |
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1027
diff
changeset
|
905 struct tm tm; |
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1027
diff
changeset
|
906 |
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1027
diff
changeset
|
907 strftime(timebuf, sizeof(timebuf), "%D,%T", localtime_r( &session->timeout.tv_sec , &tm )); |
1093
44f3e48dfe27
Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1088
diff
changeset
|
908 CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, "'%s'(%zd) h:%x m:%d d:%d to:%s.%06ld", |
1085
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1027
diff
changeset
|
909 session->sid, session->sidlen, session->hash, session->msg_cnt, session->is_destroyed, |
1369
f1bbcab403a6
Clean up trailing whitespace in sessions.c
Thomas Klausner <tk@giga.or.at>
parents:
1093
diff
changeset
|
910 timebuf, session->timeout.tv_nsec/1000), |
1085
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1027
diff
changeset
|
911 return NULL); |
1369
f1bbcab403a6
Clean up trailing whitespace in sessions.c
Thomas Klausner <tk@giga.or.at>
parents:
1093
diff
changeset
|
912 |
1085
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1027
diff
changeset
|
913 if (with_states) { |
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1027
diff
changeset
|
914 struct fd_list * li; |
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1027
diff
changeset
|
915 CHECK_POSIX_DO( pthread_mutex_lock(&session->stlock), /* ignore */ ); |
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1027
diff
changeset
|
916 pthread_cleanup_push( fd_cleanup_mutex, &session->stlock ); |
1369
f1bbcab403a6
Clean up trailing whitespace in sessions.c
Thomas Klausner <tk@giga.or.at>
parents:
1093
diff
changeset
|
917 |
1085
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1027
diff
changeset
|
918 for (li = session->states.next; li != &session->states; li = li->next) { |
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1027
diff
changeset
|
919 struct state * st = (struct state *)(li->o); |
1093
44f3e48dfe27
Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1088
diff
changeset
|
920 CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, "\n {state i:%d}(@%p): ", st->hdl->id, st), return NULL); |
1085
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1027
diff
changeset
|
921 if (st->hdl->state_dump) { |
1369
f1bbcab403a6
Clean up trailing whitespace in sessions.c
Thomas Klausner <tk@giga.or.at>
parents:
1093
diff
changeset
|
922 CHECK_MALLOC_DO( (*st->hdl->state_dump)( FD_DUMP_STD_PARAMS, st->state), |
1093
44f3e48dfe27
Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1088
diff
changeset
|
923 fd_dump_extend( FD_DUMP_STD_PARAMS, "[dumper error]")); |
1085
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1027
diff
changeset
|
924 } else { |
1093
44f3e48dfe27
Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1088
diff
changeset
|
925 CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, "<%p>", st->state), return NULL); |
1085
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1027
diff
changeset
|
926 } |
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1027
diff
changeset
|
927 } |
1369
f1bbcab403a6
Clean up trailing whitespace in sessions.c
Thomas Klausner <tk@giga.or.at>
parents:
1093
diff
changeset
|
928 |
1085
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1027
diff
changeset
|
929 pthread_cleanup_pop(0); |
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1027
diff
changeset
|
930 CHECK_POSIX_DO( pthread_mutex_unlock(&session->stlock), /* ignore */ ); |
5
c2d2729e3603
Completed new session module tests; some bugs fixed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
4
diff
changeset
|
931 } |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
932 } |
1369
f1bbcab403a6
Clean up trailing whitespace in sessions.c
Thomas Klausner <tk@giga.or.at>
parents:
1093
diff
changeset
|
933 |
1085
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1027
diff
changeset
|
934 return *buf; |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
935 } |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
936 |
1085
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1027
diff
changeset
|
937 DECLARE_FD_DUMP_PROTOTYPE(fd_sess_dump_hdl, struct session_handler * handler) |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
938 { |
1093
44f3e48dfe27
Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1088
diff
changeset
|
939 FD_DUMP_HANDLE_OFFSET(); |
1369
f1bbcab403a6
Clean up trailing whitespace in sessions.c
Thomas Klausner <tk@giga.or.at>
parents:
1093
diff
changeset
|
940 |
1085
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1027
diff
changeset
|
941 CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, "{sesshdl}(@%p): ", handler), return NULL); |
1369
f1bbcab403a6
Clean up trailing whitespace in sessions.c
Thomas Klausner <tk@giga.or.at>
parents:
1093
diff
changeset
|
942 |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
943 if (!VALIDATE_SH(handler)) { |
1093
44f3e48dfe27
Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1088
diff
changeset
|
944 CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, "INVALID/NULL"), return NULL); |
5
c2d2729e3603
Completed new session module tests; some bugs fixed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
4
diff
changeset
|
945 } else { |
1093
44f3e48dfe27
Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1088
diff
changeset
|
946 CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, "i:%d cl:%p d:%p o:%p", handler->id, handler->cleanup, handler->state_dump, handler->opaque), return NULL); |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
947 } |
1085
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1027
diff
changeset
|
948 return *buf; |
1369
f1bbcab403a6
Clean up trailing whitespace in sessions.c
Thomas Klausner <tk@giga.or.at>
parents:
1093
diff
changeset
|
949 } |
778
003df4a9ade2
Added two new interfaces on Zach requests http://lists.freediameter.net/pipermail/help/2012-January/000312.html and http://lists.freediameter.net/pipermail/help/2012-January/000311.html
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
950 |
003df4a9ade2
Added two new interfaces on Zach requests http://lists.freediameter.net/pipermail/help/2012-January/000312.html and http://lists.freediameter.net/pipermail/help/2012-January/000311.html
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
951 int fd_sess_getcount(uint32_t *cnt) |
003df4a9ade2
Added two new interfaces on Zach requests http://lists.freediameter.net/pipermail/help/2012-January/000312.html and http://lists.freediameter.net/pipermail/help/2012-January/000311.html
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
952 { |
003df4a9ade2
Added two new interfaces on Zach requests http://lists.freediameter.net/pipermail/help/2012-January/000312.html and http://lists.freediameter.net/pipermail/help/2012-January/000311.html
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
953 CHECK_PARAMS(cnt); |
003df4a9ade2
Added two new interfaces on Zach requests http://lists.freediameter.net/pipermail/help/2012-January/000312.html and http://lists.freediameter.net/pipermail/help/2012-January/000311.html
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
954 CHECK_POSIX( pthread_mutex_lock( &exp_lock ) ); |
003df4a9ade2
Added two new interfaces on Zach requests http://lists.freediameter.net/pipermail/help/2012-January/000312.html and http://lists.freediameter.net/pipermail/help/2012-January/000311.html
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
955 *cnt = sess_cnt; |
003df4a9ade2
Added two new interfaces on Zach requests http://lists.freediameter.net/pipermail/help/2012-January/000312.html and http://lists.freediameter.net/pipermail/help/2012-January/000311.html
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
956 CHECK_POSIX( pthread_mutex_unlock( &exp_lock ) ); |
003df4a9ade2
Added two new interfaces on Zach requests http://lists.freediameter.net/pipermail/help/2012-January/000312.html and http://lists.freediameter.net/pipermail/help/2012-January/000311.html
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
957 return 0; |
003df4a9ade2
Added two new interfaces on Zach requests http://lists.freediameter.net/pipermail/help/2012-January/000312.html and http://lists.freediameter.net/pipermail/help/2012-January/000311.html
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
958 } |