Debian Codegraph @

Source/Network/HTTP/CQtHttpListner.cpp

raw
1 /*
2 * Copyright (C) 2013-2015, 2019 by the Konclude Developer Team.
3 *
4 * This file is part of the reasoning system Konclude.
5 * For details and support, see <http://konclude.com/>.
6 *
7 * Konclude is free software: you can redistribute it and/or modify
8 * it under the terms of version 3 of the GNU Lesser General Public
9 * License (LGPLv3) as published by the Free Software Foundation.
10 *
11 * Konclude is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU (Lesser) General Public License for more details.
15 *
16 * You should have received a copy of the GNU (Lesser) General Public
17 * License along with Konclude. If not, see <http://www.gnu.org/licenses/>.
18 *
19 */
20
21 #include "CQtHttpListner.h"
22
23
24 namespace Konclude {
25
26 namespace Network {
27
28 namespace HTTP {
29
30 CQtHttpListner::CQtHttpListner(CQtHttpConnectionHandlerFactory* handlerFactory, cint64 port) {
31 mPort = port;
32 mHandlerFactory = handlerFactory;
33
34 listen(QHostAddress::Any,port);
35 if (isListening()) {
36 LOG(INFO,"::Konclude::Network::HTTP::HttpListner",logTr("Listening on port '%1'").arg(port),this);
37 } else {
38 LOG(WARNING,"::Konclude::Network::HTTP::HttpListner",logTr("Cannot bind to port '%1', because: '%2'.").arg(port).arg(errorString()),this);
39 }
40 }
41
42 CQtHttpListner::~CQtHttpListner() {
43 }
44
45 void CQtHttpListner::incomingConnection(qintptr socketDescriptor) {
46 CQtHttpConnectionHandler* handler = mHandlerFactory->getConnectionHandler();
47 if (handler) {
48 handler->handleIncomingConnection(socketDescriptor);
49 } else {
50 QTcpSocket* socket=new QTcpSocket(this);
51 if (socket->setSocketDescriptor(socketDescriptor)) {
52 connect(socket, SIGNAL(disconnected()), socket, SLOT(deleteLater()));
53 socket->write("HTTP/1.1 503 too many connections\r\nConnection: close\r\n\r\nToo many connections\r\n");
54 LOG(WARNING,"::Konclude::Network::HTTP::HttpListner",logTr("Too many connections on port '%1'.").arg(mPort),this);
55 socket->disconnectFromHost();
56 } else {
57 connect(socket, SIGNAL(disconnected()), socket, SLOT(deleteLater()));
58 LOG(WARNING,"::Konclude::Network::HTTP::HttpListner",logTr("Set socket description error."),this);
59 }
60 }
61 }
62
63
64 }; // end namespace HTTP
65
66 }; // end namespace Network
67
68 }; // end namespace Konclude
69