Hi,

I experience strange behaviour with libevent on Solaris in combination with 
pipes.
Start the following program and then kill its child.  The parent goes in an 
endless loop instead of exiting.
When using socketpair() instead of pipe() everything works as expected.
Setting EVENT_NOEVPORT=y also makes it work.

Im using libevent-1.4.9-stable on Solaris 5.10


   Jörg


/////////////////////////////////////////////////////
#include <event.h>
#include <unistd.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>

static void eventCallback( int fd, short swhat, void* ud )
{
  char buf[100];
  size_t readn = read( fd, buf, sizeof(buf)-1 );
  if( readn > 0 )
  {
    buf[readn] = 0;
    printf( "%s\n", buf );
  }
  else
  {
    close( fd );
    event_del( (struct event*)ud );
  }
}

int main( int argc, char** argv )
{
  int fd[2];
  if( 0 )
    socketpair( AF_UNIX, SOCK_STREAM, 0, fd ); // works
  else
    pipe( fd );                                // fails

  pid_t child = fork();
  if( child == 0 )
  {
    close( fd[0] );
    for(;;)
    {
      write( fd[1], "hello world", 11 );
      sleep( 1 );
    }
  }
  else
  {
    close( fd[1] );
    event_init();
    struct event ev;
    event_set( &ev, fd[0], EV_READ | EV_PERSIST, eventCallback, &ev );
    event_add( &ev, 0 );
    event_dispatch();
    printf( "it works!\n" );
  }
}
/////////////////////////////////////////////////////

_______________________________________________
Libevent-users mailing list
Libevent-users@monkey.org
http://monkeymail.org/mailman/listinfo/libevent-users

Reply via email to