[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[Libevent-users] bufferevent with openssl server



Hi,

I tried to setup an SSL server with libevent. But the read/write callbacks are not invoked after the handshake phase.
Please see the code below. 

Thanks, 
W Shao

The listener callback is as follows:

void listener_cb(struct evconnlistener *listener, evutil_socket_t fd,
      struct sockaddr *sa, int socklen, void *user_data) {
  struct event_base *base = (struct event_base*) user_data;
  struct bufferevent *bev;
  
  BIO *sbio=BIO_new_socket(fd,BIO_NOCLOSE);
  ssl=SSL_new(ctx); 

  SSL_set_bio(ssl,sbio,sbio);

  bev = bufferevent_openssl_socket_new(base, fd, ssl, BUFFEREVENT_SSL_ACCEPTING,
      BEV_OPT_CLOSE_ON_FREE);
  if (!bev) {
    fprintf(stderr, "Error constructing bufferevent!");
    event_base_loopbreak(base);
    return;
  }
  
  // Question: 
  //  Do I need to call SSL_accept at some point?
  
 bev = bufferevent_openssl_filter_new(base,
      bev,
      ssl,
      BUFFEREVENT_SSL_OPEN,
      BEV_OPT_CLOSE_ON_FREE);

  if (!bev) {
    perror("Bufferevent_openssl_new");
  }

  bufferevent_setcb(bev, readcb, writecb, eventcb, NULL);
  bufferevent_enable(bev, EV_WRITE);
  bufferevent_enable(bev, EV_READ);
}