POSIX Sockets: How to detect Ctrl-C sent via Telnet?

Short question
What is the correct way to handle the Ctrl-C event sent via Telnet on the server side?

Debt issue
After calling recv () on a socket, I would like to handle some situations accordingly. One of them is to return an error code when Ctrl-C was received. What is the right way to detect this? The following works, but it just doesn't seem right:

size_t recv_count;
static char ctrl_c[5] = {0xff, 0xf4, 0xff, 0xfd, 0x06};

recv_count = recv(socket, buffer, buffer_size, 0);

if (recv_count == sizeof(ctrl_c) &&
    memcmp(buffer, ctrl_c, sizeof(ctrl_c) == 0)
{
    return CTRL_C_RECEIVED;
}

I found a comment on Ctrl-C in a note in this UNIX Socket FAQ:

[...] (by the way, out-of-band is often used for this ctrl-C too).

, recv() . , recv(), , . , - recv() oob-.

+5
1

fcntl(), select() (pselect() ), . , , recv(), send(), . , .

recv() , . ( SO_OOBINLINE) OOB, . ioctl() SIOCATMARK, , - .

OOB, recv() OOB recv(), .

, , ctrl-c - .

+2

All Articles