| 78 | /////////////////////////////////////////////////////////////////////////////// |
| 79 | |
| 80 | int main(int argc, char ** argv) { |
| 81 | QCoreApplication app(argc, argv); |
| 82 | #if defined(Q_OS_UNIX) |
| 83 | catchUnixSignals({SIGQUIT, SIGINT, SIGTERM, SIGHUP}); |
| 84 | #endif |
| 85 | |
| 86 | // dumb (trivial) connection counter |
| 87 | quint64 iconnectionCounter = 0; |
| 88 | |
| 89 | QString portOrUnixSocket("10022"); // default: TCP port 10022 |
| 90 | if ( argc > 1 ) |
| 91 | portOrUnixSocket = argv[1]; |
| 92 | |
| 93 | QHttpServer server(&app); |
| 94 | server.listen(portOrUnixSocket, [&](QHttpRequest* req, QHttpResponse* res){ |
| 95 | new ClientHandler(++iconnectionCounter, req, res); |
| 96 | // this ClientHandler object will be deleted automatically when: |
| 97 | // socket disconnects (automatically after data has been sent to the client) |
| 98 | // -> QHttpConnection destroys |
| 99 | // -> QHttpRequest destroys -> ClientHandler destroys |
| 100 | // -> QHttpResponse destroys |
| 101 | // all by parent-child model of QObject. |
| 102 | }); |
| 103 | |
| 104 | if ( !server.isListening() ) { |
| 105 | fprintf(stderr, "can not listen on %s!\n", qPrintable(portOrUnixSocket)); |
| 106 | return -1; |
| 107 | } |
| 108 | |
| 109 | app.exec(); |
| 110 | } |
nothing calls this directly
no test coverage detected