Changeset 16:013ce9851131 in freeDiameter for freeDiameter/p_psm.c
- Timestamp:
- Oct 2, 2009, 6:57:06 PM (15 years ago)
- Branch:
- default
- Phase:
- public
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
freeDiameter/p_psm.c
r14 r16 37 37 38 38 const char *peer_state_str[] = { 39 "STATE_ ZOMBIE"39 "STATE_NEW" 40 40 , "STATE_OPEN" 41 41 , "STATE_CLOSED" … … 46 46 , "STATE_SUSPECT" 47 47 , "STATE_REOPEN" 48 , "STATE_ZOMBIE" 48 49 }; 49 50 … … 123 124 } 124 125 126 /* Wait for the next event in the PSM, or timeout */ 125 127 static int psm_ev_timedget(struct fd_peer * peer, int *code, void ** data) 126 128 { … … 142 144 143 145 return 0; 144 } 145 146 /* The state machine thread */146 } 147 148 /* The state machine thread (controler) */ 147 149 static void * p_psm_th( void * arg ) 148 150 { 149 151 struct fd_peer * peer = (struct fd_peer *)arg; 150 152 int created_started = started; 153 int event; 154 void * ev_data; 151 155 152 156 CHECK_PARAMS_DO( CHECK_PEER(peer), ASSERT(0) ); … … 161 165 } 162 166 163 /* Wait that the PSM are authorized to start in the daemon */164 CHECK_FCT_DO( fd_psm_waitstart(), goto end );165 166 167 /* The state machine starts in CLOSED state */ 167 168 peer->p_hdr.info.pi_state = STATE_CLOSED; 169 170 /* Wait that the PSM are authorized to start in the daemon */ 171 CHECK_FCT_DO( fd_psm_waitstart(), goto psm_end ); 168 172 169 173 /* Initialize the timer */ … … 174 178 } 175 179 176 psm: 177 do { 178 int event; 179 void * ev_data; 180 181 /* Get next event */ 182 CHECK_FCT_DO( psm_ev_timedget(peer, &event, &ev_data), goto end ); 183 TRACE_DEBUG(FULL, "'%s'\t<-- '%s'\t(%p)\t'%s'", 184 STATE_STR(peer->p_hdr.info.pi_state), 185 fd_pev_str(event), ev_data, 186 peer->p_hdr.info.pi_diamid); 187 188 /* Now, the action depends on the current state and the incoming event */ 189 190 191 } while (1); 192 193 194 end: 195 /* set STATE_ZOMBIE */ 196 pthread_cleanup_pop(1); 180 psm_loop: 181 /* Get next event */ 182 CHECK_FCT_DO( psm_ev_timedget(peer, &event, &ev_data), goto psm_end ); 183 TRACE_DEBUG(FULL, "'%s'\t<-- '%s'\t(%p)\t'%s'", 184 STATE_STR(peer->p_hdr.info.pi_state), 185 fd_pev_str(event), ev_data, 186 peer->p_hdr.info.pi_diamid); 187 188 /* Now, the action depends on the current state and the incoming event */ 189 190 /* The following two states are impossible */ 191 ASSERT( peer->p_hdr.info.pi_state != STATE_NEW ); 192 ASSERT( peer->p_hdr.info.pi_state != STATE_ZOMBIE ); 193 194 /* Purge invalid events */ 195 if (!CHECK_EVENT(event)) { 196 TRACE_DEBUG(INFO, "Invalid event received in PSM '%s' : %d", peer->p_hdr.info.pi_diamid, event); 197 goto psm_loop; 198 } 199 200 /* Handle the (easy) debug event now */ 201 if (event == FDEVP_DUMP_ALL) { 202 fd_peer_dump(peer, ANNOYING); 203 goto psm_loop; 204 } 205 206 /* Requests to terminate the peer object */ 207 if (event == FDEVP_TERMINATE) { 208 switch (peer->p_hdr.info.pi_state) { 209 case STATE_CLOSING: 210 case STATE_WAITCNXACK: 211 case STATE_WAITCNXACK_ELEC: 212 case STATE_WAITCEA: 213 case STATE_SUSPECT: 214 /* In these cases, we just cleanup the peer object and terminate now */ 215 TODO("Cleanup the PSM: terminate connection object, ..."); 216 case STATE_CLOSED: 217 /* Then we just terminate the PSM */ 218 goto psm_end; 219 220 case STATE_OPEN: 221 case STATE_REOPEN: 222 /* We cannot just close the conenction, we have to send a DPR first */ 223 TODO("Send DPR, mark the peer as CLOSING"); 224 goto psm_loop; 225 } 226 } 227 228 /* MSG_RECEIVED: fd_p_expi_update(struct fd_peer * peer ) */ 229 /* If timeout or OPEN : call cb if defined */ 230 231 /* Default action : the handling has not yet been implemented. */ 232 TODO("Missing handler in PSM : '%s'\t<-- '%s'", STATE_STR(peer->p_hdr.info.pi_state), fd_pev_str(event)); 233 if (event == FDEVP_PSM_TIMEOUT) { 234 /* We have not handled timeout in this state, let's postpone next alert */ 235 psm_next_timeout(peer, 0, 60); 236 } 237 238 goto psm_loop; 239 240 psm_end: 241 pthread_cleanup_pop(1); /* set STATE_ZOMBIE */ 197 242 return NULL; 198 243 } … … 205 250 { 206 251 TRACE_ENTRY("%p", peer); 207 TODO(""); 208 return ENOTSUP; 252 253 /* Check the peer and state are OK */ 254 CHECK_PARAMS( CHECK_PEER(peer) && (peer->p_hdr.info.pi_state == STATE_NEW) ); 255 256 /* Create the PSM controler thread */ 257 CHECK_POSIX( pthread_create( &peer->p_psm, NULL, p_psm_th, peer ) ); 258 259 /* We're done */ 260 return 0; 209 261 } 210 262 … … 214 266 TRACE_ENTRY("%p", peer); 215 267 CHECK_PARAMS( CHECK_PEER(peer) ); 216 CHECK_FCT( fd_event_send(peer->p_events, FDEVP_TERMINATE, NULL) ); 268 if (peer->p_hdr.info.pi_state != STATE_ZOMBIE) { 269 CHECK_FCT( fd_event_send(peer->p_events, FDEVP_TERMINATE, NULL) ); 270 } else { 271 TRACE_DEBUG(FULL, "Peer '%s' was already terminated", peer->p_hdr.info.pi_diamid); 272 } 217 273 return 0; 218 274 } … … 225 281 TODO("Cancel IN thread"); 226 282 TODO("Cancel OUT thread"); 227 TODO("Cleanup the connection"); 283 TODO("Cleanup the peer connection object"); 284 TODO("Cleanup the message queues (requeue)"); 228 285 return; 229 286 }
Note: See TracChangeset
for help on using the changeset viewer.