Changeset 1536


Ignore:
Timestamp:
Oct 31, 2007 1:28:08 PM (16 years ago)
Author:
bennylp
Message:

Ticket #407: keep-alive for UDP transports in PJSUA-LIB

Location:
pjproject/trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/build.symbian/pjsua_libU.def

    r1535 r1536  
    33        pjsua_acc_add_local                      @ 2 NONAME 
    44        pjsua_acc_config_default                 @ 3 NONAME 
    5         pjsua_acc_create_request                 @ 4 NONAME 
    6         pjsua_acc_create_uac_contact             @ 5 NONAME 
    7         pjsua_acc_create_uas_contact             @ 6 NONAME 
    8         pjsua_acc_del                            @ 7 NONAME 
    9         pjsua_acc_enum_info                      @ 8 NONAME 
    10         pjsua_acc_find_for_incoming              @ 9 NONAME 
    11         pjsua_acc_find_for_outgoing              @ 10 NONAME 
    12         pjsua_acc_get_count                      @ 11 NONAME 
    13         pjsua_acc_get_default                    @ 12 NONAME 
    14         pjsua_acc_get_info                       @ 13 NONAME 
    15         pjsua_acc_is_valid                       @ 14 NONAME 
    16         pjsua_acc_modify                         @ 15 NONAME 
    17         pjsua_acc_set_default                    @ 16 NONAME 
    18         pjsua_acc_set_online_status              @ 17 NONAME 
    19         pjsua_acc_set_online_status2             @ 18 NONAME 
    20         pjsua_acc_set_registration               @ 19 NONAME 
    21         pjsua_acc_set_transport                  @ 20 NONAME 
    22         pjsua_buddy_add                          @ 21 NONAME 
    23         pjsua_buddy_config_default               @ 22 NONAME 
    24         pjsua_buddy_del                          @ 23 NONAME 
    25         pjsua_buddy_get_info                     @ 24 NONAME 
    26         pjsua_buddy_is_valid                     @ 25 NONAME 
    27         pjsua_buddy_subscribe_pres               @ 26 NONAME 
    28         pjsua_buddy_update_pres                  @ 27 NONAME 
    29         pjsua_call_answer                        @ 28 NONAME 
    30         pjsua_call_dial_dtmf                     @ 29 NONAME 
    31         pjsua_call_dump                          @ 30 NONAME 
    32         pjsua_call_get_conf_port                 @ 31 NONAME 
    33         pjsua_call_get_count                     @ 32 NONAME 
    34         pjsua_call_get_info                      @ 33 NONAME 
    35         pjsua_call_get_max_count                 @ 34 NONAME 
    36         pjsua_call_get_rem_nat_type              @ 35 NONAME 
    37         pjsua_call_get_user_data                 @ 36 NONAME 
    38         pjsua_call_hangup                        @ 37 NONAME 
    39         pjsua_call_hangup_all                    @ 38 NONAME 
    40         pjsua_call_has_media                     @ 39 NONAME 
    41         pjsua_call_is_active                     @ 40 NONAME 
    42         pjsua_call_make_call                     @ 41 NONAME 
    43         pjsua_call_reinvite                      @ 42 NONAME 
    44         pjsua_call_send_im                       @ 43 NONAME 
    45         pjsua_call_send_request                  @ 44 NONAME 
    46         pjsua_call_send_typing_ind               @ 45 NONAME 
    47         pjsua_call_set_hold                      @ 46 NONAME 
    48         pjsua_call_set_user_data                 @ 47 NONAME 
    49         pjsua_call_update                        @ 48 NONAME 
    50         pjsua_call_xfer                          @ 49 NONAME 
    51         pjsua_call_xfer_replaces                 @ 50 NONAME 
    52         pjsua_codec_get_param                    @ 51 NONAME 
    53         pjsua_codec_set_param                    @ 52 NONAME 
    54         pjsua_codec_set_priority                 @ 53 NONAME 
    55         pjsua_conf_add_port                      @ 54 NONAME 
    56         pjsua_conf_adjust_rx_level               @ 55 NONAME 
    57         pjsua_conf_adjust_tx_level               @ 56 NONAME 
    58         pjsua_conf_connect                       @ 57 NONAME 
    59         pjsua_conf_disconnect                    @ 58 NONAME 
    60         pjsua_conf_get_active_ports              @ 59 NONAME 
    61         pjsua_conf_get_max_ports                 @ 60 NONAME 
    62         pjsua_conf_get_port_info                 @ 61 NONAME 
    63         pjsua_conf_get_signal_level              @ 62 NONAME 
    64         pjsua_conf_remove_port                   @ 63 NONAME 
    65         pjsua_config_default                     @ 64 NONAME 
    66         pjsua_config_dup                         @ 65 NONAME 
    67         pjsua_create                             @ 66 NONAME 
    68         pjsua_destroy                            @ 67 NONAME 
    69         pjsua_detect_nat_type                    @ 68 NONAME 
    70         pjsua_dump                               @ 69 NONAME 
    71         pjsua_enum_accs                          @ 70 NONAME 
    72         pjsua_enum_buddies                       @ 71 NONAME 
    73         pjsua_enum_calls                         @ 72 NONAME 
    74         pjsua_enum_codecs                        @ 73 NONAME 
    75         pjsua_enum_conf_ports                    @ 74 NONAME 
    76         pjsua_enum_snd_devs                      @ 75 NONAME 
    77         pjsua_enum_transports                    @ 76 NONAME 
    78         pjsua_get_buddy_count                    @ 77 NONAME 
    79         pjsua_get_ec_tail                        @ 78 NONAME 
    80         pjsua_get_nat_type                       @ 79 NONAME 
    81         pjsua_get_pjmedia_endpt                  @ 80 NONAME 
    82         pjsua_get_pjsip_endpt                    @ 81 NONAME 
    83         pjsua_get_pool_factory                   @ 82 NONAME 
    84         pjsua_get_snd_dev                        @ 83 NONAME 
    85         pjsua_get_var                            @ 84 NONAME 
    86         pjsua_handle_events                      @ 85 NONAME 
    87         pjsua_im_send                            @ 86 NONAME 
    88         pjsua_im_typing                          @ 87 NONAME 
    89         pjsua_init                               @ 88 NONAME 
    90         pjsua_logging_config_default             @ 89 NONAME 
    91         pjsua_logging_config_dup                 @ 90 NONAME 
    92         pjsua_media_config_default               @ 91 NONAME 
    93         pjsua_media_transports_create            @ 92 NONAME 
    94         pjsua_msg_data_init                      @ 93 NONAME 
    95         pjsua_perror                             @ 94 NONAME 
    96         pjsua_player_create                      @ 95 NONAME 
    97         pjsua_player_destroy                     @ 96 NONAME 
    98         pjsua_player_get_conf_port               @ 97 NONAME 
    99         pjsua_player_get_port                    @ 98 NONAME 
    100         pjsua_player_set_pos                     @ 99 NONAME 
    101         pjsua_playlist_create                    @ 100 NONAME 
    102         pjsua_pool_create                        @ 101 NONAME 
    103         pjsua_pres_dump                          @ 102 NONAME 
    104         pjsua_reconfigure_logging                @ 103 NONAME 
    105         pjsua_recorder_create                    @ 104 NONAME 
    106         pjsua_recorder_destroy                   @ 105 NONAME 
    107         pjsua_recorder_get_conf_port             @ 106 NONAME 
    108         pjsua_recorder_get_port                  @ 107 NONAME 
    109         pjsua_set_ec                             @ 108 NONAME 
    110         pjsua_set_no_snd_dev                     @ 109 NONAME 
    111         pjsua_set_null_snd_dev                   @ 110 NONAME 
    112         pjsua_set_snd_dev                        @ 111 NONAME 
    113         pjsua_start                              @ 112 NONAME 
    114         pjsua_transport_close                    @ 113 NONAME 
    115         pjsua_transport_config_default           @ 114 NONAME 
    116         pjsua_transport_config_dup               @ 115 NONAME 
    117         pjsua_transport_create                   @ 116 NONAME 
    118         pjsua_transport_get_info                 @ 117 NONAME 
    119         pjsua_transport_register                 @ 118 NONAME 
    120         pjsua_transport_set_enable               @ 119 NONAME 
    121         pjsua_verify_sip_url                     @ 120 NONAME 
     5        pjsua_acc_config_dup                     @ 4 NONAME 
     6        pjsua_acc_create_request                 @ 5 NONAME 
     7        pjsua_acc_create_uac_contact             @ 6 NONAME 
     8        pjsua_acc_create_uas_contact             @ 7 NONAME 
     9        pjsua_acc_del                            @ 8 NONAME 
     10        pjsua_acc_enum_info                      @ 9 NONAME 
     11        pjsua_acc_find_for_incoming              @ 10 NONAME 
     12        pjsua_acc_find_for_outgoing              @ 11 NONAME 
     13        pjsua_acc_get_count                      @ 12 NONAME 
     14        pjsua_acc_get_default                    @ 13 NONAME 
     15        pjsua_acc_get_info                       @ 14 NONAME 
     16        pjsua_acc_is_valid                       @ 15 NONAME 
     17        pjsua_acc_modify                         @ 16 NONAME 
     18        pjsua_acc_set_default                    @ 17 NONAME 
     19        pjsua_acc_set_online_status              @ 18 NONAME 
     20        pjsua_acc_set_online_status2             @ 19 NONAME 
     21        pjsua_acc_set_registration               @ 20 NONAME 
     22        pjsua_acc_set_transport                  @ 21 NONAME 
     23        pjsua_buddy_add                          @ 22 NONAME 
     24        pjsua_buddy_config_default               @ 23 NONAME 
     25        pjsua_buddy_del                          @ 24 NONAME 
     26        pjsua_buddy_get_info                     @ 25 NONAME 
     27        pjsua_buddy_is_valid                     @ 26 NONAME 
     28        pjsua_buddy_subscribe_pres               @ 27 NONAME 
     29        pjsua_buddy_update_pres                  @ 28 NONAME 
     30        pjsua_call_answer                        @ 29 NONAME 
     31        pjsua_call_dial_dtmf                     @ 30 NONAME 
     32        pjsua_call_dump                          @ 31 NONAME 
     33        pjsua_call_get_conf_port                 @ 32 NONAME 
     34        pjsua_call_get_count                     @ 33 NONAME 
     35        pjsua_call_get_info                      @ 34 NONAME 
     36        pjsua_call_get_max_count                 @ 35 NONAME 
     37        pjsua_call_get_rem_nat_type              @ 36 NONAME 
     38        pjsua_call_get_user_data                 @ 37 NONAME 
     39        pjsua_call_hangup                        @ 38 NONAME 
     40        pjsua_call_hangup_all                    @ 39 NONAME 
     41        pjsua_call_has_media                     @ 40 NONAME 
     42        pjsua_call_is_active                     @ 41 NONAME 
     43        pjsua_call_make_call                     @ 42 NONAME 
     44        pjsua_call_reinvite                      @ 43 NONAME 
     45        pjsua_call_send_im                       @ 44 NONAME 
     46        pjsua_call_send_request                  @ 45 NONAME 
     47        pjsua_call_send_typing_ind               @ 46 NONAME 
     48        pjsua_call_set_hold                      @ 47 NONAME 
     49        pjsua_call_set_user_data                 @ 48 NONAME 
     50        pjsua_call_update                        @ 49 NONAME 
     51        pjsua_call_xfer                          @ 50 NONAME 
     52        pjsua_call_xfer_replaces                 @ 51 NONAME 
     53        pjsua_codec_get_param                    @ 52 NONAME 
     54        pjsua_codec_set_param                    @ 53 NONAME 
     55        pjsua_codec_set_priority                 @ 54 NONAME 
     56        pjsua_conf_add_port                      @ 55 NONAME 
     57        pjsua_conf_adjust_rx_level               @ 56 NONAME 
     58        pjsua_conf_adjust_tx_level               @ 57 NONAME 
     59        pjsua_conf_connect                       @ 58 NONAME 
     60        pjsua_conf_disconnect                    @ 59 NONAME 
     61        pjsua_conf_get_active_ports              @ 60 NONAME 
     62        pjsua_conf_get_max_ports                 @ 61 NONAME 
     63        pjsua_conf_get_port_info                 @ 62 NONAME 
     64        pjsua_conf_get_signal_level              @ 63 NONAME 
     65        pjsua_conf_remove_port                   @ 64 NONAME 
     66        pjsua_config_default                     @ 65 NONAME 
     67        pjsua_config_dup                         @ 66 NONAME 
     68        pjsua_create                             @ 67 NONAME 
     69        pjsua_destroy                            @ 68 NONAME 
     70        pjsua_detect_nat_type                    @ 69 NONAME 
     71        pjsua_dump                               @ 70 NONAME 
     72        pjsua_enum_accs                          @ 71 NONAME 
     73        pjsua_enum_buddies                       @ 72 NONAME 
     74        pjsua_enum_calls                         @ 73 NONAME 
     75        pjsua_enum_codecs                        @ 74 NONAME 
     76        pjsua_enum_conf_ports                    @ 75 NONAME 
     77        pjsua_enum_snd_devs                      @ 76 NONAME 
     78        pjsua_enum_transports                    @ 77 NONAME 
     79        pjsua_get_buddy_count                    @ 78 NONAME 
     80        pjsua_get_ec_tail                        @ 79 NONAME 
     81        pjsua_get_nat_type                       @ 80 NONAME 
     82        pjsua_get_pjmedia_endpt                  @ 81 NONAME 
     83        pjsua_get_pjsip_endpt                    @ 82 NONAME 
     84        pjsua_get_pool_factory                   @ 83 NONAME 
     85        pjsua_get_snd_dev                        @ 84 NONAME 
     86        pjsua_get_var                            @ 85 NONAME 
     87        pjsua_handle_events                      @ 86 NONAME 
     88        pjsua_im_send                            @ 87 NONAME 
     89        pjsua_im_typing                          @ 88 NONAME 
     90        pjsua_init                               @ 89 NONAME 
     91        pjsua_logging_config_default             @ 90 NONAME 
     92        pjsua_logging_config_dup                 @ 91 NONAME 
     93        pjsua_media_config_default               @ 92 NONAME 
     94        pjsua_media_transports_create            @ 93 NONAME 
     95        pjsua_msg_data_init                      @ 94 NONAME 
     96        pjsua_perror                             @ 95 NONAME 
     97        pjsua_player_create                      @ 96 NONAME 
     98        pjsua_player_destroy                     @ 97 NONAME 
     99        pjsua_player_get_conf_port               @ 98 NONAME 
     100        pjsua_player_get_port                    @ 99 NONAME 
     101        pjsua_player_set_pos                     @ 100 NONAME 
     102        pjsua_playlist_create                    @ 101 NONAME 
     103        pjsua_pool_create                        @ 102 NONAME 
     104        pjsua_pres_dump                          @ 103 NONAME 
     105        pjsua_reconfigure_logging                @ 104 NONAME 
     106        pjsua_recorder_create                    @ 105 NONAME 
     107        pjsua_recorder_destroy                   @ 106 NONAME 
     108        pjsua_recorder_get_conf_port             @ 107 NONAME 
     109        pjsua_recorder_get_port                  @ 108 NONAME 
     110        pjsua_set_ec                             @ 109 NONAME 
     111        pjsua_set_no_snd_dev                     @ 110 NONAME 
     112        pjsua_set_null_snd_dev                   @ 111 NONAME 
     113        pjsua_set_snd_dev                        @ 112 NONAME 
     114        pjsua_start                              @ 113 NONAME 
     115        pjsua_transport_close                    @ 114 NONAME 
     116        pjsua_transport_config_default           @ 115 NONAME 
     117        pjsua_transport_config_dup               @ 116 NONAME 
     118        pjsua_transport_create                   @ 117 NONAME 
     119        pjsua_transport_get_info                 @ 118 NONAME 
     120        pjsua_transport_register                 @ 119 NONAME 
     121        pjsua_transport_set_enable               @ 120 NONAME 
     122        pjsua_verify_sip_url                     @ 121 NONAME 
  • pjproject/trunk/pjsip/include/pjsua-lib/pjsua.h

    r1535 r1536  
    17691769 */ 
    17701770#ifndef PJSUA_REG_INTERVAL 
    1771 #   define PJSUA_REG_INTERVAL       55 
     1771#   define PJSUA_REG_INTERVAL       300 
    17721772#endif 
    17731773 
     
    18981898    /**  
    18991899     * Optional interval for registration, in seconds. If the value is zero,  
    1900      * default interval will be used (PJSUA_REG_INTERVAL, 55 seconds). 
     1900     * default interval will be used (PJSUA_REG_INTERVAL, 300 seconds). 
    19011901     */ 
    19021902    unsigned        reg_timeout; 
     
    19481948    pj_bool_t auto_update_nat; 
    19491949 
     1950    /** 
     1951     * Set the interval for periodic keep-alive transmission for this account. 
     1952     * If this value is zero, keep-alive will be disabled for this account. 
     1953     * The keep-alive transmission will be sent to the registrar's address, 
     1954     * after successful registration. 
     1955     * 
     1956     * Even if this setting is enabled, keep-alive transmission is only done 
     1957     * when STUN is enabled in the global #pjsua_config, and the transport 
     1958     * used for registration is UDP. For TCP and TLS transports, keep-alive 
     1959     * is done by the transport themselves. 
     1960     * 
     1961     * Default: 15 (seconds) 
     1962     */ 
     1963    unsigned         ka_interval; 
     1964 
     1965    /** 
     1966     * Specify the data to be transmitted as keep-alive packets. 
     1967     * 
     1968     * Default: CR-LF 
     1969     */ 
     1970    pj_str_t         ka_data; 
     1971 
    19501972} pjsua_acc_config; 
    19511973 
     
    19641986 */ 
    19651987PJ_DECL(void) pjsua_acc_config_default(pjsua_acc_config *cfg); 
     1988 
     1989 
     1990/** 
     1991 * Duplicate account config. 
     1992 * 
     1993 * @param pool      Pool to be used for duplicating the config. 
     1994 * @param dst       Destination configuration. 
     1995 * @param src       Source configuration. 
     1996 */ 
     1997PJ_DECL(void) pjsua_acc_config_dup(pj_pool_t *pool, 
     1998                                   pjsua_acc_config *dst, 
     1999                                   const pjsua_acc_config *src); 
    19662000 
    19672001 
  • pjproject/trunk/pjsip/include/pjsua-lib/pjsua_internal.h

    r1533 r1536  
    8787 
    8888    pjsip_regc      *regc;          /**< Client registration session.   */ 
    89     pj_timer_entry   reg_timer;     /**< Registration timer.            */ 
    9089    pj_status_t      reg_last_err;  /**< Last registration error.       */ 
    9190    int              reg_last_code; /**< Last status last register.     */ 
     91 
     92    pj_timer_entry   ka_timer;      /**< Keep-alive timer for UDP.      */ 
     93    pjsip_transport *ka_transport;  /**< Transport for keep-alive.      */ 
     94    pj_sockaddr      ka_target;     /**< Destination address for K-A    */ 
     95    unsigned         ka_target_len; /**< Length of ka_target.           */ 
    9296 
    9397    pjsip_route_hdr  route_set;     /**< Complete route set inc. outbnd.*/ 
  • pjproject/trunk/pjsip/src/pjsip/sip_transport.c

    r1462 r1536  
    418418{ 
    419419 
     420    if (tdata->info) 
     421        return tdata->info; 
     422 
    420423    if (tdata==NULL || tdata->msg==NULL) 
    421424        return "NULL"; 
    422  
    423     if (tdata->info) 
    424         return tdata->info; 
    425425 
    426426    pj_lock_acquire(tdata->lock); 
     
    653653            return status; 
    654654        } 
     655 
     656        tdata->info = "raw"; 
    655657 
    656658        /* Add reference counter. */ 
  • pjproject/trunk/pjsip/src/pjsua-lib/pjsua_acc.c

    r1520 r1536  
    6565 * Copy account configuration. 
    6666 */ 
    67 static void copy_acc_config(pj_pool_t *pool, 
    68                             pjsua_acc_config *dst, 
    69                             const pjsua_acc_config *src) 
     67PJ_DEF(void) pjsua_acc_config_dup( pj_pool_t *pool, 
     68                                   pjsua_acc_config *dst, 
     69                                   const pjsua_acc_config *src) 
    7070{ 
    7171    unsigned i; 
     
    8888        pjsip_cred_dup(pool, &dst->cred_info[i], &src->cred_info[i]); 
    8989    } 
     90 
     91    dst->ka_interval = src->ka_interval; 
     92    pj_strdup(pool, &dst->ka_data, &src->ka_data); 
    9093} 
    9194 
     
    276279 
    277280    /* Copy config */ 
    278     copy_acc_config(pjsua_var.pool, &pjsua_var.acc[id].cfg, cfg); 
     281    pjsua_acc_config_dup(pjsua_var.pool, &pjsua_var.acc[id].cfg, cfg); 
    279282     
    280283    /* Normalize registration timeout */ 
     
    632635} 
    633636 
     637 
     638/* Keep alive timer callback */ 
     639static void keep_alive_timer_cb(pj_timer_heap_t *th, pj_timer_entry *te) 
     640{ 
     641    pjsua_acc *acc; 
     642    pjsip_tpselector tp_sel; 
     643    pj_time_val delay; 
     644    pj_status_t status; 
     645 
     646    PJ_UNUSED_ARG(th); 
     647 
     648    PJSUA_LOCK(); 
     649 
     650    te->id = PJ_FALSE; 
     651 
     652    acc = (pjsua_acc*) te->user_data; 
     653 
     654    /* Select the transport to send the packet */ 
     655    pj_bzero(&tp_sel, sizeof(tp_sel)); 
     656    tp_sel.type = PJSIP_TPSELECTOR_TRANSPORT; 
     657    tp_sel.u.transport = acc->ka_transport; 
     658 
     659    PJ_LOG(5,(THIS_FILE,  
     660              "Sending %d bytes keep-alive packet for acc %d to %s:%d", 
     661              acc->cfg.ka_data.slen, acc->index, 
     662              pj_inet_ntoa(acc->ka_target.ipv4.sin_addr), 
     663              pj_ntohs(acc->ka_target.ipv4.sin_port))); 
     664 
     665    /* Send raw packet */ 
     666    status = pjsip_tpmgr_send_raw(pjsip_endpt_get_tpmgr(pjsua_var.endpt), 
     667                                  PJSIP_TRANSPORT_UDP, &tp_sel, 
     668                                  NULL, acc->cfg.ka_data.ptr,  
     669                                  acc->cfg.ka_data.slen,  
     670                                  &acc->ka_target, acc->ka_target_len, 
     671                                  NULL, NULL); 
     672 
     673    if (status != PJ_SUCCESS && status != PJ_EPENDING) { 
     674        pjsua_perror(THIS_FILE, "Error sending keep-alive packet", status); 
     675    } 
     676 
     677    /* Reschedule next timer */ 
     678    delay.sec = acc->cfg.ka_interval; 
     679    delay.msec = 0; 
     680    status = pjsip_endpt_schedule_timer(pjsua_var.endpt, te, &delay); 
     681    if (status == PJ_SUCCESS) { 
     682        te->id = PJ_TRUE; 
     683    } else { 
     684        pjsua_perror(THIS_FILE, "Error starting keep-alive timer", status); 
     685    } 
     686 
     687    PJSUA_UNLOCK(); 
     688} 
     689 
     690 
     691/* Update keep-alive for the account */ 
     692static void update_keep_alive(pjsua_acc *acc, pj_bool_t start, 
     693                              struct pjsip_regc_cbparam *param) 
     694{ 
     695    /* In all cases, stop keep-alive timer if it's running. */ 
     696    if (acc->ka_timer.id) { 
     697        pjsip_endpt_cancel_timer(pjsua_var.endpt, &acc->ka_timer); 
     698        acc->ka_timer.id = PJ_FALSE; 
     699 
     700        pjsip_transport_dec_ref(acc->ka_transport); 
     701        acc->ka_transport = NULL; 
     702    } 
     703 
     704    if (start) { 
     705        pj_time_val delay; 
     706        pj_status_t status; 
     707 
     708        /* Only do keep-alive if: 
     709         *  - STUN is enabled in global config, and 
     710         *  - ka_interval is not zero in the account, and 
     711         *  - transport is UDP. 
     712         */ 
     713        if (pjsua_var.stun_srv.ipv4.sin_family == 0 || 
     714            acc->cfg.ka_interval == 0 || 
     715            param->rdata->tp_info.transport->key.type != PJSIP_TRANSPORT_UDP) 
     716        { 
     717            /* Keep alive is not necessary */ 
     718            return; 
     719        } 
     720 
     721        /* Save transport and destination address. */ 
     722        acc->ka_transport = param->rdata->tp_info.transport; 
     723        pjsip_transport_add_ref(acc->ka_transport); 
     724        pj_memcpy(&acc->ka_target, &param->rdata->pkt_info.src_addr, 
     725                  param->rdata->pkt_info.src_addr_len); 
     726        acc->ka_target_len = param->rdata->pkt_info.src_addr_len; 
     727 
     728        /* Setup and start the timer */ 
     729        acc->ka_timer.cb = &keep_alive_timer_cb; 
     730        acc->ka_timer.user_data = (void*)acc; 
     731 
     732        delay.sec = acc->cfg.ka_interval; 
     733        delay.msec = 0; 
     734        status = pjsip_endpt_schedule_timer(pjsua_var.endpt, &acc->ka_timer,  
     735                                            &delay); 
     736        if (status == PJ_SUCCESS) { 
     737            acc->ka_timer.id = PJ_TRUE; 
     738            PJ_LOG(4,(THIS_FILE, "Keep-alive timer started for acc %d, " 
     739                                 "destination:%s:%d, interval:%ds", 
     740                                 acc->index, 
     741                                 param->rdata->pkt_info.src_name, 
     742                                 param->rdata->pkt_info.src_port, 
     743                                 acc->cfg.ka_interval)); 
     744        } else { 
     745            acc->ka_timer.id = PJ_FALSE; 
     746            pjsip_transport_dec_ref(acc->ka_transport); 
     747            acc->ka_transport = NULL; 
     748            pjsua_perror(THIS_FILE, "Error starting keep-alive timer", status); 
     749        } 
     750    } 
     751} 
     752 
     753 
    634754/* 
    635755 * This callback is called by pjsip_regc when outgoing register 
     
    655775        acc->regc = NULL; 
    656776         
     777        /* Stop keep-alive timer if any. */ 
     778        update_keep_alive(acc, PJ_FALSE, NULL); 
     779 
    657780    } else if (param->code < 0 || param->code >= 300) { 
    658781        PJ_LOG(2, (THIS_FILE, "SIP registration failed, status=%d (%.*s)",  
     
    662785        acc->regc = NULL; 
    663786 
     787        /* Stop keep-alive timer if any. */ 
     788        update_keep_alive(acc, PJ_FALSE, NULL); 
     789 
    664790    } else if (PJSIP_IS_STATUS_IN_CLASS(param->code, 200)) { 
    665791 
     
    667793            pjsip_regc_destroy(acc->regc); 
    668794            acc->regc = NULL; 
     795 
     796            /* Stop keep-alive timer if any. */ 
     797            update_keep_alive(acc, PJ_FALSE, NULL); 
     798 
    669799            PJ_LOG(3,(THIS_FILE, "%s: unregistration success", 
    670800                      pjsua_var.acc[acc->index].cfg.id.ptr)); 
     
    687817                       (int)param->reason.slen, param->reason.ptr, 
    688818                       param->expiration)); 
     819 
     820            /* Start keep-alive timer if necessary. */ 
     821            update_keep_alive(acc, PJ_TRUE, param); 
    689822 
    690823            /* Send initial PUBLISH if it is enabled */ 
  • pjproject/trunk/pjsip/src/pjsua-lib/pjsua_core.c

    r1533 r1536  
    141141    cfg->auto_update_nat = PJ_TRUE; 
    142142    cfg->require_100rel = pjsua_var.ua_cfg.require_100rel; 
     143    cfg->ka_interval = 15; 
     144    cfg->ka_data = pj_str("\r\n"); 
    143145} 
    144146 
Note: See TracChangeset for help on using the changeset viewer.