- Timestamp:
- Jun 23, 2006 3:04:54 PM (18 years ago)
- Location:
- pjproject/trunk/pjsip
- Files:
-
- 2 added
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjsip/build/pjsip_core.dsp
r515 r550 147 147 # Begin Source File 148 148 149 SOURCE=..\src\pjsip\sip_transport_tcp.c 150 # PROP Exclude_From_Build 1 151 # End Source File 152 # Begin Source File 153 149 154 SOURCE=..\src\pjsip\sip_transport_udp.c 150 155 # End Source File … … 279 284 # Begin Source File 280 285 286 SOURCE=..\include\pjsip\sip_transport_tcp.h 287 # End Source File 288 # Begin Source File 289 281 290 SOURCE=..\include\pjsip\sip_transport_udp.h 282 291 # End Source File -
pjproject/trunk/pjsip/include/pjsip/sip_transport.h
r515 r550 493 493 pj_atomic_t *ref_cnt; /**< Reference counter. */ 494 494 pj_lock_t *lock; /**< Lock object. */ 495 int tracing; /**< Tracing enabled? */ 495 pj_bool_t tracing; /**< Tracing enabled? */ 496 pj_bool_t is_shutdown; /**< Being shutdown? */ 496 497 497 498 /** Key for indexing this transport in hash table. */ … … 550 551 551 552 /** 552 * Destroy this transport. 553 * Instruct the transport to initiate graceful shutdown procedure. 554 * After all objects release their reference to this transport, 555 * the transport will be deleted. 556 * 557 * Note that application MUST use #pjsip_transport_shutdown() instead. 558 * 559 * @param transport The transport. 560 * 561 * @return PJ_SUCCESS on success. 562 */ 563 pj_status_t (*do_shutdown)(pjsip_transport *transport); 564 565 /** 566 * Forcefully destroy this transport regardless whether there are 567 * objects that currently use this transport. This function should only 568 * be called by transport manager or other internal objects (such as the 569 * transport itself) who know what they're doing. Application should use 570 * #pjsip_transport_shutdown() instead. 571 * 572 * @param transport The transport. 573 * 574 * @return PJ_SUCCESS on success. 553 575 */ 554 576 pj_status_t (*destroy)(pjsip_transport *transport); … … 561 583 562 584 /** 563 * Register a transport. 585 * Register a transport instance to the transport manager. This function 586 * is normally called by the transport instance when it is created 587 * by application. 588 * 589 * @param mgr The transport manager. 590 * @param tp The new transport to be registered. 591 * 592 * @return PJ_SUCCESS on success. 564 593 */ 565 594 PJ_DECL(pj_status_t) pjsip_transport_register( pjsip_tpmgr *mgr, … … 568 597 569 598 /** 570 * Unregister transport. This will eventually call the transport to 571 * destroy itself. 572 */ 573 PJ_DECL(pj_status_t) pjsip_transport_unregister( pjsip_tpmgr *mgr, 574 pjsip_transport *tp); 575 576 /** 577 * Add ref. 599 * Start graceful shutdown procedure for this transport. After graceful 600 * shutdown has been initiated, no new reference can be obtained for 601 * the transport. However, existing objects that currently uses the 602 * transport may still use this transport to send and receive packets. 603 * 604 * After all objects release their reference to this transport, 605 * the transport will be destroyed immediately. 606 * 607 * @param tp The transport. 608 * 609 * @return PJ_SUCCESS on success. 610 */ 611 PJ_DECL(pj_status_t) pjsip_transport_shutdown(pjsip_transport *tp); 612 613 /** 614 * Destroy a transport when there is no object currently uses the transport. 615 * This function is normally called internally by transport manager or the 616 * transport itself. Application should use #pjsip_transport_shutdown() 617 * instead. 618 * 619 * @param tp The transport instance. 620 * 621 * @return PJ_SUCCESS on success or the appropriate error code. 622 * Some of possible errors are PJSIP_EBUSY if the 623 * transport's reference counter is not zero. 624 */ 625 PJ_DECL(pj_status_t) pjsip_transport_destroy( pjsip_transport *tp); 626 627 /** 628 * Add reference counter to the specified transport. Any objects that wishes 629 * to keep the reference of the transport MUST increment the transport's 630 * reference counter to prevent it from being destroyed. 631 * 632 * @param tp The transport instance. 633 * 634 * @return PJ_SUCCESS on success or the appropriate error code. 578 635 */ 579 636 PJ_DECL(pj_status_t) pjsip_transport_add_ref( pjsip_transport *tp ); 580 637 581 638 /** 582 * Dec ref. 639 * Decrement reference counter of the specified transport. When an object no 640 * longer want to keep the reference to the transport, it must decrement the 641 * reference counter. When the reference counter of the transport reaches 642 * zero, the transport manager will start the idle timer to destroy the 643 * transport if no objects acquire the reference counter during the idle 644 * interval. 645 * 646 * @param tp The transport instance. 647 * 648 * @return PJ_SUCCESS on success. 583 649 */ 584 650 PJ_DECL(pj_status_t) pjsip_transport_dec_ref( pjsip_transport *tp ); … … 586 652 587 653 /** 588 * Call for incoming message. 654 * This function is called by transport instances to report an incoming 655 * packet to the transport manager. The transport manager then would try to 656 * parse all SIP messages in the packet, and for each parsed SIP message, it 657 * would report the message to the SIP endpoint (#pjsip_endpoint). 658 * 659 * @param mgr The transport manager instance. 660 * @param rdata The receive data buffer containing the packet. The 661 * transport MUST fully initialize tp_info and pkt_info 662 * member of the rdata. 663 * 664 * @return The number of bytes successfully processed from the 665 * packet. If the transport is datagram oriented, the 666 * value will be equal to the size of the packet. For 667 * stream oriented transport (e.g. TCP, TLS), the value 668 * returned may be less than the packet size, if 669 * partial message is received. The transport then MUST 670 * keep the remainder part and report it again to 671 * this function once more data/packet is received. 589 672 */ 590 673 PJ_DECL(pj_ssize_t) pjsip_tpmgr_receive_packet(pjsip_tpmgr *mgr, … … 598 681 *****************************************************************************/ 599 682 600 601 /** 602 * Transport factory.683 /* 684 * Forward declaration for transport factory (since it is referenced by 685 * the transport factory itself). 603 686 */ 604 687 typedef struct pjsip_tpfactory pjsip_tpfactory; 605 688 606 /** 607 * Transport factory. 689 690 /** 691 * A transport factory is normally used for connection oriented transports 692 * (such as TCP or TLS) to create instances of transports. It registers 693 * a new transport type to the transport manager, and the transport manager 694 * would ask the factory to create a transport instance when it received 695 * command from application to send a SIP message using the specified 696 * transport type. 608 697 */ 609 698 struct pjsip_tpfactory -
pjproject/trunk/pjsip/include/pjsip/sip_transport_udp.h
r515 r550 30 30 31 31 /** 32 * @defgroup PJSIP_TRANSPORT_UDP UDP transport32 * @defgroup PJSIP_TRANSPORT_UDP UDP Transport 33 33 * @ingroup PJSIP_TRANSPORT 34 34 * @brief API to create and register UDP transport. -
pjproject/trunk/pjsip/src/pjsip/sip_transport.c
r491 r550 517 517 518 518 entry->id = PJ_FALSE; 519 pjsip_transport_ unregister(tp->tpmgr,tp);519 pjsip_transport_destroy(tp); 520 520 } 521 521 … … 555 555 /* Verify again. */ 556 556 if (pj_atomic_get(tp->ref_cnt) == 0) { 557 pj_time_val delay = { PJSIP_TRANSPORT_IDLE_TIME, 0 }; 557 pj_time_val delay; 558 559 /* If transport is in graceful shutdown, then this is the 560 * last user who uses the transport. Schedule to destroy the 561 * transport immediately. Otherwise schedule idle timer. 562 */ 563 if (tp->is_shutdown) { 564 delay.sec = delay.msec = 0; 565 } else { 566 delay.sec = PJSIP_TRANSPORT_IDLE_TIME; 567 delay.msec = 0; 568 } 558 569 559 570 pj_assert(tp->idle_timer.id == 0); … … 624 635 } 625 636 637 638 /* 639 * Start graceful shutdown procedure for this transport. 640 */ 641 PJ_DEF(pj_status_t) pjsip_transport_shutdown(pjsip_transport *tp) 642 { 643 pjsip_tpmgr *mgr; 644 pj_status_t status; 645 646 pj_lock_acquire(tp->lock); 647 648 mgr = tp->tpmgr; 649 pj_lock_acquire(mgr->lock); 650 651 /* Do nothing if transport is being shutdown already */ 652 if (tp->is_shutdown) { 653 pj_lock_release(tp->lock); 654 pj_lock_release(mgr->lock); 655 return PJ_SUCCESS; 656 } 657 658 status = PJ_SUCCESS; 659 660 /* Instruct transport to shutdown itself */ 661 if (tp->do_shutdown) 662 status = tp->do_shutdown(tp); 663 664 if (status == PJ_SUCCESS) 665 tp->is_shutdown = PJ_TRUE; 666 667 pj_lock_release(tp->lock); 668 pj_lock_release(mgr->lock); 669 670 return status; 671 } 672 673 626 674 /** 627 675 * Unregister transport. 628 676 */ 629 PJ_DEF(pj_status_t) pjsip_transport_unregister( pjsip_tpmgr *mgr, 630 pjsip_transport *tp) 677 PJ_DEF(pj_status_t) pjsip_transport_destroy( pjsip_transport *tp) 631 678 { 632 679 /* Must have no user. */ … … 634 681 635 682 /* Destroy. */ 636 return destroy_transport( mgr, tp);683 return destroy_transport(tp->tpmgr, tp); 637 684 } 638 685 … … 1030 1077 } 1031 1078 1032 if (transport != NULL) {1079 if (transport!=NULL && !transport->is_shutdown) { 1033 1080 /* 1034 1081 * Transport found! -
pjproject/trunk/pjsip/src/pjsip/sip_transport_udp.c
r543 r550 378 378 379 379 /* 380 * udp_shutdown() 381 * 382 * Start graceful UDP shutdown. 383 */ 384 static pj_status_t udp_shutdown(pjsip_transport *transport) 385 { 386 return pjsip_transport_dec_ref(transport); 387 } 388 389 390 /* 380 391 * pjsip_udp_transport_attach() 381 392 * … … 506 517 /* Set functions. */ 507 518 tp->base.send_msg = &udp_send_msg; 519 tp->base.do_shutdown = &udp_shutdown; 508 520 tp->base.destroy = &udp_destroy; 509 521 … … 531 543 if (!rdata_pool) { 532 544 pj_atomic_set(tp->base.ref_cnt, 0); 533 pjsip_transport_ unregister(tp->base.tpmgr,&tp->base);545 pjsip_transport_destroy(&tp->base); 534 546 return PJ_ENOMEM; 535 547 } … … 557 569 } else if (status != PJ_EPENDING) { 558 570 /* Error! */ 559 pjsip_transport_ unregister(tp->base.tpmgr,&tp->base);571 pjsip_transport_destroy(&tp->base); 560 572 return status; 561 573 } -
pjproject/trunk/pjsip/src/test-pjsip/transport_udp_test.c
r127 r550 103 103 104 104 /* Force destroy this transport. */ 105 status = pjsip_transport_ unregister( pjsip_endpt_get_tpmgr(endpt),udp_tp);105 status = pjsip_transport_destroy(udp_tp); 106 106 if (status != PJ_SUCCESS) 107 107 return -90;
Note: See TracChangeset
for help on using the changeset viewer.