What happened to tcp flag URGENT, MSG_OOB and SIGURG?
Nobody today uses tcp urgent mode, so it's good topic to make some research on.
Usually when socket receives tcp packet with URG flag it treats it as normal tcp data. recv() is going to read urgent data as it was normal tcp stream. The only difference is that the last byte of data is discarded. The last byte in urgent data was always a problem due to incoherent rfc.
Pseudocode for this case:
server: send("ab", MSG_OOB)Tcp urgent packets whould trigger SIGURG for process that's listening on socket. It doesn't work until we set process pid of socket owner (thanks MichaĆ for this tip).
client: recv() -> "a"
if (fcntl(sd, F_SETOWN, getpid()) < 0) {The interesting thing is that after we enabled SIGURG it's possible to send a signal to remote process without sending any valid data. Such situation occures when process receives tcp URG packet with one byte payload. The only byte is discarded, no data is waiting on a socket, but SIGURG is sent to a process.
perror("fcntl()");
exit(-1);
}
client: signal(SIGURG, handler);That's all. Feel free to use draft source code of client and server I used for testing.
client: fcntl(sd, F_SETOWN, getpid());
client: poll([sd], 1, 1000);
server: send("a", MSG_OOB);
client: signal SIGURG is received by a handler
client: poll ends, because of received signal
client: but there aren't any data waiting on a socket