Example #1
0
File: test.c Project: jcaose/evcom
static evcom_stream*
pingpong_on_server_connection (evcom_server *_server, struct sockaddr *addr)
{
  assert(_server == &server);
  assert(addr);

  evcom_stream *stream = malloc(sizeof(evcom_stream));
  evcom_stream_init(stream);
  stream->on_read = pingpong_on_peer_read;
  stream->on_close = common_on_peer_close;
  stream->on_timeout = common_on_peer_timeout;
  evcom_stream_reset_timeout(stream, PINGPONG_TIMEOUT);

  assert(EVCOM_INITIALIZED == evcom_stream_state(stream));

  nconnections++;

#if EVCOM_HAVE_GNUTLS
  if (use_tls) anon_tls_server(stream);
#endif

  printf("on server connection\n");

  return stream;
}
Example #2
0
File: test.c Project: jcaose/evcom
int
pair_pingpong (int use_pipe)
{
  a_got_close = 0;
  a_got_connect = 0;
  b_got_close = 0;
  b_got_connect = 0;
  pair_pingpong_cnt = 0;

  evcom_stream_init(&a);
  a.on_close = a_close;
  a.on_connect = a_connect;
  a.on_read = a_read;
  evcom_stream_reset_timeout(&a, PAIR_PINGPONG_TIMEOUT);
#if EVCOM_HAVE_GNUTLS
  if (use_tls) anon_tls_client(&a);
#endif

  evcom_stream_init(&b);
  b.on_close = b_close;
  b.on_connect = b_connect;
  b.on_read = b_read;
  evcom_stream_reset_timeout(&b, PAIR_PINGPONG_TIMEOUT);
#if EVCOM_HAVE_GNUTLS
  if (use_tls) anon_tls_server(&b);
#endif

  if (use_pipe) {
    int pipeA[2], pipeB[2];
    assert(0 == pipe(pipeA));
    assert(0 == pipe(pipeB));

    evcom_stream_assign_fds(&a, pipeA[0], pipeB[1]);
    evcom_stream_assign_fds(&b, pipeB[0], pipeA[1]);

  } else {
    int r = evcom_stream_pair(&a, &b);
    assert(r == 0);
  }

  evcom_stream_attach(EV_DEFAULT_ &a);
  evcom_stream_attach(EV_DEFAULT_ &b);

  evcom_stream_write(&a, PING, strlen(PING));

  ev_loop(EV_DEFAULT_ 0);

  assert(a_got_close);
  assert(a_got_connect);
  assert(b_got_close);
  assert(b_got_connect);
  assert(pair_pingpong_cnt == PAIR_PINGPONG_EXCHANGES);

  return 0;
}
Example #3
0
File: test.c Project: jcaose/evcom
static evcom_stream*
make_echo_connection (evcom_server *server, struct sockaddr *addr)
{
  assert(server);
  assert(addr);

  evcom_stream *stream = malloc(sizeof(evcom_stream));
  evcom_stream_init(stream);
  stream->on_read = echo;
  stream->on_close = free_stream;
  stream->on_timeout = error_out;
  evcom_stream_reset_timeout(stream, ZERO_TIMEOUT);

#if EVCOM_HAVE_GNUTLS
  if (use_tls) anon_tls_server(stream);
#endif

  return stream;
}
Example #4
0
static oi_socket* 
on_server_connection(oi_server *server, struct sockaddr *addr, socklen_t len)
{
  oi_socket *socket = malloc(sizeof(oi_socket));
  oi_socket_init(socket, TIMEOUT);
  socket->on_read    = on_peer_read;
  socket->on_drain   = on_peer_drain;
  socket->on_close   = on_peer_close;
  socket->on_timeout = on_peer_timeout;

#if HAVE_GNUTLS
# if SECURE
  anon_tls_server(socket);
# endif
#endif

  //printf("on server connection\n");

  return socket;
}
Example #5
0
File: test.c Project: jcaose/evcom
static evcom_stream*
connint_on_connection(evcom_server *_server, struct sockaddr *addr)
{
  assert(_server == &server);
  assert(addr);

  evcom_stream *stream = malloc(sizeof(evcom_stream));
  evcom_stream_init(stream);
  stream->on_read    = send_bye_and_close;
  stream->on_close   = common_on_peer_close;
  stream->on_timeout = common_on_peer_timeout;
  evcom_stream_reset_timeout(stream, CONNINT_TIMEOUT);

#if EVCOM_HAVE_GNUTLS
  if (use_tls) anon_tls_server(stream);
#endif

  printf("on server connection\n");

  return stream;
}