I have an application that acts as a watchdog for another application. The duty of the watchdog is to monitor the host application existence and respawn it whenever it dies.
Below is the socket code:
sock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
if (sock < 0) {
return (-1);
}
int optval = 1;
struct timeval tv;
tv.tv_sec = SOC_READ_TIMEOUT;
tv.tv_usec = 0;
setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO, (char*) &tv, sizeof(tv));
tv.tv_sec = SOC_READ_TIMEOUT;
tv.tv_usec = 0;
setsockopt(sock, SOL_SOCKET, SO_SNDTIMEO, (char*) &tv, sizeof(tv));
setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (int*) &optval,
sizeof(int));
name.sin_family = AF_INET;
name.sin_port = htons(port);
name.sin_addr.s_addr = htonl(INADDR_ANY);
if (bind(sock, (sockaddr *) &name, sizeof(name)) < 0) {
close(sock);
return (-1);
}
The problem I am facing is that whenever I kill the host application instance. The new instance gives an error "Cannot assign requested address". I believe this is occurring because the Raspbian OS doesn't support SO_REUSEPORT.
Is there any way, I can work this out? Any suggestion is welcome.