// run with // ./sslserver 127.0.0.1 9001 ./cert.pem ./key.pem #include #include #include #include #include "EchoMessage.hpp" #include #include #include SocketServer *socketServer; void signalHandler(int s) { LOG_STATIC( Logger::INFO, std::string("Exiting after receiving signal: "). append(TToStr(s)).c_str() ); socketServer->stop(); delete socketServer; SslConnection::destroy(); Logger::destroy(); exit(1); } int main(int argc, char* argv[] ) { if ( argc != 5 ) { std::cerr << "Usage: " << argv[0] << " " << std::endl; return 1; } struct sigaction sigIntHandler; sigIntHandler.sa_handler = signalHandler; sigemptyset(&sigIntHandler.sa_mask); sigIntHandler.sa_flags = 0; sigaction(SIGINT, &sigIntHandler, NULL); Logger::createInstance(); Logger::init(std::cout); Logger::setLogLevel(Logger::FINEST); SslConnection::init(); EchoMessage msg; SslConnection conn(argv[1], argv[2], &msg); if ( !conn.initServerContext(argv[3], argv[4]) ) { LOG_STATIC( Logger::ERR, "Failed to init SSL context, exiting..."); SslConnection::destroy(); Logger::destroy(); return 1; } socketServer = new SocketServer(&conn); if ( !socketServer->start() ) { LOG_STATIC( Logger::ERR, "Failed to start TCP server, exiting..."); delete socketServer; SslConnection::destroy(); Logger::destroy(); return 1; } // never reached return 0; }