Changeset 1140 for pjproject/trunk/pjnath/src/pjnath/stun_transaction.c
- Timestamp:
- Apr 3, 2007 6:01:27 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjnath/src/pjnath/stun_transaction.c
r1126 r1140 37 37 38 38 pj_bool_t complete; 39 \ 39 40 40 pj_bool_t require_retransmit; 41 pj_timer_entry timer;41 pj_timer_entry retransmit_timer; 42 42 unsigned transmit_count; 43 43 pj_time_val retransmit_time; 44 45 pj_timer_entry destroy_timer; 44 46 45 47 void *last_pkt; … … 50 52 static void retransmit_timer_callback(pj_timer_heap_t *timer_heap, 51 53 pj_timer_entry *timer); 54 static void destroy_timer_callback(pj_timer_heap_t *timer_heap, 55 pj_timer_entry *timer); 52 56 53 57 #define stun_perror(tsx,msg,rc) pjnath_perror(tsx->obj_name, msg, rc) … … 70 74 pj_memcpy(&tsx->cb, cb, sizeof(*cb)); 71 75 72 tsx->timer.cb = &retransmit_timer_callback; 73 tsx->timer.user_data = tsx; 76 tsx->retransmit_timer.cb = &retransmit_timer_callback; 77 tsx->retransmit_timer.user_data = tsx; 78 79 tsx->destroy_timer.cb = &destroy_timer_callback; 80 tsx->destroy_timer.user_data = tsx; 74 81 75 82 pj_ansi_snprintf(tsx->obj_name, sizeof(tsx->obj_name), "stuntsx%p", tsx); … … 82 89 83 90 84 /* 85 * . 91 PJ_DEF(pj_status_t) 92 pj_stun_client_tsx_schedule_destroy(pj_stun_client_tsx *tsx, 93 const pj_time_val *delay) 94 { 95 pj_status_t status; 96 97 PJ_ASSERT_RETURN(tsx && delay, PJ_EINVAL); 98 PJ_ASSERT_RETURN(tsx->cb.on_destroy, PJ_EINVAL); 99 100 /* Cancel previously registered timer */ 101 if (tsx->destroy_timer.id != 0) { 102 pj_timer_heap_cancel(tsx->cfg->timer_heap, &tsx->destroy_timer); 103 tsx->destroy_timer.id = 0; 104 } 105 106 /* Stop retransmission, just in case */ 107 if (tsx->retransmit_timer.id != 0) { 108 pj_timer_heap_cancel(tsx->cfg->timer_heap, &tsx->retransmit_timer); 109 tsx->retransmit_timer.id = 0; 110 } 111 112 status = pj_timer_heap_schedule(tsx->cfg->timer_heap, 113 &tsx->destroy_timer, delay); 114 if (status != PJ_SUCCESS) 115 return status; 116 117 tsx->destroy_timer.id = TIMER_ACTIVE; 118 119 return PJ_SUCCESS; 120 } 121 122 123 /* 124 * Destroy transaction immediately. 86 125 */ 87 126 PJ_DEF(pj_status_t) pj_stun_client_tsx_destroy(pj_stun_client_tsx *tsx) … … 89 128 PJ_ASSERT_RETURN(tsx, PJ_EINVAL); 90 129 91 if (tsx->timer.id != 0) { 92 pj_timer_heap_cancel(tsx->cfg->timer_heap, &tsx->timer); 93 tsx->timer.id = 0; 94 } 130 if (tsx->retransmit_timer.id != 0) { 131 pj_timer_heap_cancel(tsx->cfg->timer_heap, &tsx->retransmit_timer); 132 tsx->retransmit_timer.id = 0; 133 } 134 if (tsx->destroy_timer.id != 0) { 135 pj_timer_heap_cancel(tsx->cfg->timer_heap, &tsx->destroy_timer); 136 tsx->destroy_timer.id = 0; 137 } 138 139 PJ_LOG(5,(tsx->obj_name, "STUN client transaction destroyed")); 95 140 return PJ_SUCCESS; 96 141 } … … 136 181 pj_status_t status; 137 182 138 PJ_ASSERT_RETURN(tsx-> timer.id == 0, PJ_EBUSY);183 PJ_ASSERT_RETURN(tsx->retransmit_timer.id == 0, PJ_EBUSY); 139 184 140 185 if (tsx->require_retransmit) { … … 161 206 * cancel transmission). 162 207 */; 163 status = pj_timer_heap_schedule(tsx->cfg->timer_heap, &tsx->timer, 208 status = pj_timer_heap_schedule(tsx->cfg->timer_heap, 209 &tsx->retransmit_timer, 164 210 &tsx->retransmit_time); 165 211 if (status != PJ_SUCCESS) { 166 tsx-> timer.id = 0;212 tsx->retransmit_timer.id = 0; 167 213 return status; 168 214 } 169 tsx-> timer.id = TIMER_ACTIVE;215 tsx->retransmit_timer.id = TIMER_ACTIVE; 170 216 } 171 217 … … 174 220 status = tsx->cb.on_send_msg(tsx, tsx->last_pkt, tsx->last_pkt_size); 175 221 if (status != PJ_SUCCESS) { 176 if (tsx->timer.id != 0) { 177 pj_timer_heap_cancel(tsx->cfg->timer_heap, &tsx->timer); 178 tsx->timer.id = 0; 222 if (tsx->retransmit_timer.id != 0) { 223 pj_timer_heap_cancel(tsx->cfg->timer_heap, 224 &tsx->retransmit_timer); 225 tsx->retransmit_timer.id = 0; 179 226 } 180 227 stun_perror(tsx, "STUN error sending message", status); … … 199 246 { 200 247 PJ_ASSERT_RETURN(tsx && pkt && pkt_len, PJ_EINVAL); 201 PJ_ASSERT_RETURN(tsx-> timer.id == 0, PJ_EBUSY);248 PJ_ASSERT_RETURN(tsx->retransmit_timer.id == 0, PJ_EBUSY); 202 249 203 250 /* Encode message */ … … 224 271 if (tsx->transmit_count >= PJ_STUN_MAX_RETRANSMIT_COUNT) { 225 272 /* Retransmission count exceeded. Transaction has failed */ 226 tsx-> timer.id = 0;273 tsx->retransmit_timer.id = 0; 227 274 PJ_LOG(4,(tsx->obj_name, "STUN timeout waiting for response")); 228 tsx->complete = PJ_TRUE; 229 if (tsx->cb.on_complete) { 230 tsx->cb.on_complete(tsx, PJNATH_ESTUNTIMEDOUT, NULL); 275 if (!tsx->complete) { 276 tsx->complete = PJ_TRUE; 277 if (tsx->cb.on_complete) { 278 tsx->cb.on_complete(tsx, PJNATH_ESTUNTIMEDOUT, NULL); 279 } 231 280 } 232 281 return; 233 282 } 234 283 235 tsx-> timer.id = 0;284 tsx->retransmit_timer.id = 0; 236 285 status = tsx_transmit_msg(tsx); 237 286 if (status != PJ_SUCCESS) { 238 tsx->timer.id = 0; 239 tsx->complete = PJ_TRUE; 240 if (tsx->cb.on_complete) { 241 tsx->cb.on_complete(tsx, status, NULL); 242 } 243 } 244 } 245 287 tsx->retransmit_timer.id = 0; 288 if (!tsx->complete) { 289 tsx->complete = PJ_TRUE; 290 if (tsx->cb.on_complete) { 291 tsx->cb.on_complete(tsx, status, NULL); 292 } 293 } 294 } 295 } 296 297 298 /* Timer callback to destroy transaction */ 299 static void destroy_timer_callback(pj_timer_heap_t *timer_heap, 300 pj_timer_entry *timer) 301 { 302 pj_stun_client_tsx *tsx = (pj_stun_client_tsx *) timer->user_data; 303 304 PJ_UNUSED_ARG(timer_heap); 305 306 tsx->destroy_timer.id = PJ_FALSE; 307 tsx->cb.on_destroy(tsx); 308 /* Don't access transaction after this */ 309 } 246 310 247 311 … … 268 332 * We can cancel retransmit timer now. 269 333 */ 270 if (tsx-> timer.id) {271 pj_timer_heap_cancel(tsx->cfg->timer_heap, &tsx-> timer);272 tsx-> timer.id = 0;334 if (tsx->retransmit_timer.id) { 335 pj_timer_heap_cancel(tsx->cfg->timer_heap, &tsx->retransmit_timer); 336 tsx->retransmit_timer.id = 0; 273 337 } 274 338 … … 297 361 298 362 /* Call callback */ 299 tsx->complete = PJ_TRUE; 300 if (tsx->cb.on_complete) { 301 tsx->cb.on_complete(tsx, status, msg); 302 } 303 304 return PJ_SUCCESS; 305 306 } 307 363 if (!tsx->complete) { 364 tsx->complete = PJ_TRUE; 365 if (tsx->cb.on_complete) { 366 tsx->cb.on_complete(tsx, status, msg); 367 } 368 } 369 370 return PJ_SUCCESS; 371 372 } 373
Note: See TracChangeset
for help on using the changeset viewer.