0

I am using libapr, but some of their basic primitives seem to be not working well, presenting a very strange behaviour. Here is the code I am writing:

    pr_pool_t *mp=NULL;
    apr_file_t *fp = NULL;
    apr_pollset_t *pollset=NULL;
    apr_pollfd_t file_fd;

    /*apr initialization*/
    CuAssertIntEquals(ct,0,apr_initialize());
    CuAssertIntEquals(ct,0,apr_pool_create(&mp,NULL));

    /*opens file to test poll*/
    CuAssertIntEquals(ct,0,apr_file_open(&fp, FILENAME,
            APR_FOPEN_WRITE | APR_FOPEN_CREATE | APR_FOPEN_READ,
            APR_FPROT_UREAD|APR_FPROT_UWRITE|APR_FPROT_UEXECUTE , mp));

    /*creates pollset*/
    CuAssertIntEquals(ct,0,apr_pollset_create(&pollset, 10,mp,0));

    /*prepares poll fd...*/
    file_fd.desc_type = APR_POLL_FILE;
    file_fd.reqevents = APR_POLLIN|APR_POLLOUT;
    file_fd.desc.f = fp;
    file_fd.client_data = fp;

    /*adds pollfd to pollset*/
    CuAssertIntEquals(ct,0,apr_pollset_add(pollset, &file_fd));

Everything runs well, untill I get to apr_pollset_add(pollset, &file_fd) where it fails and returns the value 1.

If you analyse the source code of this function, you find it will never return 1. Actually 1 is returned as a system error, which using libapr routine apr_sterror is translated into: 'operation not permitted'.

I almost didn't sleep and eat trying to solve this problem, but without success. I really need to use this library.

Any help would be appreciated.

twawpt
  • 51
  • 4

1 Answers1

1

I found the problem.

I was polling a regular file. A regular file is always ready be read or written.

1 corresponds to operation not permitted which is set when poll_ctl is called.

Community
  • 1
  • 1
twawpt
  • 51
  • 4