MCPcopy Create free account
hub / github.com/azadkuh/qhttp / main

Function main

example/basic-server/main.cpp:80–110  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

78///////////////////////////////////////////////////////////////////////////////
79
80int 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}

Callers

nothing calls this directly

Calls 3

catchUnixSignalsFunction · 0.85
listenMethod · 0.80
isListeningMethod · 0.80

Tested by

no test coverage detected