You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@apr.apache.org by Jack Andrews <ef...@gmail.com> on 2009/06/16 20:42:46 UTC

poll/select process's IO on windows

hi,

i want to detect IO on a child process stdio as well
as a socket from elsewhere.  ie. i want a select()
on /windows/.

is it possible with APR?  or do i have to hack around?

my first attempt is here:

int main(int c,char** argv)
{ apr_procattr_t *attr;
  const char*args[]={"cmd.exe",0};
  apr_sockaddr_t *sa;
  apr_socket_t *sock;
  apr_file_t *fds[4];
  apr_pollfd_t pfd[4],*pfdout;
  apr_pollset_t *pollset;

  fds[0]=(apr_file_t*)sock;
  AS(apr_procattr_create(&attr, pool));
  AS(apr_procattr_io_set(attr, APR_FULL_BLOCK,APR_FULL_BLOCK,APR_FULL_BLOCK));
  AS(apr_procattr_cmdtype_set(attr, APR_PROGRAM));
  AS(apr_proc_create(&newproc, "c:\\Windows\\system32\\cmd.exe", args,
0, attr, pool));
  fds[1]=newproc.in;fds[2]=newproc.out;fds[3]=newproc.err;
  AS(apr_pollset_create(&pollset, 4, pool, APR_POLLSET_WAKEABLE));

#define setpfd(x,a,b,c,d)
pfd[x].desc_type=(a),pfd[x].reqevents=(b),pfd[x].desc.s=(c),pfd[x].client_data=(d)
  for(i=0;i<4;i++)
  { setpfd(i,i?APR_POLL_FILE:APR_POLL_SOCKET,APR_POLLIN|APR_POLLOUT|APR_POLLHUP,(apr_socket_t*)fds[i],NULL);
    AS(apr_pollset_add(pollset,pfd+i));
  }
  for(;APR_TIMEUP==apr_pollset_poll(pollset,0,&n,&pfdout);)
  { printf("hoo\n");
  }
  return 0;
}



ta, jack.

Re: poll/select process's IO on windows

Posted by Erik Huelsmann <eh...@gmail.com>.
Hi Jack,

Regardless of the portability library that you're using, Windows
doesn't allow select() operations on any other than socket handles.

I don't have personal experience how to work around that issue with
APR though, I'm sorry.


With kind regards,

Erik.

On Tue, Jun 16, 2009 at 8:42 PM, Jack Andrews<ef...@gmail.com> wrote:
> hi,
>
> i want to detect IO on a child process stdio as well
> as a socket from elsewhere.  ie. i want a select()
> on /windows/.
>
> is it possible with APR?  or do i have to hack around?
>
> my first attempt is here:
>
> int main(int c,char** argv)
> { apr_procattr_t *attr;
>  const char*args[]={"cmd.exe",0};
>  apr_sockaddr_t *sa;
>  apr_socket_t *sock;
>  apr_file_t *fds[4];
>  apr_pollfd_t pfd[4],*pfdout;
>  apr_pollset_t *pollset;
>
>  fds[0]=(apr_file_t*)sock;
>  AS(apr_procattr_create(&attr, pool));
>  AS(apr_procattr_io_set(attr, APR_FULL_BLOCK,APR_FULL_BLOCK,APR_FULL_BLOCK));
>  AS(apr_procattr_cmdtype_set(attr, APR_PROGRAM));
>  AS(apr_proc_create(&newproc, "c:\\Windows\\system32\\cmd.exe", args,
> 0, attr, pool));
>  fds[1]=newproc.in;fds[2]=newproc.out;fds[3]=newproc.err;
>  AS(apr_pollset_create(&pollset, 4, pool, APR_POLLSET_WAKEABLE));
>
> #define setpfd(x,a,b,c,d)
> pfd[x].desc_type=(a),pfd[x].reqevents=(b),pfd[x].desc.s=(c),pfd[x].client_data=(d)
>  for(i=0;i<4;i++)
>  { setpfd(i,i?APR_POLL_FILE:APR_POLL_SOCKET,APR_POLLIN|APR_POLLOUT|APR_POLLHUP,(apr_socket_t*)fds[i],NULL);
>    AS(apr_pollset_add(pollset,pfd+i));
>  }
>  for(;APR_TIMEUP==apr_pollset_poll(pollset,0,&n,&pfdout);)
>  { printf("hoo\n");
>  }
>  return 0;
> }
>
>
>
> ta, jack.
>

Re: poll/select process's IO on windows

Posted by Jack Andrews <ef...@gmail.com>.
>> i want to detect IO on a child process stdio as well
>> as a socket from elsewhere.  ie. i want a select()
>> on /windows/.

i wonder if it would be useful to have an
  apr_socket_from_files(files_in, files_out, &socket)
that plugs a socket onto the end of pipes on windows.

  . only implement on windows

then we could [effectively] poll a process's stdio.

if you think it's worth pursuing, i'll have a crack at it.


ta, jack.

Re: poll/select process's IO on windows

Posted by Mladen Turk <mt...@apache.org>.
Jack Andrews wrote:
 > hi,
 >
 > i want to detect IO on a child process stdio as well
 > as a socket from elsewhere.  ie. i want a select()
 > on /windows/.
 >
 > is it possible with APR?  or do i have to hack around?
 >

It's not possible with APR, however you can make a hack
if you know its stdin (or stdout, stderr) and you need to know
if there is a data pending.

#if APR_FILES_AS_SOCKETS
static apr_status_t get_file_event(apr_file_t *f, apr_pool_t *pool)
{
     apr_int32_t  nd;
     apr_pollfd_t wait_pollfd;

     wait_pollfd.p = pool;
     wait_pollfd.desc_type = APR_POLL_FILE;
     wait_pollfd.reqevents = APR_POLLIN;
     wait_pollfd.desc.f    = f;

     return apr_poll(&wait_pollfd, 1, &nd, 0);
}
#elif defined(WIN32)
static apr_status_t get_file_event(apr_file_t *f, apr_pool_t *pool)
{
     HANDLE h;
     char   c;
     DWORD  r;

     apr_os_file_get(&h, f);
     if (PeekNamedPipe(h, &c, 1, &r, NULL, NULL)) {
     	if (r == 1)
             APR_POLLOUT;
     }
     return APR_TIMEUP;
}
#endif

This will return APR_POLLOUT if there is data present to
be read, or APR_TIMEUP if not. customize at will ;)


Regards
-- 
^(TM)