Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

passive close
Hi,
I have a server process that needs to reuse a TCP socket. So I would like
it to always do a passive close. To do this I do the following

char c;
int tmp;
tmp = read(TCPsocket, &c, 1, 0);
while(tmp >= 0 || (errno != ENOTCONN))
{
tmp = read(TCPsocket, &c, 1, 0);
}

The TCPsocket is non-blocking so I check whether read() returns -1 for
some other reason like EWOULDBLOCK.
This loop never ends. So my question is whether read() returns 0 or -1
(with ENOTCONN set) when the remote end sends a FIN pkt. What is the usual
method for ensuring that a server only does a passvive close?

Thank you,
Anant.

Report this thread to moderator Post Follow-up to this message
Old Post
Anant Padmanath Mudambi
04-23-05 01:57 AM


Re: passive close
In article <Pine.GSO.4.58.0504221210280.14072@mamba.cs.Virginia.EDU>,
Anant Padmanath Mudambi <apm9v@mamba.cs.Virginia.EDU> wrote:

> Hi,
> I have a server process that needs to reuse a TCP socket. So I would like
> it to always do a passive close. To do this I do the following
>
> char c;
> int tmp;
> tmp = read(TCPsocket, &c, 1, 0);
> while(tmp >= 0 || (errno != ENOTCONN))
> {
> tmp = read(TCPsocket, &c, 1, 0);
> }
>
> The TCPsocket is non-blocking so I check whether read() returns -1 for
> some other reason like EWOULDBLOCK.
> This loop never ends. So my question is whether read() returns 0 or -1
> (with ENOTCONN set) when the remote end sends a FIN pkt. What is the usual
> method for ensuring that a server only does a passvive close?

If the remote end sends a FIN segment, read() will return 0 when you've
finished reading everything.  So change 'tmp >= 0' to 'tmp > 0'.

--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***

Report this thread to moderator Post Follow-up to this message
Old Post
Barry Margolin
04-23-05 08:57 AM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

Unix Programming archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 07:22 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.