call to accept()...socket I/O

call to accept()...socket I/O

Post by zip.. » Fri, 22 Sep 2000 04:00:00



OK folks,

I am creating a server and have created my listen
socket and am now calling accept() to accept
incoming requests for a connection. My problem is
that the process cannot be halted while calling
accept(). I need a way to poll for requests
periodically.

Does anybody know of a way to call accept()
without giving up control, i.e. in a polling
fashion???

Thanks,
Zal

Sent via Deja.com http://www.deja.com/
Before you buy.

 
 
 

call to accept()...socket I/O

Post by aa.. » Fri, 22 Sep 2000 04:00:00



> I am creating a server and have created my listen
> socket and am now calling accept() to accept
> incoming requests for a connection. My problem is
> that the process cannot be halted while calling
> accept(). I need a way to poll for requests
> periodically.

        What you need is to set up a non-blocking socket to accept on.
Once this is accomplished (see Unix socket FAQ), accept will fail with
status EWOULDBLOCK if there are no coonections waiting (see man accept).
Then poll to your heart's content.

-- Greg McLearn

CS Graduate Student, University of Waterloo

 
 
 

call to accept()...socket I/O

Post by Mihir Lal » Fri, 22 Sep 2000 04:00:00



> OK folks,

> I am creating a server and have created my listen
> socket and am now calling accept() to accept
> incoming requests for a connection. My problem is
> that the process cannot be halted while calling
> accept(). I need a way to poll for requests
> periodically.

> Does anybody know of a way to call accept()
> without giving up control, i.e. in a polling
> fashion???

> Thanks,
> Zal

> Sent via Deja.com http://www.deja.com/
> Before you buy.

There are 2 ways of which I think you can do this:

1. Use select and and add the listening socket's descriptor to your
FD_SET; accept only if you get a connection from a client.

2. Have 2 processes, one blocking on accept and the other process
reading/wroting to clients. For this to work, pass the file descriptor
of an accepted connection to the second process. Refer to UNP by Richard
Stevens to know more about file descriptor passing.

hope this helps.

 
 
 

call to accept()...socket I/O

Post by zip.. » Fri, 22 Sep 2000 04:00:00





> > I am creating a server and have created my listen
> > socket and am now calling accept() to accept
> > incoming requests for a connection. My problem is
> > that the process cannot be halted while calling
> > accept(). I need a way to poll for requests
> > periodically.

>    What you need is to set up a non-blocking socket to accept on.
> Once this is accomplished (see Unix socket FAQ), accept will fail with
> status EWOULDBLOCK if there are no coonections waiting (see man
accept).
> Then poll to your heart's content.

Thank you so much for your quick response. This seems like exactly what
I need. Could you kindly give me a link to Unix socket FAQ?

Thanks again,
Zal

Quote:

> -- Greg McLearn

> CS Graduate Student, University of Waterloo

Sent via Deja.com http://www.deja.com/
Before you buy.
 
 
 

call to accept()...socket I/O

Post by Barry Margoli » Fri, 22 Sep 2000 04:00:00



>Thank you so much for your quick response. This seems like exactly what
>I need. Could you kindly give me a link to Unix socket FAQ?

Have you looked on www.faqs.org?

--

Genuity, Burlington, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.

 
 
 

call to accept()...socket I/O

Post by Mark Paul » Fri, 22 Sep 2000 04:00:00


Use the select() call.  select() will break on a set time,
system event, or when your socket "pops".  When your
socket pops, then you can do the accept() call.  


> OK folks,

> I am creating a server and have created my listen
> socket and am now calling accept() to accept
> incoming requests for a connection. My problem is
> that the process cannot be halted while calling
> accept(). I need a way to poll for requests
> periodically.

> Does anybody know of a way to call accept()
> without giving up control, i.e. in a polling
> fashion???

> Thanks,
> Zal

> Sent via Deja.com http://www.deja.com/
> Before you buy.

--
Message sent VIA Followup and E-Mail --

--
****   Please remove the NO.SPAM when replying   ****

 
 
 

call to accept()...socket I/O

Post by aa.. » Fri, 22 Sep 2000 04:00:00



> Thank you so much for your quick response. This seems like exactly what
> I need. Could you kindly give me a link to Unix socket FAQ?

        Well there are several copies out on the Web, and I believe one is
posted to the group every month or so.  Google's top hit for "unix socket
programming faq" yields http://www.landfield.com/faqs/unix-faq/socket/
Also be sure to check out "man socket" and "man fcntl".

-- Greg McLearn

CS Graduate Student, University of Waterloo