Networking Forums

Networking Forums > Computer Networking > Linux Networking > C/C++ socket send causes program to exit

Reply
Thread Tools Display Modes

C/C++ socket send causes program to exit

 
 
Bjorn Nuyttens
Guest
Posts: n/a

 
      07-16-2007, 04:12 PM
I have two programs, a "client" and a "server". The server just sends
some data to the client. When I kill the client by pressing Ctrl+C, the
connection is not always properly terminated on the server's side.

When the server is in the middle of a send() or write() call, the
process exists with error code 141. No Segmentation faults, no
exceptions thrown, not even a return value from the send/write call. I
expect send or write to return -1 (see manpages) but it does not return,
the whole process just exits.

Any ideas what could be causing this? Can this be caused by a bug in the
OS (Ubuntu 7.04)?


Program code:
printf("1"); fflush(stdout);
//int retval = send(s, pData, uLength, 0);
int retval = write(s, pData, uLength);
printf("2"); fflush(stdout);

Typical output at the server side:
121212121212 (kill client)(server exits correctly with code 0)
12121212121 (kill client when server calls send)(server stops executing
code, i.e. printf etc and process exits with code 141)


Bjorn Nuyttens
 
Reply With Quote
 
 
 
 
David Schwartz
Guest
Posts: n/a

 
      07-16-2007, 10:02 PM
On Jul 16, 9:12 am, Bjorn Nuyttens <cyberc...@pandora.be> wrote:

> When the server is in the middle of a send() or write() call, the
> process exists with error code 141. No Segmentation faults, no
> exceptions thrown, not even a return value from the send/write call. I
> expect send or write to return -1 (see manpages) but it does not return,
> the whole process just exits.
>
> Any ideas what could be causing this? Can this be caused by a bug in the
> OS (Ubuntu 7.04)?


No, the OS is doing the right thing. Since your program can no longer
write to the place it was trying to write, the OS assumes that it can
no longer make useful progress. You didn't tell the OS anything else,
so you get the default behavior.

Google for 'SIGPIPE'.

DS

 
Reply With Quote
 
Bjorn Nuyttens
Guest
Posts: n/a

 
      07-17-2007, 08:53 AM
David Schwartz wrote:
> On Jul 16, 9:12 am, Bjorn Nuyttens <cyberc...@pandora.be> wrote:
>
>> When the server is in the middle of a send() or write() call, the
>> process exists with error code 141. No Segmentation faults, no
>> exceptions thrown, not even a return value from the send/write call. I
>> expect send or write to return -1 (see manpages) but it does not return,
>> the whole process just exits.
>>
>> Any ideas what could be causing this? Can this be caused by a bug in the
>> OS (Ubuntu 7.04)?

>
> No, the OS is doing the right thing. Since your program can no longer
> write to the place it was trying to write, the OS assumes that it can
> no longer make useful progress. You didn't tell the OS anything else,
> so you get the default behavior.
>
> Google for 'SIGPIPE'.
>
> DS
>


For those interested: you could either ignore or handle the SIGPIPE
signal or specifiy the MSG_NOSIGNAL option with the send command. For
the time being, I chose the latter.

printf("1"); fflush(stdout);
int retval = send(s, pData, uLength, MSG_NOSIGNAL);
printf("2"); fflush(stdout);


Thanks to David for pointing me in the right direction!
 
Reply With Quote
 
 
 
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Purging socket send buffers Markus Linux Networking 1 06-20-2007 07:17 PM
How to find UDP socket is closed in client and server program in C sandeep Linux Networking 1 09-22-2006 12:18 PM
Raw socket transfer, fixing slow TX rate (C program, linux) bobrics@gmail.com Linux Networking 0 04-09-2006 05:05 AM
How can I send a struct containing a char * with a socket? Patrick Lam Linux Networking 5 04-03-2006 08:54 PM
Mini pop checker program, with Send facility Peter Broadband 4 12-09-2005 04:02 PM



1 2 3 4 5 6 7 8 9 10 11