My main goal is to detect if my client connected to my server is here and responding. Hence I have developed this server socket (without error handling it is purely experimental):
int opt = 1;
memset(&myServerInfo, 0, sizeof(myServerInfo));
// AF_INER = IPV4
myServerInfo.ai_family = AF_INET;
// TCP
myServerInfo.ai_socktype = SOCK_STREAM;
// Make the socket suitable for binding
myServerInfo.ai_flags = AI_PASSIVE;
getaddrinfo(NULL, SERVER_PORT, &myServerInfo, ¤tInfo);
mySocket = socket(¤tInfo.ai_family, ¤tInfo.ai_socktype, ¤tInfo.ai_protocol);
setsockopt(mySocket, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt));
bind(mySocket, ¤tInfo.ai_addr, ¤tInfo.ai_addrlen);
listen(mySocket, MAX_PENDING_CONNECTIONS);
myDataSocket = accept(mySocket, (struct sockaddr *)&their_addr, &addr_size);
setsockopt(myDataSocket, SOL_SOCKET, SO_KEEPALIVE, &opt, sizeof(opt));
With the option byte SO_KEEPALIVE (in the setsockopt()) I want my server to ask my client continuously if he's here.
By setting this option I was wondering what is the poll() event that can trigger my poll when my client doesn't respond to my keepalives ?