Date: Tue, 8 May 2001 23:32:41 -0700 From: "Jonathan Graehl" <jonathan@graehl.org> To: "'Garrett Wollman'" <wollman@khavrinen.lcs.mit.edu> Cc: <freebsd-net@freebsd.org> Subject: RE: Do I need to close after shutdown if I don't want to leak descriptors? (making sure TCP retransmits all my data) Message-ID: <000b01c0d851$dca62340$6dfeac40@straylight.com> In-Reply-To: <200105081923.PAA64300@khavrinen.lcs.mit.edu>
next in thread | previous in thread | raw e-mail | index | archive | help
> > Problem: close() does not perform an orderly shutdown, does > not resend > > unacknowledged data - responds with RST to data/acks sent to me > > I suggest that this is a bug. That is my feeling as well. I am well aware that depending on the transport layer to ensure delivery of the "last word" does not obviate end-to-end application acknowledgment, but honestly, if I really wanted to improperly terminate a TCP connection, I already have that option with SO_LINGER and a 0 linger time. By default (without messing with SO_LINGER), a close() on a TCP connection should do the right thing (keep the send socket buffer around and retransmit until all is acknowledged; and accept, acknowledge, and discard data). However, I believe that FreeBSD is not alone in this shortcoming, so it would really only be a platform-specific optimization (one that is unnecessary if you use application level acknowledgments), saving two syscalls and some user bookkeeping per socket termination. > > > Incomplete solution: shutdown(SHUT_RDWR), but then what? > Will the OS > > close the fd for me once the other end acknowledges, or better yet, > > closes its end as well, or do I need to close the fd? > > No, you still have to close. > > > (selecting for readable is not a solution; if they have > > sent me data I am uninterested in reading, I will select readable) > > selecting for an exception *should* do what you want, but > doesn't (this is also a bug). There is no such concept (EVFILT_EXCEPTION?) for kqueue, although waiting for the socket to be writable with the low water mark = size of entire buffer, as suggested by Alfred, does let me ensure that all the data was acknowledged before closing (it does not tell me that they have closed the connection, though) (waiting for the buffer to drain can be done using NOTE_LOWAT in kqueue, although you have to getsockopt(SO_SNDBUF) per fd since the size can vary between remote and local sockets). -Jon To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-net" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?000b01c0d851$dca62340$6dfeac40>