Ignore:
Timestamp:
Aug 27, 2010 6:46:29 AM (14 years ago)
Author:
ming
Message:

Closed ticket #1107: iOS4 background feature

  • pjlib:
    • add support for activesock TCP to work in background mode.
    • add feature in ioqueue to recreate closed UDP sockets.
  • pjsip-apps:
    • ipjsua: add support for iPhone OS 4 background mode
    • ipjsystest: add support for iPhone OS 4 background mode
File:
1 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjlib/src/pj/activesock.c

    r2980 r3299  
    2222#include <pj/assert.h> 
    2323#include <pj/errno.h> 
     24#include <pj/log.h> 
    2425#include <pj/pool.h> 
    2526#include <pj/sock.h> 
    2627#include <pj/string.h> 
     28 
     29#if defined(PJ_IPHONE_OS_HAS_MULTITASKING_SUPPORT) && \ 
     30    PJ_IPHONE_OS_HAS_MULTITASKING_SUPPORT!=0 
     31#   include <CFNetwork/CFNetwork.h> 
     32#endif 
    2733 
    2834#define PJ_ACTIVESOCK_MAX_LOOP      50 
     
    7278    unsigned             max_loop; 
    7379    pj_activesock_cb     cb; 
    74  
     80#if defined(PJ_IPHONE_OS_HAS_MULTITASKING_SUPPORT) && \ 
     81    PJ_IPHONE_OS_HAS_MULTITASKING_SUPPORT!=0 
     82    int                  bg_setting; 
     83    pj_sock_t            sock; 
     84    CFReadStreamRef      readStream; 
     85#endif 
     86     
    7587    struct send_data     send_data; 
    7688 
     
    106118} 
    107119 
     120#if defined(PJ_IPHONE_OS_HAS_MULTITASKING_SUPPORT) && \ 
     121    PJ_IPHONE_OS_HAS_MULTITASKING_SUPPORT!=0 
     122static void activesock_destroy_iphone_os_stream(pj_activesock_t *asock) 
     123{ 
     124    if (asock->readStream) { 
     125        CFReadStreamClose(asock->readStream); 
     126        CFRelease(asock->readStream); 
     127        asock->readStream = NULL; 
     128    } 
     129} 
     130 
     131static void activesock_create_iphone_os_stream(pj_activesock_t *asock) 
     132{ 
     133    if (asock->bg_setting && asock->stream_oriented) { 
     134        activesock_destroy_iphone_os_stream(asock); 
     135 
     136        CFStreamCreatePairWithSocket(kCFAllocatorDefault, asock->sock, 
     137                                     &asock->readStream, NULL); 
     138 
     139        if (!asock->readStream || 
     140            CFReadStreamSetProperty(asock->readStream, 
     141                                    kCFStreamNetworkServiceType, 
     142                                    kCFStreamNetworkServiceTypeVoIP) 
     143            != TRUE || 
     144            CFReadStreamOpen(asock->readStream) != TRUE) 
     145        { 
     146            PJ_LOG(2,("", "Failed to configure TCP transport for VoIP " 
     147                      "usage. Background mode will not be supported.")); 
     148             
     149            activesock_destroy_iphone_os_stream(asock); 
     150        } 
     151    } 
     152} 
     153 
     154 
     155PJ_DEF(void) pj_activesock_set_iphone_os_bg(pj_activesock_t *asock, 
     156                                            int val) 
     157{ 
     158    asock->bg_setting = val; 
     159    if (asock->bg_setting) 
     160        activesock_create_iphone_os_stream(asock); 
     161    else 
     162        activesock_destroy_iphone_os_stream(asock); 
     163} 
     164#endif 
    108165 
    109166PJ_DEF(pj_status_t) pj_activesock_create( pj_pool_t *pool, 
     
    157214    } 
    158215 
     216#if defined(PJ_IPHONE_OS_HAS_MULTITASKING_SUPPORT) && \ 
     217    PJ_IPHONE_OS_HAS_MULTITASKING_SUPPORT!=0 
     218    asock->sock = sock; 
     219    pj_activesock_set_iphone_os_bg(asock, 
     220                                   PJ_ACTIVESOCK_TCP_IPHONE_OS_BG); 
     221#endif 
     222 
    159223    *p_asock = asock; 
    160224    return PJ_SUCCESS; 
     
    216280    PJ_ASSERT_RETURN(asock, PJ_EINVAL); 
    217281    if (asock->key) { 
     282#if defined(PJ_IPHONE_OS_HAS_MULTITASKING_SUPPORT) && \ 
     283    PJ_IPHONE_OS_HAS_MULTITASKING_SUPPORT!=0 
     284        activesock_destroy_iphone_os_stream(asock); 
     285#endif   
     286         
    218287        pj_ioqueue_unregister(asock->key); 
    219288        asock->key = NULL; 
     
    734803                return; 
    735804 
     805#if defined(PJ_IPHONE_OS_HAS_MULTITASKING_SUPPORT) && \ 
     806    PJ_IPHONE_OS_HAS_MULTITASKING_SUPPORT!=0 
     807            activesock_create_iphone_os_stream(asock); 
     808#endif 
    736809        } else if (status==PJ_SUCCESS) { 
    737810            /* Application doesn't handle the new socket, we need to  
     
    776849            return; 
    777850        } 
     851         
     852#if defined(PJ_IPHONE_OS_HAS_MULTITASKING_SUPPORT) && \ 
     853    PJ_IPHONE_OS_HAS_MULTITASKING_SUPPORT!=0 
     854        activesock_create_iphone_os_stream(asock); 
     855#endif 
     856         
    778857    } 
    779858} 
Note: See TracChangeset for help on using the changeset viewer.