| 233 | == Disconnection detection == |
| 234 | For TCP/TLS, you can enable socket keep-alive parameters via {{{pjsua_transport_config.sockopt_params}}} to detect if there is a disconnection. The below code has been reported to work on iOS (30s timeout). |
| 235 | {{{ |
| 236 | static int time=30, probe=5, interval=1, enable=1; |
| 237 | cfg.sockopt_params.cnt = 4; |
| 238 | cfg.sockopt_params.options[0].level = pj_SOL_TCP(); |
| 239 | cfg.sockopt_params.options[0].optname = TCP_KEEPIDLE; |
| 240 | cfg.sockopt_params.options[0].optval = &time; |
| 241 | cfg.sockopt_params.options[0].optlen = sizeof(time); |
| 242 | |
| 243 | cfg.sockopt_params.options[1].level = pj_SOL_TCP(); |
| 244 | cfg.sockopt_params.options[1].optname = TCP_KEEPINTVL; |
| 245 | cfg.sockopt_params.options[1].optval = &interval; |
| 246 | cfg.sockopt_params.options[1].optlen = sizeof(interval); |
| 247 | |
| 248 | cfg.sockopt_params.options[2].level = pj_SOL_TCP(); |
| 249 | cfg.sockopt_params.options[2].optname = TCP_KEEPCNT; |
| 250 | cfg.sockopt_params.options[2].optval = &probe; |
| 251 | cfg.sockopt_params.options[2].optlen = sizeof(probe); |
| 252 | |
| 253 | cfg.sockopt_params.options[3].level = pj_SOL_SOCKET(); |
| 254 | cfg.sockopt_params.options[3].optname = SO_KEEPALIVE; |
| 255 | cfg.sockopt_params.options[3].optval = &enable; |
| 256 | cfg.sockopt_params.options[3].optlen = sizeof(enable); |
| 257 | }}} |