Changeset 550


Ignore:
Timestamp:
Jun 23, 2006 3:04:54 PM (16 years ago)
Author:
bennylp
Message:

Renamed pjsip_transport_unregister() to pjsip_transport_destroy(), also initial implementation of TCP transport

Location:
pjproject/trunk/pjsip
Files:
2 added
6 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjsip/build/pjsip_core.dsp

    r515 r550  
    147147# Begin Source File 
    148148 
     149SOURCE=..\src\pjsip\sip_transport_tcp.c 
     150# PROP Exclude_From_Build 1 
     151# End Source File 
     152# Begin Source File 
     153 
    149154SOURCE=..\src\pjsip\sip_transport_udp.c 
    150155# End Source File 
     
    279284# Begin Source File 
    280285 
     286SOURCE=..\include\pjsip\sip_transport_tcp.h 
     287# End Source File 
     288# Begin Source File 
     289 
    281290SOURCE=..\include\pjsip\sip_transport_udp.h 
    282291# End Source File 
  • pjproject/trunk/pjsip/include/pjsip/sip_transport.h

    r515 r550  
    493493    pj_atomic_t            *ref_cnt;        /**< Reference counter.         */ 
    494494    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?            */ 
    496497 
    497498    /** Key for indexing this transport in hash table. */ 
     
    550551 
    551552    /** 
    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. 
    553575     */ 
    554576    pj_status_t (*destroy)(pjsip_transport *transport); 
     
    561583 
    562584/** 
    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. 
    564593 */ 
    565594PJ_DECL(pj_status_t) pjsip_transport_register( pjsip_tpmgr *mgr, 
     
    568597 
    569598/** 
    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 */ 
     611PJ_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 */ 
     625PJ_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. 
    578635 */ 
    579636PJ_DECL(pj_status_t) pjsip_transport_add_ref( pjsip_transport *tp ); 
    580637 
    581638/** 
    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. 
    583649 */ 
    584650PJ_DECL(pj_status_t) pjsip_transport_dec_ref( pjsip_transport *tp ); 
     
    586652 
    587653/** 
    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. 
    589672 */ 
    590673PJ_DECL(pj_ssize_t) pjsip_tpmgr_receive_packet(pjsip_tpmgr *mgr, 
     
    598681 *****************************************************************************/ 
    599682 
    600  
    601 /** 
    602  * Transport factory. 
     683/* 
     684 * Forward declaration for transport factory (since it is referenced by 
     685 * the transport factory itself). 
    603686 */ 
    604687typedef struct pjsip_tpfactory pjsip_tpfactory; 
    605688 
    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. 
    608697 */ 
    609698struct pjsip_tpfactory 
  • pjproject/trunk/pjsip/include/pjsip/sip_transport_udp.h

    r515 r550  
    3030 
    3131/** 
    32  * @defgroup PJSIP_TRANSPORT_UDP UDP transport 
     32 * @defgroup PJSIP_TRANSPORT_UDP UDP Transport 
    3333 * @ingroup PJSIP_TRANSPORT 
    3434 * @brief API to create and register UDP transport. 
  • pjproject/trunk/pjsip/src/pjsip/sip_transport.c

    r491 r550  
    517517 
    518518    entry->id = PJ_FALSE; 
    519     pjsip_transport_unregister(tp->tpmgr, tp); 
     519    pjsip_transport_destroy(tp); 
    520520} 
    521521 
     
    555555        /* Verify again. */ 
    556556        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            } 
    558569 
    559570            pj_assert(tp->idle_timer.id == 0); 
     
    624635} 
    625636 
     637 
     638/* 
     639 * Start graceful shutdown procedure for this transport.  
     640 */ 
     641PJ_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 
    626674/** 
    627675 * Unregister transport. 
    628676 */ 
    629 PJ_DEF(pj_status_t) pjsip_transport_unregister( pjsip_tpmgr *mgr, 
    630                                                 pjsip_transport *tp) 
     677PJ_DEF(pj_status_t) pjsip_transport_destroy( pjsip_transport *tp) 
    631678{ 
    632679    /* Must have no user. */ 
     
    634681 
    635682    /* Destroy. */ 
    636     return destroy_transport(mgr, tp); 
     683    return destroy_transport(tp->tpmgr, tp); 
    637684} 
    638685 
     
    10301077    } 
    10311078     
    1032     if (transport != NULL) { 
     1079    if (transport!=NULL && !transport->is_shutdown) { 
    10331080        /* 
    10341081         * Transport found! 
  • pjproject/trunk/pjsip/src/pjsip/sip_transport_udp.c

    r543 r550  
    378378 
    379379/* 
     380 * udp_shutdown() 
     381 * 
     382 * Start graceful UDP shutdown. 
     383 */ 
     384static pj_status_t udp_shutdown(pjsip_transport *transport) 
     385{ 
     386    return pjsip_transport_dec_ref(transport); 
     387} 
     388 
     389 
     390/* 
    380391 * pjsip_udp_transport_attach() 
    381392 * 
     
    506517    /* Set functions. */ 
    507518    tp->base.send_msg = &udp_send_msg; 
     519    tp->base.do_shutdown = &udp_shutdown; 
    508520    tp->base.destroy = &udp_destroy; 
    509521 
     
    531543        if (!rdata_pool) { 
    532544            pj_atomic_set(tp->base.ref_cnt, 0); 
    533             pjsip_transport_unregister(tp->base.tpmgr, &tp->base); 
     545            pjsip_transport_destroy(&tp->base); 
    534546            return PJ_ENOMEM; 
    535547        } 
     
    557569        } else if (status != PJ_EPENDING) { 
    558570            /* Error! */ 
    559             pjsip_transport_unregister(tp->base.tpmgr, &tp->base); 
     571            pjsip_transport_destroy(&tp->base); 
    560572            return status; 
    561573        } 
  • pjproject/trunk/pjsip/src/test-pjsip/transport_udp_test.c

    r127 r550  
    103103 
    104104    /* Force destroy this transport. */ 
    105     status = pjsip_transport_unregister( pjsip_endpt_get_tpmgr(endpt), udp_tp); 
     105    status = pjsip_transport_destroy(udp_tp); 
    106106    if (status != PJ_SUCCESS) 
    107107        return -90; 
Note: See TracChangeset for help on using the changeset viewer.