Mercurial > hg > freeDiameter
annotate libfdproto/sessions.c @ 706:4ffbc9f1e922
Large UNTESTED commit with the following changes:
* Improved DiameterIdentity handling (esp. interationalization issues),
and improve efficiency of some string operations in peers, sessions,
and dictionary modules (closes #7)
* Cleanup in the session module to free only unreferenced sessions (#16)
* Removed fd_cpu_flush_cache(), replaced by more robust alternatives.
* Improved peer state machine algorithm to counter SCTP multistream race
condition.
author | Sebastien Decugis <sdecugis@nict.go.jp> |
---|---|
date | Wed, 09 Feb 2011 15:26:58 +0900 |
parents | 78b665400097 |
children | 4a9f08d6b6ba |
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) * |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
3 * Author: Sebastien Decugis <sdecugis@nict.go.jp> * |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
4 * * |
662
2e94ef0515d7
Updated copyright information
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
658
diff
changeset
|
5 * Copyright (c) 2011, 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. |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
37 * |
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 */ |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
71 void (*cleanup)(session_state *, os0_t, void *); /* The cleanup function to be called for cleaning a 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
|
72 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
|
73 }; |
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 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
|
76 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
|
77 |
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 /* 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
|
80 struct state { |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
81 int eyec; /* Must be SD_EYEC */ |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
82 session_state *state; /* The state registered by the application, never NULL (or the whole object is deleted) */ |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
83 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
|
84 union { |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
85 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
|
86 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
|
87 }; |
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 /* 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
|
91 struct session { |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
92 int eyec; /* Eyecatcher, SI_EYEC */ |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
93 |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
94 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
|
95 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
|
96 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
|
97 struct fd_list chain_h;/* chaining in the hash table of sessions. */ |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
98 |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
99 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
|
100 struct fd_list expire; /* List of expiring sessions, ordered by timeouts. */ |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
101 |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
102 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
|
103 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
|
104 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
|
105 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
|
106 }; |
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 /* 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
|
109 static struct { |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
110 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
|
111 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
|
112 } sess_hash [ 1 << SESS_HASH_SIZE ] ; |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
113 #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
|
114 #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
|
115 #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
|
116 |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
117 /* 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
|
118 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
|
119 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
|
120 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
|
121 |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
122 /* Expiring sessions management */ |
14
14cf6daf716d
Some progress on peers module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
7
diff
changeset
|
123 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
|
124 static pthread_mutex_t exp_lock = PTHREAD_MUTEX_INITIALIZER; /* lock protecting the list. */ |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
125 static pthread_cond_t exp_cond = PTHREAD_COND_INITIALIZER; /* condvar used by the expiry mecahinsm. */ |
686
f83d9878bf66
Fixed in case of termination of several modules (before initialization completed)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
126 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
|
127 |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
128 /* 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
|
129 * hash lock > state lock > expiry lock |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
130 * 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
|
131 * 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
|
132 */ |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
133 |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
134 /********************************************************************************************************/ |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
135 |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
136 /* 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
|
137 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
|
138 { |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
139 struct session * sess; |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
140 |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
141 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
|
142 CHECK_PARAMS_DO( sid && sidlen, return NULL ); |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
143 |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
144 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
|
145 memset(sess, 0, sizeof(struct session)); |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
146 |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
147 sess->eyec = SI_EYEC; |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
148 |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
149 sess->sid = sid; |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
150 sess->sidlen = sidlen; |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
151 sess->hash = hash; |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
152 fd_list_init(&sess->chain_h, sess); |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
153 |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
154 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
|
155 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
|
156 fd_list_init(&sess->expire, sess); |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
157 |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
158 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
|
159 fd_list_init(&sess->states, sess); |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
160 |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
161 return sess; |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
162 } |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
163 |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
164 /* 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
|
165 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
|
166 { |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
167 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
|
168 free(s->sid); |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
169 fd_list_unlink(&s->chain_h); |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
170 fd_list_unlink(&s->expire); |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
171 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
|
172 free(s); |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
173 } |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
174 |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
175 /* The expiry thread */ |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
176 static void * exp_fct(void * arg) |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
177 { |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
178 fd_log_threadname ( "Session/expire" ); |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
179 TRACE_ENTRY( "" ); |
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 |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
182 do { |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
183 struct timespec now; |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
184 struct session * first; |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
185 |
203
536b1dde8761
Some cleanups in the cnxctx module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
136
diff
changeset
|
186 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
|
187 pthread_cleanup_push( fd_cleanup_mutex, &exp_lock ); |
536b1dde8761
Some cleanups in the cnxctx module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
136
diff
changeset
|
188 again: |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
189 /* 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
|
190 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
|
191 /* 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
|
192 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
|
193 /* Restart the loop on wakeup */ |
203
536b1dde8761
Some cleanups in the cnxctx module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
136
diff
changeset
|
194 goto again; |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
195 } |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
196 |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
197 /* 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
|
198 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
|
199 ASSERT( VALIDATE_SI(first) ); |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
200 |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
201 /* Get the current time */ |
203
536b1dde8761
Some cleanups in the cnxctx module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
136
diff
changeset
|
202 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
|
203 |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
204 /* 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
|
205 if ( TS_IS_INFERIOR( &now, &first->timeout ) ) { |
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 CHECK_POSIX_DO2( pthread_cond_timedwait( &exp_cond, &exp_lock, &first->timeout ), |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
208 ETIMEDOUT, /* ETIMEDOUT is a normal error, continue */, |
203
536b1dde8761
Some cleanups in the cnxctx module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
136
diff
changeset
|
209 /* on other error, */ break ); |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
210 |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
211 /* on wakeup, loop */ |
203
536b1dde8761
Some cleanups in the cnxctx module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
136
diff
changeset
|
212 goto again; |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
213 } |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
214 |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
215 /* 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
|
216 pthread_cleanup_pop( 0 ); |
536b1dde8761
Some cleanups in the cnxctx module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
136
diff
changeset
|
217 CHECK_POSIX_DO( pthread_mutex_unlock(&exp_lock), break ); |
536b1dde8761
Some cleanups in the cnxctx module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
136
diff
changeset
|
218 |
536b1dde8761
Some cleanups in the cnxctx module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
136
diff
changeset
|
219 CHECK_FCT_DO( fd_sess_destroy( &first ), break ); |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
220 |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
221 } while (1); |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
222 |
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
|
223 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
|
224 ASSERT(0); |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
225 return NULL; |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
226 } |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
227 |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
228 |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
229 |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
230 /********************************************************************************************************/ |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
231 |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
232 /* Initialize the session module */ |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
233 int fd_sess_init(void) |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
234 { |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
235 int i; |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
236 |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
237 TRACE_ENTRY( "" ); |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
238 |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
239 /* Initialize the global counters */ |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
240 sid_h = (uint32_t) time(NULL); |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
241 sid_l = 0; |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
242 |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
243 /* Initialize the hash table */ |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
244 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
|
245 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
|
246 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
|
247 } |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
248 |
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
|
249 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
|
250 } |
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
|
251 |
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
|
252 /* 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
|
253 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
|
254 { |
14
14cf6daf716d
Some progress on peers module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
7
diff
changeset
|
255 /* Start session garbage collector (expiry) */ |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
256 CHECK_POSIX( pthread_create(&exp_thr, NULL, exp_fct, NULL) ); |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
257 |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
258 return 0; |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
259 } |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
260 |
235
8773740401a5
Centralized signal handlers management in the library
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
203
diff
changeset
|
261 /* Terminate */ |
8773740401a5
Centralized signal handlers management in the library
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
203
diff
changeset
|
262 void fd_sess_fini(void) |
8773740401a5
Centralized signal handlers management in the library
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
203
diff
changeset
|
263 { |
8773740401a5
Centralized signal handlers management in the library
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
203
diff
changeset
|
264 TRACE_ENTRY(""); |
8773740401a5
Centralized signal handlers management in the library
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
203
diff
changeset
|
265 CHECK_FCT_DO( fd_thr_term(&exp_thr), /* continue */ ); |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
266 |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
267 /* Destroy all sessions in the hash table, and the hash table itself? -- How to do it without a race condition ? */ |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
268 |
235
8773740401a5
Centralized signal handlers management in the library
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
203
diff
changeset
|
269 return; |
8773740401a5
Centralized signal handlers management in the library
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
203
diff
changeset
|
270 } |
8773740401a5
Centralized signal handlers management in the library
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
203
diff
changeset
|
271 |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
272 /* Create a new handler */ |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
273 int fd_sess_handler_create_internal ( struct session_handler ** handler, void (*cleanup)(session_state *, os0_t, void *), void * opaque ) |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
274 { |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
275 struct session_handler *new; |
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 TRACE_ENTRY("%p %p", handler, cleanup); |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
278 |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
279 CHECK_PARAMS( handler && cleanup ); |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
280 |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
281 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
|
282 memset(new, 0, sizeof(struct session_handler)); |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
283 |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
284 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
|
285 new->id = ++hdl_id; |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
286 CHECK_POSIX( pthread_mutex_unlock(&hdl_lock) ); |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
287 |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
288 new->eyec = SH_EYEC; |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
289 new->cleanup = cleanup; |
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
|
290 new->opaque = 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 *handler = new; |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
293 return 0; |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
294 } |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
295 |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
296 /* 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. |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
297 * 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
|
298 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
|
299 { |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
300 struct session_handler * del; |
14
14cf6daf716d
Some progress on peers module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
7
diff
changeset
|
301 /* 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
|
302 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
|
303 int i; |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
304 |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
305 TRACE_ENTRY("%p", handler); |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
306 CHECK_PARAMS( handler && VALIDATE_SH(*handler) ); |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
307 |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
308 del = *handler; |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
309 *handler = NULL; |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
310 |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
311 del->eyec = 0xdead; /* The handler is not valid anymore for any other operation */ |
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 /* 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
|
314 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
|
315 struct fd_list * li_si; |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
316 CHECK_POSIX( pthread_mutex_lock(&sess_hash[i].lock) ); |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
317 |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
318 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
|
319 struct fd_list * li_st; |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
320 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
|
321 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
|
322 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
|
323 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
|
324 /* The list is ordered */ |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
325 if (st->hdl->id < del->id) |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
326 continue; |
5
c2d2729e3603
Completed new session module tests; some bugs fixed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
4
diff
changeset
|
327 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
|
328 /* 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
|
329 fd_list_unlink(&st->chain); |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
330 st->sid = sess->sid; |
5
c2d2729e3603
Completed new session module tests; some bugs fixed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
4
diff
changeset
|
331 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
|
332 } |
c2d2729e3603
Completed new session module tests; some bugs fixed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
4
diff
changeset
|
333 break; |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
334 } |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
335 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
|
336 } |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
337 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
|
338 } |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
339 |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
340 /* 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
|
341 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
|
342 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
|
343 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
|
344 (*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
|
345 fd_list_unlink(&st->chain); |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
346 free(st); |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
347 } |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
348 |
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
|
349 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
|
350 *opaque = del->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
|
351 |
452
2b36eccbe426
Free unfreed memory
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
403
diff
changeset
|
352 /* Free the handler */ |
2b36eccbe426
Free unfreed memory
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
403
diff
changeset
|
353 free(del); |
2b36eccbe426
Free unfreed memory
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
403
diff
changeset
|
354 |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
355 return 0; |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
356 } |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
357 |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
358 |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
359 |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
360 /* Create a new session object with the default timeout value, and link it */ |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
361 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
|
362 { |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
363 os0_t sid = NULL; |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
364 size_t sidlen; |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
365 uint32_t hash; |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
366 struct session * sess; |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
367 struct fd_list * li; |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
368 int found = 0; |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
369 int ret = 0; |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
370 |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
371 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
|
372 CHECK_PARAMS( session && (diamid || opt) ); |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
373 |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
374 if (diamid) { |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
375 if (!diamidlen) { |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
376 diamidlen = strlen(diamid); |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
377 } |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
378 /* 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
|
379 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
|
380 } else { |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
381 diamidlen = 0; |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
382 } |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
383 if (opt) { |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
384 if (!optlen) { |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
385 optlen = strlen((char *)opt); |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
386 } else { |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
387 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
|
388 } |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
389 } else { |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
390 optlen = 0; |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
391 } |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
392 |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
393 /* 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
|
394 if (diamid == NULL) { |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
395 /* opt is the full string */ |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
396 CHECK_MALLOC( sid = os0dup(opt, optlen) ); |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
397 sidlen = optlen; |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
398 } else { |
203
536b1dde8761
Some cleanups in the cnxctx module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
136
diff
changeset
|
399 uint32_t sid_h_cpy; |
536b1dde8761
Some cleanups in the cnxctx module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
136
diff
changeset
|
400 uint32_t sid_l_cpy; |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
401 /* "<diamId>;<high32>;<low32>[;opt]" */ |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
402 sidlen = diamidlen; |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
403 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
|
404 if (opt) |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
405 sidlen += 1 + optlen; /* ';opt' */ |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
406 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
|
407 CHECK_MALLOC( sid = malloc(sidlen) ); |
203
536b1dde8761
Some cleanups in the cnxctx module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
136
diff
changeset
|
408 |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
409 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
|
410 if ( ++sid_l == 0 ) /* overflow */ |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
411 ++sid_h; |
203
536b1dde8761
Some cleanups in the cnxctx module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
136
diff
changeset
|
412 sid_h_cpy = sid_h; |
536b1dde8761
Some cleanups in the cnxctx module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
136
diff
changeset
|
413 sid_l_cpy = sid_l; |
536b1dde8761
Some cleanups in the cnxctx module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
136
diff
changeset
|
414 CHECK_POSIX( pthread_mutex_unlock(&sid_lock) ); |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
415 |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
416 if (opt) { |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
417 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
|
418 } else { |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
419 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
|
420 } |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
421 } |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
422 |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
423 hash = fd_os_hash(sid, sidlen); |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
424 |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
425 /* 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
|
426 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
|
427 pthread_cleanup_push( fd_cleanup_mutex, H_LOCK(hash) ); |
203
536b1dde8761
Some cleanups in the cnxctx module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
136
diff
changeset
|
428 |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
429 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
|
430 int cmp; |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
431 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
|
432 |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
433 /* 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
|
434 if (s->hash < hash) |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
435 continue; |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
436 if (s->hash > hash) |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
437 break; |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
438 |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
439 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
|
440 if (cmp < 0) |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
441 continue; |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
442 if (cmp > 0) |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
443 break; |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
444 |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
445 /* 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
|
446 found = 1; |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
447 *session = s; |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
448 break; |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
449 } |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
450 |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
451 /* 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
|
452 if (!found) { |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
453 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
|
454 { |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
455 ret = ENOMEM; |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
456 goto out; |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
457 } ); |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
458 |
5
c2d2729e3603
Completed new session module tests; some bugs fixed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
4
diff
changeset
|
459 fd_list_insert_before(li, &sess->chain_h); /* hash table */ |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
460 } else { |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
461 /* 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
|
462 if ((*session)->is_destroyed == 0) { |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
463 ret = EALREADY; |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
464 goto out; |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
465 } else { |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
466 /* 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
|
467 TODO("Re-creating a deleted session. Should investigate if this can lead to an issue... (need more feedback)"); |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
468 sess = *session; |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
469 |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
470 /* update the expiry time */ |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
471 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
|
472 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
|
473 } |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
474 } |
14
14cf6daf716d
Some progress on peers module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
7
diff
changeset
|
475 |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
476 /* 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
|
477 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
|
478 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
|
479 |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
480 /* 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
|
481 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
|
482 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
|
483 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
|
484 break; |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
485 } |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
486 fd_list_insert_after( li, &sess->expire ); |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
487 |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
488 /* 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
|
489 if (li == &exp_sentinel) { |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
490 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
|
491 } |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
492 |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
493 /* 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
|
494 pthread_cleanup_pop(0); |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
495 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
|
496 |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
497 out: |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
498 ; |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
499 pthread_cleanup_pop(0); |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
500 CHECK_POSIX( pthread_mutex_unlock( H_LOCK(hash) ) ); |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
501 |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
502 if (ret) /* in case of error */ |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
503 return ret; |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
504 |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
505 *session = sess; |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
506 return 0; |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
507 } |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
508 |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
509 /* Find or create a session */ |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
510 int fd_sess_fromsid ( 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
|
511 { |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
512 int ret; |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
513 |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
514 TRACE_ENTRY("%p %d %p %p", sid, len, session, new); |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
515 CHECK_PARAMS( sid && session ); |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
516 |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
517 if (!fd_os_is_valid_os0(sid,len)) { |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
518 TRACE_DEBUG(INFO, "Warning: a Session-Id value contains \\0 chars... (len:%zd, begin:'%.*s')\n => Debug messages may be truncated.", len, len, sid); |
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 |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
521 /* 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
|
522 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
|
523 switch (ret) { |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
524 case 0: |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
525 case EALREADY: |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
526 break; |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
527 |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
528 default: |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
529 CHECK_FCT(ret); |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
530 } |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
531 |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
532 if (new) |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
533 *new = ret ? 0 : 1; |
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 return 0; |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
536 } |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
537 |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
538 /* 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
|
539 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
|
540 { |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
541 TRACE_ENTRY("%p %p", session, sid); |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
542 |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
543 CHECK_PARAMS( VALIDATE_SI(session) && sid ); |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
544 |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
545 *sid = session->sid; |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
546 if (sidlen) |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
547 *sidlen = session->sidlen; |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
548 |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
549 return 0; |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
550 } |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
551 |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
552 /* 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
|
553 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
|
554 { |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
555 struct fd_list * li; |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
556 |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
557 TRACE_ENTRY("%p %p", session, timeout); |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
558 CHECK_PARAMS( VALIDATE_SI(session) && timeout ); |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
559 |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
560 /* 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
|
561 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
|
562 pthread_cleanup_push( fd_cleanup_mutex, &exp_lock ); |
3
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 /* Update the timeout */ |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
565 fd_list_unlink(&session->expire); |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
566 memcpy(&session->timeout, timeout, sizeof(struct timespec)); |
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 /* 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
|
569 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
|
570 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
|
571 |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
572 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
|
573 continue; |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
574 |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
575 break; |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
576 } |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
577 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
|
578 |
14
14cf6daf716d
Some progress on peers module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
7
diff
changeset
|
579 /* 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
|
580 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
|
581 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
|
582 } |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
583 |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
584 /* We're done */ |
203
536b1dde8761
Some cleanups in the cnxctx module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
136
diff
changeset
|
585 pthread_cleanup_pop(0); |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
586 CHECK_POSIX( pthread_mutex_unlock( &exp_lock ) ); |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
587 |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
588 return 0; |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
589 } |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
590 |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
591 /* 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
|
592 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
|
593 { |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
594 struct session * sess; |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
595 int destroy_now; |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
596 os0_t sid; |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
597 int ret = 0; |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
598 |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
599 /* 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
|
600 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
|
601 |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
602 TRACE_ENTRY("%p", session); |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
603 CHECK_PARAMS( session && VALIDATE_SI(*session) ); |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
604 |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
605 sess = *session; |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
606 *session = NULL; |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
607 |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
608 /* 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
|
609 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
|
610 pthread_cleanup_push( fd_cleanup_mutex, H_LOCK(sess->hash) ); |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
611 |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
612 /* 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
|
613 CHECK_POSIX_DO( pthread_mutex_lock( &exp_lock ), { ASSERT(0); /* otherwise cleanup handler is not pop'd */ } ); |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
614 fd_list_unlink( &sess->expire ); /* no need to signal the condition here */ |
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
|
615 CHECK_POSIX_DO( pthread_mutex_unlock( &exp_lock ), { ASSERT(0); /* otherwise cleanup handler is not pop'd */ } ); |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
616 |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
617 /* 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
|
618 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
|
619 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
|
620 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
|
621 fd_list_unlink(&st->chain); |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
622 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
|
623 } |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
624 CHECK_POSIX_DO( pthread_mutex_unlock( &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
|
625 |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
626 /* Mark the session as destroyed */ |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
627 destroy_now = (sess->msg_cnt == 0); |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
628 if (destroy_now) { |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
629 fd_list_unlink( &sess->chain_h ); |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
630 sid = sess->sid; |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
631 } else { |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
632 sess->is_destroyed = 1; |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
633 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
|
634 } |
203
536b1dde8761
Some cleanups in the cnxctx module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
136
diff
changeset
|
635 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
|
636 CHECK_POSIX( pthread_mutex_unlock( H_LOCK(sess->hash) ) ); |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
637 |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
638 if (ret) |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
639 return ret; |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
640 |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
641 /* Now, really delete the states */ |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
642 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
|
643 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
|
644 fd_list_unlink(&st->chain); |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
645 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
|
646 (*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
|
647 free(st); |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
648 } |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
649 |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
650 /* 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
|
651 if (destroy_now) { |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
652 del_session(sess); |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
653 } else { |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
654 free(sid); |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
655 } |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
656 |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
657 return 0; |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
658 } |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
659 |
6
b0d377c79d80
Progress on dispatch API spec; added fd_sess_reclaim function and test
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
5
diff
changeset
|
660 /* 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
|
661 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
|
662 { |
b0d377c79d80
Progress on dispatch API spec; added fd_sess_reclaim function and test
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
5
diff
changeset
|
663 struct session * sess; |
293
ec67c5096eeb
Fix small issue with access to freed memory
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
291
diff
changeset
|
664 uint32_t hash; |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
665 int destroy_now = 0; |
6
b0d377c79d80
Progress on dispatch API spec; added fd_sess_reclaim function and test
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
5
diff
changeset
|
666 |
b0d377c79d80
Progress on dispatch API spec; added fd_sess_reclaim function and test
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
5
diff
changeset
|
667 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
|
668 CHECK_PARAMS( session && VALIDATE_SI(*session) ); |
b0d377c79d80
Progress on dispatch API spec; added fd_sess_reclaim function and test
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
5
diff
changeset
|
669 |
b0d377c79d80
Progress on dispatch API spec; added fd_sess_reclaim function and test
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
5
diff
changeset
|
670 sess = *session; |
293
ec67c5096eeb
Fix small issue with access to freed memory
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
291
diff
changeset
|
671 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
|
672 *session = NULL; |
b0d377c79d80
Progress on dispatch API spec; added fd_sess_reclaim function and test
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
5
diff
changeset
|
673 |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
674 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
|
675 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
|
676 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
|
677 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
|
678 CHECK_POSIX_DO( pthread_mutex_lock( &exp_lock ), { ASSERT(0); /* otherwise, cleanup not poped on FreeBSD */ } ); |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
679 |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
680 /* 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
|
681 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
|
682 /* 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
|
683 fd_list_unlink( &sess->expire ); |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
684 destroy_now = (sess->msg_cnt == 0); |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
685 if (destroy_now) { |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
686 fd_list_unlink(&sess->chain_h); |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
687 } else { |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
688 /* 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
|
689 sess->is_destroyed = 1; |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
690 } |
6
b0d377c79d80
Progress on dispatch API spec; added fd_sess_reclaim function and test
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
5
diff
changeset
|
691 } |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
692 |
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
|
693 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
|
694 pthread_cleanup_pop(0); |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
695 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
|
696 pthread_cleanup_pop(0); |
293
ec67c5096eeb
Fix small issue with access to freed memory
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
291
diff
changeset
|
697 CHECK_POSIX( pthread_mutex_unlock( H_LOCK(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
|
698 |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
699 if (destroy_now) |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
700 del_session(sess); |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
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 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
|
703 } |
b0d377c79d80
Progress on dispatch API spec; added fd_sess_reclaim function and test
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
5
diff
changeset
|
704 |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
705 /* Save a state information with a session */ |
6
b0d377c79d80
Progress on dispatch API spec; added fd_sess_reclaim function and test
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
5
diff
changeset
|
706 int fd_sess_state_store_internal ( struct session_handler * handler, struct session * session, session_state ** state ) |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
707 { |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
708 struct state *new; |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
709 struct fd_list * li; |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
710 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
|
711 int ret = 0; |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
712 |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
713 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
|
714 CHECK_PARAMS( handler && VALIDATE_SH(handler) && session && VALIDATE_SI(session) && (!session->is_destroyed) && state ); |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
715 |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
716 /* Lock the session state list */ |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
717 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
|
718 pthread_cleanup_push( fd_cleanup_mutex, &session->stlock ); |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
719 |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
720 /* 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
|
721 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
|
722 memset(new, 0, sizeof(struct state)); |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
723 |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
724 new->eyec = SD_EYEC; |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
725 new->state= *state; |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
726 fd_list_init(&new->chain, new); |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
727 new->hdl = handler; |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
728 |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
729 /* 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
|
730 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
|
731 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
|
732 /* 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
|
733 if (st->hdl->id < handler->id) |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
734 continue; |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
735 |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
736 if (st->hdl->id == handler->id) { |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
737 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
|
738 already = EALREADY; |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
739 } |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
740 |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
741 break; |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
742 } |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
743 |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
744 if (!already) { |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
745 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
|
746 *state = NULL; |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
747 } else { |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
748 free(new); |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
749 } |
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
|
750 out: |
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
|
751 ; |
203
536b1dde8761
Some cleanups in the cnxctx module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
136
diff
changeset
|
752 pthread_cleanup_pop(0); |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
753 CHECK_POSIX( pthread_mutex_unlock(&session->stlock) ); |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
754 |
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 return ret ?: already; |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
756 } |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
757 |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
758 /* Get the data back */ |
6
b0d377c79d80
Progress on dispatch API spec; added fd_sess_reclaim function and test
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
5
diff
changeset
|
759 int fd_sess_state_retrieve_internal ( struct session_handler * handler, struct session * session, session_state ** state ) |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
760 { |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
761 struct fd_list * li; |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
762 struct state * st = NULL; |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
763 |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
764 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
|
765 CHECK_PARAMS( handler && VALIDATE_SH(handler) && session && VALIDATE_SI(session) && state ); |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
766 |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
767 *state = NULL; |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
768 |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
769 /* Lock the session state list */ |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
770 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
|
771 pthread_cleanup_push( fd_cleanup_mutex, &session->stlock ); |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
772 |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
773 /* find the state in the list */ |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
774 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
|
775 st = (struct state *)(li->o); |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
776 |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
777 /* 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
|
778 if (st->hdl->id > handler->id) |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
779 break; |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
780 } |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
781 |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
782 /* If we found the state */ |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
783 if (st && (st->hdl == handler)) { |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
784 fd_list_unlink(&st->chain); |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
785 *state = st->state; |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
786 free(st); |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
787 } |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
788 |
203
536b1dde8761
Some cleanups in the cnxctx module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
136
diff
changeset
|
789 pthread_cleanup_pop(0); |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
790 CHECK_POSIX( pthread_mutex_unlock(&session->stlock) ); |
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 return 0; |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
793 } |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
794 |
85
e5fcd672caff
Added new function to retrieve messages sessions easily
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
795 /* For the messages module */ |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
796 int fd_sess_fromsid_msg ( 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
|
797 { |
e5fcd672caff
Added new function to retrieve messages sessions easily
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
798 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
|
799 CHECK_PARAMS( sid && len && session ); |
85
e5fcd672caff
Added new function to retrieve messages sessions easily
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
800 |
e5fcd672caff
Added new function to retrieve messages sessions easily
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
801 /* Get the session object */ |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
802 CHECK_FCT( fd_sess_fromsid ( sid, len, session, new) ); |
85
e5fcd672caff
Added new function to retrieve messages sessions easily
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
803 |
291
2d3a799ad29c
Cache the session pointer in answers when it was present in queries
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
258
diff
changeset
|
804 /* Increase count */ |
2d3a799ad29c
Cache the session pointer in answers when it was present in queries
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
258
diff
changeset
|
805 CHECK_FCT( fd_sess_ref_msg ( *session ) ); |
85
e5fcd672caff
Added new function to retrieve messages sessions easily
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
806 |
e5fcd672caff
Added new function to retrieve messages sessions easily
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
807 /* Done */ |
e5fcd672caff
Added new function to retrieve messages sessions easily
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
808 return 0; |
e5fcd672caff
Added new function to retrieve messages sessions easily
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
809 } |
e5fcd672caff
Added new function to retrieve messages sessions easily
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
810 |
291
2d3a799ad29c
Cache the session pointer in answers when it was present in queries
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
258
diff
changeset
|
811 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
|
812 { |
2d3a799ad29c
Cache the session pointer in answers when it was present in queries
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
258
diff
changeset
|
813 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
|
814 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
|
815 |
2d3a799ad29c
Cache the session pointer in answers when it was present in queries
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
258
diff
changeset
|
816 /* 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
|
817 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
|
818 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
|
819 CHECK_POSIX( pthread_mutex_unlock(&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
|
820 |
2d3a799ad29c
Cache the session pointer in answers when it was present in queries
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
258
diff
changeset
|
821 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
|
822 } |
2d3a799ad29c
Cache the session pointer in answers when it was present in queries
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
258
diff
changeset
|
823 |
85
e5fcd672caff
Added new function to retrieve messages sessions easily
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
824 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
|
825 { |
e5fcd672caff
Added new function to retrieve messages sessions easily
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
826 int reclaim; |
e5fcd672caff
Added new function to retrieve messages sessions easily
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
827 |
e5fcd672caff
Added new function to retrieve messages sessions easily
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
828 TRACE_ENTRY("%p", session); |
e5fcd672caff
Added new function to retrieve messages sessions easily
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
829 CHECK_PARAMS( session && VALIDATE_SI(*session) ); |
e5fcd672caff
Added new function to retrieve messages sessions easily
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
830 |
e5fcd672caff
Added new function to retrieve messages sessions easily
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
831 /* Update the msg refcount */ |
e5fcd672caff
Added new function to retrieve messages sessions easily
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
832 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
|
833 reclaim = (*session)->msg_cnt; |
e5fcd672caff
Added new function to retrieve messages sessions easily
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
834 (*session)->msg_cnt = reclaim - 1; |
e5fcd672caff
Added new function to retrieve messages sessions easily
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
835 CHECK_POSIX( pthread_mutex_unlock(&(*session)->stlock) ); |
e5fcd672caff
Added new function to retrieve messages sessions easily
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
836 |
e5fcd672caff
Added new function to retrieve messages sessions easily
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
837 if (reclaim == 1) { |
e5fcd672caff
Added new function to retrieve messages sessions easily
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
838 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
|
839 } else { |
e5fcd672caff
Added new function to retrieve messages sessions easily
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
840 *session = NULL; |
e5fcd672caff
Added new function to retrieve messages sessions easily
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
841 } |
e5fcd672caff
Added new function to retrieve messages sessions easily
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
842 return 0; |
e5fcd672caff
Added new function to retrieve messages sessions easily
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
843 } |
e5fcd672caff
Added new function to retrieve messages sessions easily
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
844 |
e5fcd672caff
Added new function to retrieve messages sessions easily
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
845 |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
846 |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
847 /* Dump functions */ |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
848 void fd_sess_dump(int level, struct session * session) |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
849 { |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
850 struct fd_list * li; |
5
c2d2729e3603
Completed new session module tests; some bugs fixed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
4
diff
changeset
|
851 char buf[30]; |
c2d2729e3603
Completed new session module tests; some bugs fixed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
4
diff
changeset
|
852 struct tm tm; |
c2d2729e3603
Completed new session module tests; some bugs fixed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
4
diff
changeset
|
853 |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
854 if (!TRACE_BOOL(level)) |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
855 return; |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
856 |
5
c2d2729e3603
Completed new session module tests; some bugs fixed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
4
diff
changeset
|
857 fd_log_debug("\t %*s -- Session @%p --\n", level, "", session); |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
858 if (!VALIDATE_SI(session)) { |
5
c2d2729e3603
Completed new session module tests; some bugs fixed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
4
diff
changeset
|
859 fd_log_debug("\t %*s Invalid session object\n", level, ""); |
c2d2729e3603
Completed new session module tests; some bugs fixed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
4
diff
changeset
|
860 } else { |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
861 |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
691
diff
changeset
|
862 fd_log_debug("\t %*s sid '%s'(%zd), hash %x\n", level, "", session->sid, session->sidlen, session->hash); |
5
c2d2729e3603
Completed new session module tests; some bugs fixed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
4
diff
changeset
|
863 |
c2d2729e3603
Completed new session module tests; some bugs fixed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
4
diff
changeset
|
864 strftime(buf, sizeof(buf), "%D,%T", localtime_r( &session->timeout.tv_sec , &tm )); |
c2d2729e3603
Completed new session module tests; some bugs fixed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
4
diff
changeset
|
865 fd_log_debug("\t %*s timeout %s.%09ld\n", level, "", buf, session->timeout.tv_nsec); |
c2d2729e3603
Completed new session module tests; some bugs fixed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
4
diff
changeset
|
866 |
c2d2729e3603
Completed new session module tests; some bugs fixed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
4
diff
changeset
|
867 CHECK_POSIX_DO( pthread_mutex_lock(&session->stlock), /* ignore */ ); |
203
536b1dde8761
Some cleanups in the cnxctx module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
136
diff
changeset
|
868 pthread_cleanup_push( fd_cleanup_mutex, &session->stlock ); |
5
c2d2729e3603
Completed new session module tests; some bugs fixed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
4
diff
changeset
|
869 for (li = session->states.next; li != &session->states; li = li->next) { |
c2d2729e3603
Completed new session module tests; some bugs fixed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
4
diff
changeset
|
870 struct state * st = (struct state *)(li->o); |
c2d2729e3603
Completed new session module tests; some bugs fixed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
4
diff
changeset
|
871 fd_log_debug("\t %*s handler %d registered data %p\n", level, "", st->hdl->id, st->state); |
c2d2729e3603
Completed new session module tests; some bugs fixed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
4
diff
changeset
|
872 } |
203
536b1dde8761
Some cleanups in the cnxctx module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
136
diff
changeset
|
873 pthread_cleanup_pop(0); |
5
c2d2729e3603
Completed new session module tests; some bugs fixed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
4
diff
changeset
|
874 CHECK_POSIX_DO( pthread_mutex_unlock(&session->stlock), /* ignore */ ); |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
875 } |
5
c2d2729e3603
Completed new session module tests; some bugs fixed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
4
diff
changeset
|
876 fd_log_debug("\t %*s -- end of session @%p --\n", level, "", session); |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
877 } |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
878 |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
879 void fd_sess_dump_hdl(int level, struct session_handler * handler) |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
880 { |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
881 if (!TRACE_BOOL(level)) |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
882 return; |
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
883 |
5
c2d2729e3603
Completed new session module tests; some bugs fixed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
4
diff
changeset
|
884 fd_log_debug("\t %*s -- Handler @%p --\n", level, "", handler); |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
885 if (!VALIDATE_SH(handler)) { |
5
c2d2729e3603
Completed new session module tests; some bugs fixed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
4
diff
changeset
|
886 fd_log_debug("\t %*s Invalid session handler object\n", level, ""); |
c2d2729e3603
Completed new session module tests; some bugs fixed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
4
diff
changeset
|
887 } else { |
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
|
888 fd_log_debug("\t %*s id %d, cleanup %p, opaque %p\n", level, "", handler->id, handler->cleanup, handler->opaque); |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
889 } |
5
c2d2729e3603
Completed new session module tests; some bugs fixed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
4
diff
changeset
|
890 fd_log_debug("\t %*s -- end of handler @%p --\n", level, "", handler); |
3
ef303f1078ab
Progress; added session module; testsess to be completed
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
891 } |