Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


Closed Thread
  Search this Thread
Old 09-24-2004, 12:03 PM   #1
LQ Newbie
Registered: Aug 2004
Location: New York
Posts: 6

Rep: Reputation: 0
How to determine lost socket connection

Hi, All.
I am a new Linux programmer.
I made a Linux TCP server for control applications. When some TCP client
connects to it, the program goes into infinite console loop, getting characters, echoing them to client, parsing commands etc. Everything is OK until the client unexpectedly terminates the connection. I have to detect this event inside the loop and break. I thought that it might be done by analyzing socket state (i.e. if the state is not ESTABLISHED - break the loop) but from various examples and HOWTOs I did not see how to do it. It seems that I have to solve this problem in different way.
Can anybody criticize and prompt?
Old 09-24-2004, 05:46 PM   #2
Registered: Feb 2002
Location: Grenoble
Distribution: Debian
Posts: 9,683

Rep: Reputation: 219Reputation: 219Reputation: 219
You probably get 'Broken pipe', right? If so, you should block SIGPIPE signal (set it's handler to SIG_IGN). Then, if you try to read/write from the closed socket you'll get EPIPE in errno (function result will be -1).
Old 09-24-2004, 05:58 PM   #3
Registered: Feb 2002
Location: Grenoble
Distribution: Debian
Posts: 9,683

Rep: Reputation: 219Reputation: 219Reputation: 219
Please do not post the same thread in more than one forum. Picking the most relevant forum and posting it once there makes it easier for other members to help you and keeps the discussion all in one place.

There's a discussion going in Programming, so I'm closing this thread.

Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Socket Connection Failed: 111 Connection Refused degraffenried13 Linux - General 3 05-31-2009 02:17 AM
Socket connection refused problem James_dean Linux - Networking 1 09-23-2005 05:51 PM
Killing an socket connection czelaya Linux - Networking 0 04-18-2005 05:56 PM
How to detect lost socket connection sasha_baranov Programming 4 02-17-2005 12:46 AM
socket connection raven Programming 1 02-04-2002 12:53 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 08:35 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration