int main()
{
	SLOG_INIT("./config/slog.config");

	ListenSocket linsten_socket(3011);
	if(!linsten_socket.open())
	{
		SLOG_ERROR("listen on port:3010 error.");
		return -1;
	}

	DownloadServerThreadPool server_pool(5);
	server_pool.start();

	//listen event
	ListenHandler listen_handler(&server_pool);
	EpollDemuxer io_demuxer;
	io_demuxer.register_event(linsten_socket.get_handle(), EVENT_READ|EVENT_PERSIST, -1, &listen_handler);

	//timer event
	TimerHandler timer(&io_demuxer);
	io_demuxer.register_event(-1, EVENT_INVALID, 3000, &timer);

	//run server forever
	io_demuxer.run_loop();

	SLOG_UNINIT();
	return 0;
}
Esempio n. 2
0
static pn_event_type_t ssl_server_handler(test_handler_t *h, pn_event_t *e) {
  switch (pn_event_type(e)) {
   case PN_CONNECTION_BOUND:
    return ssl_handler(h, e);
   case PN_CONNECTION_REMOTE_OPEN: {
     pn_event_type_t et = ssl_handler(h, e);
     pn_connection_open(pn_event_connection(e));
     return et;
   }
   default:
    return listen_handler(h, e);
  }
}
Esempio n. 3
0
/* Close the transport to abort a connection, i.e. close the socket without an AMQP close */
static pn_event_type_t listen_abort_handler(test_handler_t *th, pn_event_t *e) {
  switch (pn_event_type(e)) {
   case PN_CONNECTION_REMOTE_OPEN:
    /* Close the transport - abruptly closes the socket */
    pn_transport_close_tail(pn_connection_transport(pn_event_connection(e)));
    pn_transport_close_head(pn_connection_transport(pn_event_connection(e)));
    return PN_EVENT_NONE;

   default:
    /* Don't auto-close the listener to keep the event sequences simple */
    return listen_handler(th, e);
  }
}