Solved

Reconnection causes SIGPIPE signal

Posted on 2006-11-21
4
821 Views
Last Modified: 2012-05-05
I have an infinite for loop where a client app is consistently requesting data from a server, using the GNU C socket library.  (It's all happening locally though.  I'm using my localhost as a server, since this is just a test program.)

The basic routine is:

initialize client socket

for (;;) {
     connect to server
     send request
     recv data
}

The data is received fine, and everything works normally when the above is done ONCE.  But if I do this in a loop, I get SIGPIPE signals after two iterations.  This causes the program to terminate.  I can pass MSG_NOSIGNAL to the send() function, but this just generates various broken pipe error messages.  The client continues to receive data normally, but the SIGPIPE messages keep happening.  

I know that a SIGPIPE means that I'm writing to a socket, but nothing is reading from it.  But this doesn't make sense, because the server clearly is reading from it, since I'm successfully getting the data.  Does anyone know what might be happening here?  

0
Comment
Question by:chsalvia
  • 2
4 Comments
 
LVL 45

Accepted Solution

by:
Kdo earned 250 total points
ID: 17987098

After the receive, close the connection.

Or test that an active connection doesn't exist before you issue the connect().


Kent
0
 
LVL 6

Expert Comment

by:_iskywalker_
ID: 17987127
yes, dont open too much connections, make the opning connection out from the intereaction
0
 
LVL 2

Assisted Solution

by:avsrivastava
avsrivastava earned 250 total points
ID: 17987170
One possibility is that the pipe buffer gets full before the client reads any data, which raises the SIGPIPE message.
You anyways read the data correctly because once the client reads the data, the server can read more.

Solution:
Don't send the MSG_NOSIGNAL, catch the SIGPIPE signal.
When you get the message, sleep for a random amount of time(could be predetermined as well).
When the program wakes, try to write again starting from the position where you left(the return value of write tells you till which byte you managed).


0
 
LVL 2

Expert Comment

by:avsrivastava
ID: 17987184
The pipe by default on linux kernel is 64k, so if the data you are writing is only bytes this would not be the problem though.
0

Featured Post

Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How to design, and implement simple interface 5 135
C simple state machine for client server handshake 4 300
Line meaning 9 85
Using ANSI C how to Read a .csv file 10 79
Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use while-loops in the C programming language.

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question