- Timestamp:
- Feb 3, 2007 8:31:33 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/branches/iceproject/pjlib-util/src/pjlib-util/stun_transaction.c
r913 r929 1 /* $Id */1 /* $Id$ */ 2 2 /* 3 3 * Copyright (C) 2003-2005 Benny Prijono <benny@prijono.org> … … 39 39 pj_uint32_t tsx_id[4]; 40 40 41 pj_bool_t require_retransmit; 41 42 pj_timer_entry timer; 42 43 unsigned transmit_count; … … 109 110 110 111 /* 111 * .112 * Set user data. 112 113 */ 113 114 PJ_DEF(pj_status_t) pj_stun_client_tsx_set_data(pj_stun_client_tsx *tsx, … … 121 122 122 123 /* 123 * .124 * Get the user data 124 125 */ 125 126 PJ_DEF(void*) pj_stun_client_tsx_get_data(pj_stun_client_tsx *tsx) … … 139 140 PJ_ASSERT_RETURN(tsx->timer.id == 0, PJ_EBUSY); 140 141 141 /* Calculate retransmit/timeout delay */ 142 if (tsx->transmit_count == 0) { 143 tsx->retransmit_time.sec = 0; 144 tsx->retransmit_time.msec = tsx->endpt->rto_msec; 145 146 } else if (tsx->transmit_count < PJ_STUN_MAX_RETRANSMIT_COUNT) { 147 unsigned msec; 148 149 msec = PJ_TIME_VAL_MSEC(tsx->retransmit_time); 150 msec = (msec >> 1) + 100; 151 tsx->retransmit_time.sec = msec / 1000; 152 tsx->retransmit_time.msec = msec % 100; 153 154 } else { 155 tsx->retransmit_time.sec = PJ_STUN_TIMEOUT_VALUE / 1000; 156 tsx->retransmit_time.msec = PJ_STUN_TIMEOUT_VALUE % 1000; 157 } 158 159 /* Schedule timer first because when send_msg() failed we can 160 * cancel it (as opposed to when schedule_timer() failed we cannot 161 * cancel transmission). 162 */ 163 status = pj_timer_heap_schedule(tsx->endpt->timer_heap, &tsx->timer, 164 &tsx->retransmit_time); 165 if (status != PJ_SUCCESS) { 166 tsx->timer.id = 0; 167 return status; 142 if (tsx->require_retransmit) { 143 /* Calculate retransmit/timeout delay */ 144 if (tsx->transmit_count == 0) { 145 tsx->retransmit_time.sec = 0; 146 tsx->retransmit_time.msec = tsx->endpt->rto_msec; 147 148 } else if (tsx->transmit_count < PJ_STUN_MAX_RETRANSMIT_COUNT) { 149 unsigned msec; 150 151 msec = PJ_TIME_VAL_MSEC(tsx->retransmit_time); 152 msec = (msec >> 1) + 100; 153 tsx->retransmit_time.sec = msec / 1000; 154 tsx->retransmit_time.msec = msec % 100; 155 156 } else { 157 tsx->retransmit_time.sec = PJ_STUN_TIMEOUT_VALUE / 1000; 158 tsx->retransmit_time.msec = PJ_STUN_TIMEOUT_VALUE % 1000; 159 } 160 161 /* Schedule timer first because when send_msg() failed we can 162 * cancel it (as opposed to when schedule_timer() failed we cannot 163 * cancel transmission). 164 */ 165 status = pj_timer_heap_schedule(tsx->endpt->timer_heap, &tsx->timer, 166 &tsx->retransmit_time); 167 if (status != PJ_SUCCESS) { 168 tsx->timer.id = 0; 169 return status; 170 } 168 171 } 169 172 … … 172 175 status = tsx->cb.on_send_msg(tsx, tsx->last_pkt, tsx->last_pkt_size); 173 176 if (status != PJ_SUCCESS) { 174 pj_timer_heap_cancel(tsx->endpt->timer_heap, &tsx->timer); 175 tsx->timer.id = 0; 177 if (tsx->timer.id != 0) { 178 pj_timer_heap_cancel(tsx->endpt->timer_heap, &tsx->timer); 179 tsx->timer.id = 0; 180 } 176 181 stun_perror(tsx, "STUN error sending message", status); 177 182 return status; … … 185 190 } 186 191 187 /* 188 * . 192 193 /* 194 * Send outgoing message and start STUN transaction. 189 195 */ 190 196 PJ_DEF(pj_status_t) pj_stun_client_tsx_send_msg(pj_stun_client_tsx *tsx, 197 pj_bool_t retransmit, 191 198 const pj_stun_msg *msg) 192 199 { … … 208 215 pj_memcpy(&tsx->tsx_id[1], msg->hdr.tsx_id, 12); 209 216 217 /* Update STUN retransmit flag */ 218 tsx->require_retransmit = retransmit; 219 220 /* Send the message */ 210 221 return tsx_transmit_msg(tsx); 211 222 } … … 243 254 244 255 /* 245 * 256 * Notify the STUN transaction about the arrival of STUN response. 246 257 */ 247 258 PJ_DEF(pj_status_t) pj_stun_client_tsx_on_rx_msg(pj_stun_client_tsx *tsx, … … 292 303 err_attr = (pj_stun_error_code_attr*) 293 304 pj_stun_msg_find_attr(msg, PJ_STUN_ATTR_ERROR_CODE, 0); 294 if (err_attr->err_class == 1) { 305 306 if (err_attr && err_attr->err_class <= 2) { 307 /* draft-ietf-behave-rfc3489bis-05.txt Section 8.3.2: 308 * Any response between 100 and 299 MUST result in the cessation 309 * of request retransmissions, but otherwise is discarded. 310 */ 295 311 PJ_LOG(4,(tsx->obj_name, 296 312 "STUN rx_msg() error: received provisional %d code (%.*s)", … … 301 317 } 302 318 303 if (err_attr ==NULL || err_attr->err_class == 2) {319 if (err_attr == NULL) { 304 320 status = PJ_SUCCESS; 305 321 } else {
Note: See TracChangeset
for help on using the changeset viewer.