Changeset 2481 for pjproject/trunk


Ignore:
Timestamp:
Mar 2, 2009 3:48:45 PM (15 years ago)
Author:
nanang
Message:

Ticket #732:

  • Added new Symbian specific API in PJLIB, pj_symbianos_set_connection_status(), to let PJLIB knows the connection status.
  • Added connection status checks before Symbian socket operations.
  • Added loop limiter in Symbian busy_sleep() to avoid the possibility of infinite loop.
  • Added sample of connection monitor in Symbian sample application (ua.cpp).
Location:
pjproject/trunk
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjlib/include/pj/os.h

    r2394 r2481  
    395395PJ_DECL(pj_status_t) pj_symbianos_set_params(pj_symbianos_params *prm); 
    396396 
     397/** 
     398 *  Notify PJLIB that the access point connection has been down or unusable 
     399 *  and PJLIB should not try to access the Symbian socket API (especially ones 
     400 *  that send packets). Sending packet when RConnection is reconnected to  
     401 *  different access point may cause the WaitForRequest() for the function to  
     402 *  block indefinitely. 
     403 *   
     404 *  @param up           If set to PJ_FALSE it will cause PJLIB to not try 
     405 *                      to access socket API, and error will be returned 
     406 *                      immediately instead. 
     407 */ 
     408PJ_DECL(void) pj_symbianos_set_connection_status(pj_bool_t up); 
    397409 
    398410/** 
  • pjproject/trunk/pjlib/src/pj/addr_resolv_symbian.cpp

    r2394 r2481  
    7272    PJ_ASSERT_RETURN(name && count && ai, PJ_EINVAL); 
    7373 
     74    // Return failure if access point is marked as down by app. 
     75    PJ_SYMBIAN_CHECK_CONNECTION(); 
     76         
    7477    // Get resolver for the specified address family 
    7578    RHostResolver &resv = PjSymbianOS::Instance()->GetResolver(af); 
  • pjproject/trunk/pjlib/src/pj/ioqueue_symbian.cpp

    r2394 r2481  
    636636    TRequestStatus reqStatus; 
    637637 
     638    // Return failure if access point is marked as down by app. 
     639    PJ_SYMBIAN_CHECK_CONNECTION(); 
     640     
    638641    // Convert address 
    639642    status = PjSymbianOS::pj2Addr(*(const pj_sockaddr*)addr, addrlen,  
     
    748751    PJ_ASSERT_RETURN((flags & PJ_IOQUEUE_ALWAYS_ASYNC)==0, PJ_EINVAL); 
    749752 
     753    // Return failure if access point is marked as down by app. 
     754    PJ_SYMBIAN_CHECK_CONNECTION(); 
     755 
    750756    // Clear flag 
    751757    flags &= ~PJ_IOQUEUE_ALWAYS_ASYNC; 
     
    786792    PJ_ASSERT_RETURN((flags & PJ_IOQUEUE_ALWAYS_ASYNC)==0, PJ_EINVAL); 
    787793 
     794    // Return failure if access point is marked as down by app. 
     795    PJ_SYMBIAN_CHECK_CONNECTION(); 
     796 
    788797    // Convert address 
    789798    status = PjSymbianOS::pj2Addr(*(const pj_sockaddr*)addr, addrlen,  
  • pjproject/trunk/pjlib/src/pj/os_core_symbian.cpp

    r2394 r2481  
    152152 
    153153PjSymbianOS::PjSymbianOS() 
    154 : isSocketServInitialized_(false), isResolverInitialized_(false), 
     154: isConnectionUp_(false), 
     155  isSocketServInitialized_(false), isResolverInitialized_(false), 
    155156  console_(NULL), selectTimeoutTimer_(NULL), 
    156157  appSocketServ_(NULL), appConnection_(NULL), appHostResolver_(NULL), 
     
    230231    } 
    231232 
     233    isConnectionUp_ = true; 
     234     
    232235    return KErrNone; 
    233236 
     
    240243void PjSymbianOS::Shutdown() 
    241244{ 
     245    isConnectionUp_ = false; 
     246     
    242247    if (isResolverInitialized_) { 
    243248                hostResolver_.Close(); 
     
    253258    } 
    254259 
    255     if (console_) { 
    256         delete console_; 
    257         console_ = NULL; 
    258     } 
    259  
    260     if (selectTimeoutTimer_) { 
    261         delete selectTimeoutTimer_; 
    262         selectTimeoutTimer_ = NULL; 
    263     } 
     260    delete console_; 
     261    console_ = NULL; 
     262 
     263    delete selectTimeoutTimer_; 
     264    selectTimeoutTimer_ = NULL; 
     265     
     266    appSocketServ_ = NULL; 
     267    appConnection_ = NULL; 
     268    appHostResolver_ = NULL; 
     269    appHostResolver6_ = NULL; 
    264270} 
    265271 
     
    304310    PjSymbianOS::Instance()->SetParameters(prm); 
    305311    return PJ_SUCCESS; 
     312} 
     313 
     314 
     315/* Set connection status */ 
     316PJ_DEF(void) pj_symbianos_set_connection_status(pj_bool_t up) 
     317{ 
     318    PjSymbianOS::Instance()->SetConnectionStatus(up != 0); 
    306319} 
    307320 
  • pjproject/trunk/pjlib/src/pj/os_symbian.h

    r2394 r2481  
    314314    } 
    315315 
     316    // 
     317    // Return true if the access point connection is up 
     318    // 
     319    bool IsConnectionUp() const 
     320    { 
     321        return isConnectionUp_; 
     322    } 
     323 
     324    // 
     325    // Set access point connection status 
     326    // 
     327    void SetConnectionStatus(bool up) 
     328    { 
     329        isConnectionUp_ = up; 
     330    } 
    316331 
    317332    // 
     
    354369 
    355370private: 
     371    bool isConnectionUp_; 
     372     
    356373    bool isSocketServInitialized_; 
    357374    RSocketServ socketServ_; 
     
    375392}; 
    376393 
     394// This macro is used to check the access point connection status and return 
     395// failure if the AP connection is down or unusable. See the documentation 
     396// of pj_symbianos_set_connection_status() for more info 
     397#define PJ_SYMBIAN_CHECK_CONNECTION() \ 
     398    PJ_SYMBIAN_CHECK_CONNECTION2(PJ_ECANCELLED) 
     399 
     400#define PJ_SYMBIAN_CHECK_CONNECTION2(retval) \ 
     401    do { \ 
     402        if (!PjSymbianOS::Instance()->IsConnectionUp()) \ 
     403            return retval; \ 
     404    } while (0); 
    377405 
    378406#endif  /* __OS_SYMBIAN_H__ */ 
  • pjproject/trunk/pjlib/src/pj/sock_symbian.cpp

    r2394 r2481  
    464464        THostName tmpName; 
    465465 
     466        // Return empty hostname if access point is marked as down by app. 
     467        PJ_SYMBIAN_CHECK_CONNECTION2(&hostname); 
     468 
    466469        resv.GetHostName(tmpName, reqStatus); 
    467470        User::WaitForRequest(reqStatus); 
     
    489492    PJ_ASSERT_RETURN(p_sock!=NULL, PJ_EINVAL); 
    490493 
     494    // Return failure if access point is marked as down by app. 
     495    PJ_SYMBIAN_CHECK_CONNECTION(); 
     496     
    491497    /* Set proto if none is specified. */ 
    492498    if (proto == 0) { 
     
    643649    PJ_ASSERT_RETURN(sock && buf && len, PJ_EINVAL); 
    644650 
     651    // Return failure if access point is marked as down by app. 
     652    PJ_SYMBIAN_CHECK_CONNECTION(); 
     653     
    645654    CPjSocket *pjSock = (CPjSocket*)sock; 
    646655    RSocket &rSock = pjSock->Socket(); 
     
    679688    PJ_ASSERT_RETURN(sock && buf && len, PJ_EINVAL); 
    680689 
     690    // Return failure if access point is marked as down by app. 
     691    PJ_SYMBIAN_CHECK_CONNECTION(); 
     692     
    681693    CPjSocket *pjSock = (CPjSocket*)sock; 
    682694    RSocket &rSock = pjSock->Socket(); 
     
    717729    PJ_ASSERT_RETURN(sock && buf && len, PJ_EINVAL); 
    718730    PJ_ASSERT_RETURN(*len > 0, PJ_EINVAL); 
     731 
     732    // Return failure if access point is marked as down by app. 
     733    PJ_SYMBIAN_CHECK_CONNECTION(); 
    719734 
    720735    CPjSocket *pjSock = (CPjSocket*)sock; 
     
    771786    PJ_ASSERT_RETURN(*len > 0, PJ_EINVAL); 
    772787    PJ_ASSERT_RETURN(*fromlen >= (int)sizeof(pj_sockaddr_in), PJ_EINVAL); 
     788 
     789    // Return failure if access point is marked as down by app. 
     790    PJ_SYMBIAN_CHECK_CONNECTION(); 
    773791 
    774792    CPjSocket *pjSock = (CPjSocket*)sock; 
     
    869887                     PJ_EINVAL); 
    870888 
     889    // Return failure if access point is marked as down by app. 
     890    PJ_SYMBIAN_CHECK_CONNECTION(); 
     891     
    871892    CPjSocket *pjSock = (CPjSocket*)sock; 
    872893    RSocket &rSock = pjSock->Socket(); 
  • pjproject/trunk/pjsip-apps/src/symbian_ua/ua.cpp

    r2394 r2481  
    442442public: 
    443443    ConsoleUI(CConsoleBase *con); 
     444    ~ConsoleUI(); 
    444445 
    445446    // Run console UI 
     
    467468} 
    468469 
     470ConsoleUI::~ConsoleUI()  
     471{ 
     472    Stop(); 
     473} 
     474 
    469475// Run console UI 
    470476void ConsoleUI::Run()  
     
    477483void ConsoleUI::Stop()  
    478484{ 
    479     DoCancel(); 
     485    Cancel(); 
    480486} 
    481487 
     
    731737 
    732738 
     739// Class CConnMon to monitor network connection (RConnection). Whenever 
     740// the connection is down, it will notify PJLIB and restart PJSUA-LIB. 
     741class CConnMon : public CActive { 
     742public: 
     743    static CConnMon* NewL(RConnection &conn, RSocketServ &sserver) { 
     744        CConnMon *self = new (ELeave) CConnMon(conn, sserver); 
     745        CleanupStack::PushL(self); 
     746        self->ConstructL(); 
     747        CleanupStack::Pop(self); 
     748        return self; 
     749    } 
     750     
     751    void Start() { 
     752        conn_.ProgressNotification(nif_progress_, iStatus); 
     753        SetActive(); 
     754    } 
     755     
     756    void Stop() { 
     757        Cancel(); 
     758    } 
     759     
     760    ~CConnMon() { Stop(); } 
     761     
     762private: 
     763    CConnMon(RConnection &conn, RSocketServ &sserver) :  
     764        CActive(EPriorityHigh),  
     765        conn_(conn),  
     766        sserver_(sserver) 
     767    { 
     768        CActiveScheduler::Add(this); 
     769    } 
     770     
     771    void ConstructL() {} 
     772 
     773    void DoCancel() { 
     774        conn_.CancelProgressNotification(); 
     775    } 
     776 
     777    void RunL() { 
     778        int stage = nif_progress_().iStage; 
     779         
     780        if (stage == KLinkLayerClosed) { 
     781            pj_status_t status; 
     782            TInt err; 
     783 
     784            // Tell pjlib that connection is down. 
     785            pj_symbianos_set_connection_status(PJ_FALSE); 
     786             
     787            PJ_LOG(3, (THIS_FILE, "RConnection closed, restarting PJSUA..")); 
     788             
     789            // Destroy pjsua 
     790            pjsua_destroy(); 
     791            PJ_LOG(3, (THIS_FILE, "PJSUA destroyed.")); 
     792 
     793            // Reopen the connection 
     794            err = conn_.Open(sserver_); 
     795            if (err == KErrNone) 
     796                err = conn_.Start(); 
     797            if (err != KErrNone) { 
     798                CActiveScheduler::Stop(); 
     799                return; 
     800            } 
     801 
     802            // Reinit Symbian OS param before pj_init() 
     803            pj_symbianos_params sym_params; 
     804            pj_bzero(&sym_params, sizeof(sym_params)); 
     805            sym_params.rsocketserv = &sserver_; 
     806            sym_params.rconnection = &conn_; 
     807            pj_symbianos_set_params(&sym_params); 
     808 
     809            // Reinit pjsua 
     810            status = app_startup(); 
     811            if (status != PJ_SUCCESS) { 
     812                pjsua_perror(THIS_FILE, "app_startup() error", status); 
     813                CActiveScheduler::Stop(); 
     814                return; 
     815            } 
     816             
     817            PJ_LOG(3, (THIS_FILE, "PJSUA restarted.")); 
     818            PrintMenu(); 
     819        } 
     820         
     821        Start(); 
     822    } 
     823     
     824    RConnection& conn_; 
     825    RSocketServ& sserver_; 
     826    TNifProgressBuf nif_progress_; 
     827}; 
     828 
    733829//////////////////////////////////////////////////////////////////////////// 
    734830int ua_main()  
     
    773869    } 
    774870 
     871     
    775872    // Run the UI 
    776873    ConsoleUI *con = new ConsoleUI(console); 
     
    779876    PrintMenu(); 
    780877 
     878    // Init & start connection monitor 
     879    CConnMon *connmon = CConnMon::NewL(aConn, aSocketServer); 
     880    connmon->Start(); 
     881 
    781882    CActiveScheduler::Start(); 
    782883     
     884    delete connmon; 
    783885    delete con; 
    784886 
  • pjproject/trunk/pjsip/src/pjsua-lib/pjsua_core.c

    r2448 r2481  
    836836 
    837837    do { 
    838         while (pjsua_handle_events(10) > 0) 
    839             ; 
     838        int i; 
     839        i = msec / 10; 
     840        while (pjsua_handle_events(10) > 0 && i > 0) 
     841            --i; 
    840842        pj_gettimeofday(&now); 
    841843    } while (PJ_TIME_VAL_LT(now, timeout)); 
Note: See TracChangeset for help on using the changeset viewer.