Can we poll with keepalive event on a socket fd after the accept?

Viewed 39

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, &currentInfo);

mySocket = socket(&currentInfo.ai_family, &currentInfo.ai_socktype, &currentInfo.ai_protocol);

setsockopt(mySocket, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt));

bind(mySocket, &currentInfo.ai_addr, &currentInfo.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 ?

0 Answers
Related