LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Other *NIX Forums > Solaris / OpenSolaris
User Name
Password
Solaris / OpenSolaris This forum is for the discussion of Solaris and OpenSolaris.
General Sun, SunOS and Sparc related questions also go here.

Notices

Reply
 
LinkBack Search this Thread
Old 06-06-2005, 07:13 AM   #1
murugesan
Member
 
Registered: May 2003
Posts: 149

Rep: Reputation: 28
how to handle ECONNABORTED with accept system call?


hi all,

i have some code like
Code:
   while(1)
   {
      if(accept()<0)
      {
          if errno==EAGAIN 
               continue;
      }
      else
      {
          fork() and handle the new connection.
          exit the child
      }
      continue while in the parent.
   }
In some situation I am receving ECONNABORTED for accept system call.
Now is it advisible to continue the while loop in parent if i recv ECONNABORTED or shall i restart the server instance itself ?


Regards,
Murugesan
 
Old 06-06-2005, 05:56 PM   #2
technopark02
Member
 
Registered: Feb 2005
Distribution: Solaris 8 - 11, JDS Linux 3.0
Posts: 99

Rep: Reputation: 15
When the client does connect(), it will be queued up at server, waiting to be accept()'ed by the server. But if the client aborts the connection by sending RST (reset) even before server accept()s, then server accept() generates the "connection aborted" (ECONNABORTED) error.

>> Now is it advisible to continue the while loop in parent if i recv ECONNABORTED or shall i restart the server instance itself?

The server should not be vulnerable to errors like these. (How do you like it, if the linuxquestions.org web server restarts itself whenever you changed your mind not to access certain web page, while the server is still processing your request ). So, the server should continue listen() as it was listening, and handle the rest of the requests from the listen queue. The code should be changed to:
Code:
      if (accept() < 0) {
          if ((errno == EAGAIN) || (errno == ECONNABORTED) || (.. other errors ..)) {
               perror ("accept(): "); 
               continue;
          }
      }
Notes:
1. If you are new to network programming, I would recommend "Beej's Guide to Network Programming" guide. It was mirrored on: http://www-db.stanford.edu/~cho/prog.../network.html.

2. Sometimes it could be a bug too. So, it is always better to post the OS name, version etc., as well, to make it easy for the others to look through the bug/patch reports.
 
Old 06-07-2005, 12:45 AM   #3
murugesan
Member
 
Registered: May 2003
Posts: 149

Original Poster
Rep: Reputation: 28
Thanks for the reply technopark02.

This is what I am using.

/dinesh_p_v/murugesan/c $ uname -a
SunOS sun28 5.8 Generic_117350-12 sun4u sparc SUNW,Ultra-250


> and handle the rest of the requests from the listen queue

Actually my doubt was, will there be any changes to the socket credentials so that the further requests cannot be handled at all and there is a need to restart the server or there is no need to restart the server such that the socket credentials has not been changed after ECONNABORTED error?


Regards,
Murugesan
 
Old 06-07-2005, 02:18 PM   #4
technopark02
Member
 
Registered: Feb 2005
Distribution: Solaris 8 - 11, JDS Linux 3.0
Posts: 99

Rep: Reputation: 15
>> will there be any changes to the socket credentials so that the further
>> requests cannot be handled at all and there is a need to restart the
>> server or there is no need to restart the server such that the socket
>> credentials has not been changed after ECONNABORTED error?

Depends on various constraints.

1. If the connection hasn't been established yet, i.e., if it is the very first request from the client and if the client closes the connection even before the server got a chance to respond, accept() call at server results in ECONNABORTED. Server should ignore this error and move on with the next request in the queue.

If the client needs to connect to the server again, it has to do another connect().

2. If the connection between client and server is in ESTABLISHED state, and if the client closes the connection abruptly, accept() call at server results in ECONNABORTED. In this scenario, the server must close the connection that is half-open. Otherwise those half-opened sockets may remain in CLOSE_WAIT state, as long as the server process is active. Have a look at this web page: http://technopark02.blogspot.com/200...closewait.html, to know more about CLOSE_WAIT and its impact, in a slightly different scenario.

So, under any circumstances the server need not be restarted if there are some problems at the client end.

Last edited by technopark02; 06-07-2005 at 02:20 PM.
 
  


Reply


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
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
System time won't accept new timezone mustangfanatic01 Slackware 4 11-22-2005 07:34 PM
using system call ej25 Programming 9 11-30-2004 11:45 AM
Is it possible to use system() and get the return value from the system call newguy21 Programming 1 08-11-2004 01:37 PM
Problem with accept() socket call which doesn't return jph Programming 4 08-06-2003 06:30 AM
Problem with accept() call which doesn't return jph Linux - General 0 07-28-2003 04:34 AM


All times are GMT -5. The time now is 01:05 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration