Changeset 3106 for pjproject/trunk/pjsip/src/pjsip/sip_transport_tcp.c
- Timestamp:
- Feb 24, 2010 5:43:34 AM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjsip/src/pjsip/sip_transport_tcp.c
r3035 r3106 166 166 host_port->port = pj_sockaddr_get_port(addr); 167 167 } 168 169 170 static void tcp_init_shutdown(struct tcp_transport *tcp, pj_status_t status) 171 { 172 pjsip_tp_state_callback *state_cb; 173 174 if (tcp->close_reason == PJ_SUCCESS) 175 tcp->close_reason = status; 176 177 if (tcp->base.is_shutdown) 178 return; 179 180 /* Notify application of transport disconnected state */ 181 state_cb = pjsip_tpmgr_get_status_cb(tcp->base.tpmgr); 182 if (state_cb) { 183 pjsip_transport_state_info state_info; 184 185 pj_bzero(&state_info, sizeof(state_info)); 186 state_info.status = tcp->close_reason; 187 (*state_cb)(&tcp->base, PJSIP_TP_STATE_DISCONNECTED, &state_info); 188 } 189 190 /* We can not destroy the transport since high level objects may 191 * still keep reference to this transport. So we can only 192 * instruct transport manager to gracefully start the shutdown 193 * procedure for this transport. 194 */ 195 pjsip_transport_shutdown(&tcp->base); 196 } 197 168 198 169 199 /* … … 922 952 struct tcp_transport *tcp; 923 953 char addr[PJ_INET6_ADDRSTRLEN+10]; 954 pjsip_tp_state_callback *state_cb; 924 955 pj_status_t status; 925 956 … … 967 998 pj_gettimeofday(&tcp->last_activity); 968 999 } 1000 1001 /* Notify application of transport state accepted */ 1002 state_cb = pjsip_tpmgr_get_status_cb(tcp->base.tpmgr); 1003 if (state_cb) { 1004 pjsip_transport_state_info state_info; 1005 1006 pj_bzero(&state_info, sizeof(state_info)); 1007 (*state_cb)(&tcp->base, PJSIP_TP_STATE_ACCEPTED, &state_info); 1008 } 969 1009 } 970 1010 } … … 1014 1054 status = (bytes_sent == 0) ? PJ_RETURN_OS_ERROR(OSERR_ENOTCONN) : 1015 1055 -bytes_sent; 1016 if (tcp->close_reason==PJ_SUCCESS) tcp->close_reason = status; 1017 pjsip_transport_shutdown(&tcp->base);1056 1057 tcp_init_shutdown(tcp, status); 1018 1058 1019 1059 return PJ_FALSE; … … 1110 1150 if (status == PJ_SUCCESS) 1111 1151 status = PJ_RETURN_OS_ERROR(OSERR_ENOTCONN); 1112 if (tcp->close_reason==PJ_SUCCESS) tcp->close_reason = status; 1113 pjsip_transport_shutdown(&tcp->base);1152 1153 tcp_init_shutdown(tcp, status); 1114 1154 } 1115 1155 } … … 1200 1240 PJ_LOG(4,(tcp->base.obj_name, "TCP connection closed")); 1201 1241 1202 /* We can not destroy the transport since high level objects may 1203 * still keep reference to this transport. So we can only 1204 * instruct transport manager to gracefully start the shutdown 1205 * procedure for this transport. 1206 */ 1207 if (tcp->close_reason==PJ_SUCCESS) 1208 tcp->close_reason = status; 1209 pjsip_transport_shutdown(&tcp->base); 1242 tcp_init_shutdown(tcp, status); 1210 1243 1211 1244 return PJ_FALSE; … … 1229 1262 pj_sockaddr_in addr; 1230 1263 int addrlen; 1264 1265 pjsip_tp_state_callback *state_cb; 1231 1266 1232 1267 tcp = (struct tcp_transport*) pj_activesock_get_user_data(asock); … … 1253 1288 } 1254 1289 1255 /* We can not destroy the transport since high level objects may 1256 * still keep reference to this transport. So we can only 1257 * instruct transport manager to gracefully start the shutdown 1258 * procedure for this transport. 1259 */ 1260 if (tcp->close_reason==PJ_SUCCESS) tcp->close_reason = status; 1261 pjsip_transport_shutdown(&tcp->base); 1262 return PJ_FALSE; 1290 tcp_init_shutdown(tcp, status); 1263 1291 } 1264 1292 … … 1294 1322 status = tcp_start_read(tcp); 1295 1323 if (status != PJ_SUCCESS) { 1296 /* We can not destroy the transport since high level objects may 1297 * still keep reference to this transport. So we can only 1298 * instruct transport manager to gracefully start the shutdown 1299 * procedure for this transport. 1300 */ 1301 if (tcp->close_reason==PJ_SUCCESS) tcp->close_reason = status; 1302 pjsip_transport_shutdown(&tcp->base); 1324 tcp_init_shutdown(tcp, status); 1303 1325 return PJ_FALSE; 1326 } 1327 1328 /* Notify application of transport state connected */ 1329 state_cb = pjsip_tpmgr_get_status_cb(tcp->base.tpmgr); 1330 if (state_cb) { 1331 pjsip_transport_state_info state_info; 1332 1333 pj_bzero(&state_info, sizeof(state_info)); 1334 (*state_cb)(&tcp->base, PJSIP_TP_STATE_CONNECTED, &state_info); 1304 1335 } 1305 1336 … … 1359 1390 tcp_perror(tcp->base.obj_name, 1360 1391 "Error sending keep-alive packet", status); 1361 pjsip_transport_shutdown(&tcp->base);1392 tcp_init_shutdown(tcp, status); 1362 1393 return; 1363 1394 }
Note: See TracChangeset
for help on using the changeset viewer.