一些常用的选项,供参考
[C]
纯文本查看 复制代码
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 failedn"); 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;}
一些常用的选项,供参考
[C] 纯文本查看 复制代码
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 failedn"); 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;}
举报