Zero-copy network transmission with io_uring
Zero-copy network transmission with io_uring
Posted Dec 31, 2021 16:31 UTC (Fri) by Sesse (subscriber, #53779)In reply to: Zero-copy network transmission with io_uring by jezuch
Parent article: Zero-copy network transmission with io_uring
char buf[256];
int len = snprintf(buf, sizeof(buf), "GET / HTTP/1.1\r\nHost: www.lwn.net\r\n\r\n");
int ret = send(sock, buf, len, MSG_ZEROCOPY);
Now you cannot return from the function safely! Because the kernel holds a pointer into your stack (the buf variable) all the way until it's received an ACK from the other side of the world,. With default flags (no MSG_ZEROCOPY), you can do whatever you want with buf the nanosecond the send() call returns, because it's taken a copy of your data for you.
