LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-05-2003, 05:42 AM   #1
jph
LQ Newbie
 
Registered: Jul 2003
Location: Switzerland
Posts: 6

Rep: Reputation: 0
Question Problem with accept() socket call which doesn't return


Working with Red Hat 7.2, kernel 2.4.16, I'm programming sockets.
In a thread, I call the accept() function. In another thread, I close the socket. Normaly, accept() should return with an error. But it never returns !

Does anyone know this problem ?

Thank's for your help.
 
Old 08-05-2003, 11:41 AM   #2
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536

Rep: Reputation: 111Reputation: 111
It will return if either there's a client connecting to the socket, or if you use a non-blocking socket.
 
Old 08-06-2003, 01:12 AM   #3
jph
LQ Newbie
 
Registered: Jul 2003
Location: Switzerland
Posts: 6

Original Poster
Rep: Reputation: 0
The case is when the server decides itself to stop. It wants to stop his listen thread (the one waiting on accept() call). With your first idea, if no client comes to connect, the accept call never returns, so the thread never ends. The second idea will probably be the solution, but I wanted to avoid it because it means that the thread must pull periodically (with a sleep time) on the socket instead of staying inactive. And this solution introduces a delay : the thread cannot react immediately on the client demand.
Thank's you for your message.
 
Old 08-06-2003, 05:57 AM   #4
DIYLinux
Member
 
Registered: Jul 2003
Location: NL
Distribution: My own
Posts: 92

Rep: Reputation: 18
What is called first, accept or close ? Are the threads synchronised, using a mutex or condition variable. They should be, because the order of accept and close is important.
 
Old 08-06-2003, 06:30 AM   #5
jph
LQ Newbie
 
Registered: Jul 2003
Location: Switzerland
Posts: 6

Original Poster
Rep: Reputation: 0
Sequence is :
1- the server is first waiting on accept() in the listen thread.
2- at any time, the main thread can call close() to close the socket.

I even tried to make a call to select() before accept(). But it doesn't work too. The select() call remains blocked, as did accept().

I come to have a look at the man page of accept() : no return error is specified when the socket is suddenly closed. So it cannot work like this.

I should say that I work with two PC, one is Linux and the other is Windows, and I first wrote my program under Windows and it works. But the Windows accept() specifies a return error when the socket is canceled. I was too trustful when trying under Linux !
 
  


Reply



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
how to handle ECONNABORTED with accept system call? murugesan Solaris / OpenSolaris 3 06-07-2005 02:18 PM
C: Socket weirdness: select() -> fork() -> accept() maxfacta Programming 1 03-01-2005 01:33 PM
(c++) network socket programming: help with accept() Dark Carnival Programming 4 08-11-2004 04:22 PM
How can get values return from a system call quenn Programming 1 09-16-2003 11:05 PM
Problem with accept() call which doesn't return jph Linux - General 0 07-28-2003 04:34 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:41 AM.

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