Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 8 Oct 2002 20:05:24 -0300 (ART)
From:      Fernando Gleiser <fgleiser@cactus.fi.uba.ar>
To:        alireza mahini <alirezamahini@yahoo.com>
Cc:        questions@freebsd.org
Subject:   Re: How i can force a stream socket to wait as limited  time in accept() function?
Message-ID:  <20021008195502.I3949-100000@cactus.fi.uba.ar>
In-Reply-To: <20021008210940.3032.qmail@web40709.mail.yahoo.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On Tue, 8 Oct 2002, alireza mahini wrote:

> Please sending for me a sample code that set a timeout
> for accept().
> ///Alireza


Not a complete example, but the concept is there:

int sl, sc;
fd_set rset;

sl=socket();
/*
 * listen, bind, etc goes here
 */

flags=fcntl(sl, F_GETFL,0);
flags=fcntl(sl, F_SETFL, flags | O_NONBLOCK);


while(1) {
	select(sl+1, &rset, 0, 0, &tv);
	if (FD_ISSET(sl, &rset){
		accept();
	}
}



> --- Fernando Gleiser <fgleiser@cactus.fi.uba.ar>
> wrote:
> > On Tue, 8 Oct 2002, alireza mahini wrote:
> >
> > > I am a C++ programmer and the platform that i
> > develop
> > > my project on it is FreeBSD4.4 .I am aplaying the
> > > setsocketopt()function for seting the timeout into
> > the
> > > stream socket that blocked in accept() function
> > but i
> > > can't successful.
> >
> > It's easy, mmmkay :)
> >
> > You need to set the socket descriptor in
> > non-blocking mode, then call
> > accept. accept will fail and return -1 with errno
> > set to EWOULDBLOCK,
> > the call select(2) on the socket. select will return
> > when a connection
> > arrives (you need to test for it) or when the
> > timeout expires.
> >
> > I (and everybody else) recommend "Unix Network
> > Programming, 2d Ed" by
> > Rich Stevens. It is THE book for unix programmers.
> >
> >
> > 			Fer
> >
> >
> > >
> > > __________________________________________________
> > > Do you Yahoo!?
> > > Faith Hill - Exclusive Performances, Videos & More
> > > http://faith.yahoo.com
> > >
> > > To Unsubscribe: send mail to majordomo@FreeBSD.org
> > > with "unsubscribe freebsd-questions" in the body
> > of the message
> > >
> >
>
>
> __________________________________________________
> Do you Yahoo!?
> Faith Hill - Exclusive Performances, Videos & More
> http://faith.yahoo.com
>


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-questions" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20021008195502.I3949-100000>