You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@apr.apache.org by Damir Dezeljin <pr...@mbss.org> on 2004/06/05 07:33:30 UTC
Poll() problem
Hi.
I would like to use poll() functions to check for available data on read
part of a pipe to avoid blocked read. Unfortunately I can't get it
working. When executing an apr_pollset_add(), I always get 'Bad file
descriptor' error.
So I created a simplest pice of code and tried with it. Unfortunately also
it doesn't work. Do anyone have a clue what is going on (what I made wrong
? :) ):
----
apr_pollset_t *pSet_p=NULL;
apr_pollfd_t pollfd;
apr_file_t *aFd=NULL;
aRv = apr_file_open(&aFd, "c:\\test.txt", APR_READ, APR_UREAD, pool_p);
APR_CHECK_ERR(aRv);
/* The below line is working fine if uncomented
* aRv = apr_file_read(aFd, buf, &len);
* APR_CHECK_ERR(aRv);
*/
aRv = apr_pollset_create(&pSet_p, 1, pool_p, 0);
APR_CHECK_ERR(aRv);
// BTW: is the below line necesary (it doesn't matter
// anyway it doesn't work.
// pollfd.p = pool_p;
pollfd.desc_type = APR_POLL_FILE;
pollfd.reqevents = APR_POLLNVAL | APR_POLLIN | APR_POLLOUT;
pollfd.desc.f = aFd;
aRv = apr_pollset_add(pSet_p, &pollfd);
APR_CHECK_ERR(aRv); // Tu javi error
----
Regards,
Dezo
Re: Poll() problem
Posted by Paul Querna <ch...@force-elite.com>.
On Sat, 2004-06-05 at 06:33 +0100, Damir Dezeljin wrote:
> Hi.
>
> I would like to use poll() functions to check for available data on read
> part of a pipe to avoid blocked read. Unfortunately I can't get it
> working. When executing an apr_pollset_add(), I always get 'Bad file
> descriptor' error.
>
> So I created a simplest pice of code and tried with it. Unfortunately also
> it doesn't work. Do anyone have a clue what is going on (what I made wrong
> ? :) ):
I have made a simple complete example(see attached) using apr_pollset.
It seems to operate perfectly fine on FreeBSD 5.2-Current. From what
you posted, I didn't see anything wrong with your code.
-Paul Querna
Re: Poll() problem
Posted by rb...@rkbloom.net.
On Sat, 5 Jun 2004, Damir Dezeljin wrote:
> Hi.
>
>
> > What platform are you on?
> Windows :'(
>
>
> > (although I know we have solved this somehow
> > for pipes, because we must poll in mod_cgi.)
> This is a great news. I need to poll on a pipe from child process. I will
> try to checkout a recent version of apr, apr-utils and apr-iconv and try
> to recompile.
Sorry to lead you to believe this was actually fixed in APR. It isn't.
What I meant, was that I know we can do timed reads from a pipe, because
mod_cgi in Apache does it. However, apr_poll does not. My initial
thought as to why we can do it from apr_file_read and not from apr_poll,
is that sockets and files are different beasts in Windows, and the API
that polls sockets can't poll files. So, for file reads in Windows, we
use async I/O to get timeouts.
If you are polling to determine if a single pipe has data, then your best
bet is to just call apr_file_read after having set a timeout on the pipe.
If you want to poll a set of pipes to determine which to read from, you
will probably end up sitting in a tight loop trying to read from each with
a 0 timeout until one has data.
This is really bad, but it is all Windows allows us to do.
Ryan
Re: Poll() problem
Posted by Damir Dezeljin <pr...@mbss.org>.
Hi.
> What platform are you on?
Windows :'(
> (although I know we have solved this somehow
> for pipes, because we must poll in mod_cgi.)
This is a great news. I need to poll on a pipe from child process. I will
try to checkout a recent version of apr, apr-utils and apr-iconv and try
to recompile.
10x to all of you for a great portability library.
Regards,
Dezo
Re: Poll() problem
Posted by rb...@rkbloom.net.
What platform are you on? Polling on file descriptors isn't available on
all platforms, because not all of the underlying platforms support it. I
believe that Windows, for example, can't do it, at least not with the
functions that we are using. (although I know we have solved this somehow
for pipes, because we must poll in mod_cgi.)
Ryan
On Sat, 5 Jun 2004, Damir Dezeljin wrote:
> Hi.
>
>
> I would like to use poll() functions to check for available data on read
> part of a pipe to avoid blocked read. Unfortunately I can't get it
> working. When executing an apr_pollset_add(), I always get 'Bad file
> descriptor' error.
>
>
> So I created a simplest pice of code and tried with it. Unfortunately also
> it doesn't work. Do anyone have a clue what is going on (what I made wrong
> ? :) ):
> ----
> apr_pollset_t *pSet_p=NULL;
> apr_pollfd_t pollfd;
> apr_file_t *aFd=NULL;
>
> aRv = apr_file_open(&aFd, "c:\\test.txt", APR_READ, APR_UREAD, pool_p);
> APR_CHECK_ERR(aRv);
>
> /* The below line is working fine if uncomented
> * aRv = apr_file_read(aFd, buf, &len);
> * APR_CHECK_ERR(aRv);
> */
>
> aRv = apr_pollset_create(&pSet_p, 1, pool_p, 0);
> APR_CHECK_ERR(aRv);
>
> // BTW: is the below line necesary (it doesn't matter
> // anyway it doesn't work.
> // pollfd.p = pool_p;
> pollfd.desc_type = APR_POLL_FILE;
> pollfd.reqevents = APR_POLLNVAL | APR_POLLIN | APR_POLLOUT;
> pollfd.desc.f = aFd;
>
> aRv = apr_pollset_add(pSet_p, &pollfd);
> APR_CHECK_ERR(aRv); // Tu javi error
> ----
>
>
> Regards,
> Dezo
>
>