summaryrefslogtreecommitdiffstats
path: root/sys/kern/sys_socket.c
diff options
context:
space:
mode:
authorphk <phk@FreeBSD.org>2009-06-28 11:28:14 +0000
committerphk <phk@FreeBSD.org>2009-06-28 11:28:14 +0000
commited08f853a1af78b712c83924957402ea1a1cf56c (patch)
tree12880e3a07e15788493652721212c558d8c339f1 /sys/kern/sys_socket.c
parent73ae1e3978fb839f852978f567e2cf682e501b57 (diff)
downloadFreeBSD-src-ed08f853a1af78b712c83924957402ea1a1cf56c.zip
FreeBSD-src-ed08f853a1af78b712c83924957402ea1a1cf56c.tar.gz
There are a number of ways an application can check if there are
inbound data waiting on a filedescriptor, such as a pipe or a socket, for instance by using select(2), poll(2), kqueue(2), ioctl(FIONREAD) etc. But we have no way of finding out if written data have yet to be disposed of, for instance, transmitted (and ack'ed!) to some remote host, or read by the applicantion at the far end of the pipe. The closest we get, is calling shutdown(2) on a TCP socket in non-blocking mode, but this has the undesirable sideeffect of preventing future communication. Add a complement to FIONREAD, called FIONWRITE, which returns the number of bytes not yet properly disposed of. Implement it for all sockets. Background: A HTTP server will want to time out connections, if no new request arrives within a certain period after the last transmitted response has actually been sent (and ack'ed). For a busy HTTP server, this timeout can be subsecond duration. In order to signal to a load-balancer that the connection is truly dead, TCP_RST will be the preferred method, as this avoids the need for a RTT delay for FIN handshaking, with a client which, surprisingly often, no longer at the remote IP number. If a slow, distant client is being served a response which is big enough to fill the window, but small enough to fit in the socket buffer, the write(2) call will return immediately. If the session timeout is armed at that time, all bytes in the response may not have been transmitted by the time it fires. FIONWRITE allows the timeout to check that no data is outstanding on the connection, before it TCP_RST's it. Input & Idea from: rwatson Approved by: re (kib)
Diffstat (limited to 'sys/kern/sys_socket.c')
-rw-r--r--sys/kern/sys_socket.c5
1 files changed, 5 insertions, 0 deletions
diff --git a/sys/kern/sys_socket.c b/sys/kern/sys_socket.c
index 93da80d..ecfb4ad 100644
--- a/sys/kern/sys_socket.c
+++ b/sys/kern/sys_socket.c
@@ -169,6 +169,11 @@ soo_ioctl(struct file *fp, u_long cmd, void *data, struct ucred *active_cred,
*(int *)data = so->so_rcv.sb_cc;
break;
+ case FIONWRITE:
+ /* Unlocked read. */
+ *(int *)data = so->so_snd.sb_cc;
+ break;
+
case FIOSETOWN:
error = fsetown(*(int *)data, &so->so_sigio);
break;
OpenPOWER on IntegriCloud