c - SO_KEEPALIVE and poll -
hello try use following code, seems not working, on connected socket (sock) do:
struct pollfd input_fd; int a=1; setsockopt(sock,sol_socket,so_keepalive,&a,sizeof(a)); a=1; setsockopt(sock,sol_tcp,tcp_keepidle,&a,sizeof(a)); a=1; setsockopt(sock,sol_tcp,tcp_keepintvl,&a,sizeof(a)); a=1; setsockopt(sock,sol_tcp,tcp_keepcnt,&a,sizeof(a)); input_fd.fd = sock; input_fd.events = pollin | pollout; input_fd.revents = 0; int p=poll(&input_fd, 1,-1);
i pull lan plug remote computer, nothing happens. kernel seems sleeping in poll syscall. desired behaviour, or defect?
set nfds:
int p=poll(&input_fd, sock+1 ,-1);
also, i'm not sure of allowed range of settings, it's worth check return value of setsockopt
.
Comments
Post a Comment