论坛元老
- 积分
- 3696
- 金钱
- 3696
- 注册时间
- 2011-5-23
- 在线时间
- 2008 小时
|
发表于 2016-12-20 09:57:16
|
显示全部楼层
一些常用的选项,供参考
[mw_shl_code=c,true]rt_err_t socket_config(void)
{
int keepalive = 1; //Enable keepalive.
int keepidle = 60; //idle time is 60s.
int keepinterval = 5; //sending interval of detective packet
int keepcount = 3; //detective count.
int flag = 1;
if (setsockopt(socket_fd, SOL_SOCKET, SO_KEEPALIVE, (void *)&keepalive, sizeof(keepalive)) < 0)
{
LOG("set Keep-Alive attribute failed\n");
return -RT_ERROR;
}
setsockopt(socket_fd, IPPROTO_TCP, TCP_KEEPIDLE, (void*)&keepidle , sizeof(keepidle));
setsockopt(socket_fd, IPPROTO_TCP, TCP_KEEPINTVL, (void *)&keepinterval , sizeof(keepinterval));
setsockopt(socket_fd, IPPROTO_TCP, TCP_KEEPCNT, (void *)&keepcount , sizeof(keepcount));
setsockopt(socket_fd, IPPROTO_TCP, TCP_NODELAY, (void *)&flag , sizeof(flag));
return RT_EOK;
}
[/mw_shl_code]
|
|