On 31/10/2010, at 4:15 AM, john skaller wrote: > The felix webserver is now up and running: > > http://184.106.135.43:1234/ >
This is now working well for me with a --close-delay=20.0, which means my connection isn't shutdown for 20 seconds after the last write. The delay preceds a shutdown() and close() on the socket. I'm wondering if I can shutdown() immediately, and just delay the close. I am guessing not, I think the RST sent by shutdown() is out-of-band, that is, it is sent immediately rather than being buffered. Anyone know? I am curious how any webservers work at all. Curl uses async I/O. What we actually want to do is delay "up to" a certain time before shutdown/close, but close earlier if the buffers have been emptied, or the connection broke. Certainly close on a blocking socket can do this with flag SO_LINGER (added just for this purpose), unfortunately that doesn't work with async (O_NONBLOCK) sockets. On my Mac I seem to have a getsockopt flag: SO_NWRITE which allows determining if the system buffers are empty yet. Unfortunately, this option is not in Posix, or, it seems, Linux. With this flag a polling loop with a timed delay could be written, to determine when it is safe to close the socket. Grrr.. :) Hmm .. those man pages and Open Groups docs are very confused. According to Linux manpage, a close() will normally return immediately and send remaining data in the background *unless* SO_LINGER is active in which case the close blocks until the data is sent or the timeout expires. But according to Posix[OB XSR]: If the O_NONBLOCK flag is set, or if there are any pending signals, close() shall not wait for output to drain, and shall dismantle the STREAM immediately. And also: When there is an outstanding cancelable asynchronous I/O operation against fildes when close() is called, that I/O operation may be canceled. An I/O operation that is not canceled completes as if the close() operation had not yet occurred. All operations that are not canceled shall complete as if the close() blocked until the operations completed. The close() operation itself need not block awaiting such I/O completion. Whether any I/O operation is canceled, and which I/O operation may be canceled upon close(), is implementation-defined. But it also says: If fildes refers to a socket, close() shall cause the socket to be destroyed. If the socket is in connection-mode, and the SO_LINGER option is set for the socket with non-zero linger time, and the socket has untransmitted data, then close() shall block for up to the current linger interval until all data is transmitted. So it is very confused: on Linux it seems close does not block if the socket is O_NONBLOCK, no matter what the value of SO_LINGER (SO_LINGER is just ignored for O_NONBLOCK on Linux as far as I can tell). -- john skaller skal...@users.sourceforge.net ------------------------------------------------------------------------------ Nokia and AT&T present the 2010 Calling All Innovators-North America contest Create new apps & games for the Nokia N8 for consumers in U.S. and Canada $10 million total in prizes - $4M cash, 500 devices, nearly $6M in marketing Develop with Nokia Qt SDK, Web Runtime, or Java and Publish to Ovi Store http://p.sf.net/sfu/nokia-dev2dev _______________________________________________ Felix-language mailing list Felix-language@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/felix-language