Hard
TCP_CORK and TCP_NODELAY across a bulk and a latency-sensitive socket
A server handles two very different workloads on separate sockets: (1) streaming a large file, where a header and payload are written via several small write() calls that should ideally coalesce into full, efficiently-packed segments; and (2) a latency-sensitive tick stream, where every small message must hit the wire immediately. Which socket option suits which workload, and how do TCP_CORK and TCP_NODELAY relate?
main.cpp
// Workload 1: bulk file transfer
int one = 1, zero = 0;
setsockopt(fileSock, IPPROTO_TCP, TCP_CORK, &one, sizeof(one));
write(fileSock, header, headerLen);
write(fileSock, payload, payloadLen);
setsockopt(fileSock, IPPROTO_TCP, TCP_CORK, &zero, sizeof(zero)); // flush
// Workload 2: tick stream
setsockopt(tickSock, IPPROTO_TCP, TCP_NODELAY, &one, sizeof(one));
write(tickSock, &tick, sizeof(tick));27 of 45 in Networking