On CentOS 5.4, Linux 2.6.18-164.6.1.el5 #1 SMP Tue Nov 3 16:18:27 EST 2009 i686 i686 i386 GNU/Linux
In man 2 send I find:
The send() call may be used only when the socket is in a connected state (so that the intended recipient is known). The only difference between send() and write() is the presence of flags. With zero flags parameter, send() is equivalent to write().
In some complex server software, if the client disconnects: send: delivers errno == ECONNRESET but write: crashes the server process.
So it is not really equivalent. Any thoughts on this?
Thanks, Mike.
On 4/6/2010 2:16 PM, Michael D. Berger wrote:
On CentOS 5.4, Linux 2.6.18-164.6.1.el5 #1 SMP Tue Nov 3 16:18:27 EST 2009 i686 i686 i386 GNU/Linux
In man 2 send I find:
The send() call may be used only when the socket is in a connected state (so that the intended recipient is known). The only difference between send() and write() is the presence of flags. With zero flags parameter, send() is equivalent to write().
In some complex server software, if the client disconnects: send: delivers errno == ECONNRESET but write: crashes the server process.
So it is not really equivalent. Any thoughts on this?
Are you sure it isn't the normal signal associated with a write when the other end closes first that is crashing the process?
On Tue, 06 Apr 2010 14:37:27 -0500, Les Mikesell wrote:
On 4/6/2010 2:16 PM, Michael D. Berger wrote:
On CentOS 5.4, Linux 2.6.18-164.6.1.el5 #1 SMP Tue Nov 3 16:18:27 EST 2009 i686 i686 i386 GNU/Linux
In man 2 send I find:
The send() call may be used only when the socket is in a connected state (so that the intended recipient is known). The only difference between send() and write() is the presence of flags. With zero flags parameter, send() is equivalent to write().
In some complex server software, if the client disconnects: send: delivers errno == ECONNRESET but write: crashes the server process.
So it is not really equivalent. Any thoughts on this?
Are you sure it isn't the normal signal associated with a write when the other end closes first that is crashing the process?
No, I.m not sure. I found that send also sometimes crashes it. Sorry for the misleading comment.
Mike.
On 4/6/2010 2:48 PM, Michael D. Berger wrote:
On Tue, 06 Apr 2010 14:37:27 -0500, Les Mikesell wrote:
On 4/6/2010 2:16 PM, Michael D. Berger wrote:
On CentOS 5.4, Linux 2.6.18-164.6.1.el5 #1 SMP Tue Nov 3 16:18:27 EST 2009 i686 i686 i386 GNU/Linux
In man 2 send I find:
The send() call may be used only when the socket is in a connected state (so that the intended recipient is known). The only difference between send() and write() is the presence of flags. With zero flags parameter, send() is equivalent to write().
In some complex server software, if the client disconnects: send: delivers errno == ECONNRESET but write: crashes the server process.
So it is not really equivalent. Any thoughts on this?
Are you sure it isn't the normal signal associated with a write when the other end closes first that is crashing the process?
No, I.m not sure. I found that send also sometimes crashes it. Sorry for the misleading comment.
They should be equivalent - if the other end closes first, you'll get a SIGPIPE, which by default will kill the process. If you want to keep running you have to handle or ignore the signal.
On Tue, 06 Apr 2010 14:53:45 -0500, Les Mikesell wrote:
[...]
They should be equivalent - if the other end closes first, you'll get a SIGPIPE, which by default will kill the process. If you want to keep running you have to handle or ignore the signal.
How about if I use MSG_NOSIGNAL in the flags argument?
Thanks, Mike.
On 4/6/2010 3:19 PM, Michael D. Berger wrote:
On Tue, 06 Apr 2010 14:53:45 -0500, Les Mikesell wrote:
[...]
They should be equivalent - if the other end closes first, you'll get a SIGPIPE, which by default will kill the process. If you want to keep running you have to handle or ignore the signal.
How about if I use MSG_NOSIGNAL in the flags argument?
If you are writing something that is supposed to be a long-running server process you should explicitly ignore all the signals that you don't want to kill it, and have handlers for anything that might be useful. For example SIGHUP is often used to tell a program to re-read its configuration file. Since the source code for the whole system is available you should be able to find examples. Or look at the *bsd versions if you are concerned about accidentally duplicating some GPL'd code.
On Tue, 06 Apr 2010 14:53:45 -0500, Les Mikesell wrote:
[...]
They should be equivalent - if the other end closes first, you'll get a SIGPIPE, which by default will kill the process. If you want to keep running you have to handle or ignore the signal.
How about if I use MSG_NOSIGNAL in the flags argument?
I don't think I'd do that. Rather, trap only the ones you expect (for testing *ONLY*), then have it let you know of any other errors handed it. But don't just let it crash. Consider that other errors might be coming (SEGV, say).
mark
On 4/6/2010 3:41 PM, m.roth@5-cent.us wrote:
On Tue, 06 Apr 2010 14:53:45 -0500, Les Mikesell wrote:
[...]
They should be equivalent - if the other end closes first, you'll get a SIGPIPE, which by default will kill the process. If you want to keep running you have to handle or ignore the signal.
How about if I use MSG_NOSIGNAL in the flags argument?
I don't think I'd do that. Rather, trap only the ones you expect (for testing *ONLY*), then have it let you know of any other errors handed it. But don't just let it crash. Consider that other errors might be coming (SEGV, say).
Or, depending on the kind of service this is supposed to provide you might let xinetd start an instance for every connection (like telnet, etc). Your code can be much simpler that way since exiting on anything unexpected is then the right thing to do.
On Tue, 06 Apr 2010 15:57:28 -0500, Les Mikesell wrote:
[...]
I added the handler and its working well now.
Thanks, Mike.
On Apr 6, 2010, at 3:37 PM, Les Mikesell lesmikesell@gmail.com wrote:
On 4/6/2010 2:16 PM, Michael D. Berger wrote:
On CentOS 5.4, Linux 2.6.18-164.6.1.el5 #1 SMP Tue Nov 3 16:18:27 EST 2009 i686 i686 i386 GNU/Linux
In man 2 send I find:
The send() call may be used only when the socket is in a connected state (so that the intended recipient is known). The only difference between send() and write() is the presence of flags. With zero flags parameter, send() is equivalent to write().
In some complex server software, if the client disconnects: send: delivers errno == ECONNRESET but write: crashes the server process.
So it is not really equivalent. Any thoughts on this?
Are you sure it isn't the normal signal associated with a write when the other end closes first that is crashing the process?
Yes it's probably broken pipe that is casing the signal.
-Ross