Re: [LIP]blocking accept...
Linux India has been formed for Foster the growth of Linux in India
Brought to you by:
manojmishra,
raju
From: Ashutosh M. <ash...@de...> - 2002-05-29 11:40:50
|
Thanks Varun Thanks a lot for detailed explanation. As you suggested to go through "Unix Network Programming, Volume 1" by Richard Stevens, I went through SO_REUSEADDR and SO_REUSEPORT Socket Options.SO_REUSEADDR allows multiple instances of server to be started on the same port(Though I am not able to run multiple instances even after using SO_REUSEADDR socket option). And it has been recommeded that SO_REUSEADDR socket option should be set before calling bind in all TCP servers. But I was thinking, if my server has to do some work like reading data from some file and modifying some data and writting back to the file, and I am not locking files when I am reading or writting, in that case the file might have inconsistent data in it. In this case I should not allow my server to bind to same address or any alias if one instance of it is already running, and so I should avoid using SO_REUSEADDR socket option. I had one more question. How can I tell my server to accept any connection from a specific IP?. > Try this - start the server - don't > connect even a single client - stop the server - and start it again - you should > be able to start it again without any delay in this case, since no connected > socket has been created. Works on my 2.4.17. The same was happening even if I did not add folloing lines. struct linger ling; ling. l_onoff = 1; ling.l_linger = 0; setsockopt(listenfd, SOL_SOCKET, SO_LINGER, &ling, sizeof(ling)); In fact the problem, I had in my first post in the thread, was only when I connected at least one client. If I did not connect even a single client it did not show me any error and started successfully Thanks again. ashutosh |