cutelyst  4.8.0
A C++ Web Framework built on top of Qt, using the simple approach of Catalyst (Perl) framework.
socket.cpp
1 /*
2  * SPDX-FileCopyrightText: (C) 2016-2018 Daniel Nicoletti <dantti12@gmail.com>
3  * SPDX-License-Identifier: BSD-3-Clause
4  */
5 #include "socket.h"
6 
7 #include "server.h"
8 
9 #include <QLoggingCategory>
10 
11 Q_LOGGING_CATEGORY(C_SERVER_SOCK, "cutelyst.server.socket", QtWarningMsg)
12 
13 using namespace Cutelyst;
14 
15 Socket::Socket(bool secure, Cutelyst::Engine *_engine)
16  : engine(_engine)
17  , isSecure(secure)
18 {
19 }
20 
21 Socket::~Socket()
22 {
23  delete protoData;
24 }
25 
26 TcpSocket::TcpSocket(Cutelyst::Engine *engine, QObject *parent)
27  : QTcpSocket(parent)
28  , Socket(false, engine)
29 {
30  connect(this,
32  this,
33  &TcpSocket::socketDisconnected,
35 }
36 
37 void TcpSocket::connectionClose()
38 {
41 }
42 
43 bool TcpSocket::requestFinished()
44 {
45  bool disconnected = state() != ConnectedState;
46  if (!--processing && disconnected) {
47  Q_EMIT finished();
48  }
49  return !disconnected;
50 }
51 
52 bool TcpSocket::flush()
53 {
54  return QTcpSocket::flush();
55 }
56 
57 void TcpSocket::socketDisconnected()
58 {
59  if (!processing) {
60  Q_EMIT finished();
61  } else {
62  protoData->socketDisconnected();
63  }
64 }
65 
66 LocalSocket::LocalSocket(Cutelyst::Engine *engine, QObject *parent)
67  : QLocalSocket(parent)
68  , Socket(false, engine)
69 {
70  connect(this,
72  this,
73  &LocalSocket::socketDisconnected,
75 }
76 
77 void LocalSocket::connectionClose()
78 {
81 }
82 
83 bool LocalSocket::requestFinished()
84 {
85  bool disconnected = state() != ConnectedState;
86  if (!--processing && disconnected) {
87  Q_EMIT finished();
88  }
89  return !disconnected;
90 }
91 
92 bool LocalSocket::flush()
93 {
94  return QLocalSocket::flush();
95 }
96 
97 void LocalSocket::socketDisconnected()
98 {
99  if (!processing) {
100  Q_EMIT finished();
101  } else {
102  protoData->socketDisconnected();
103  }
104 }
105 
106 #ifndef QT_NO_SSL
107 
108 SslSocket::SslSocket(Cutelyst::Engine *engine, QObject *parent)
109  : QSslSocket(parent)
110  , Socket(true, engine)
111 {
112  connect(this,
114  this,
115  &SslSocket::socketDisconnected,
117 }
118 
119 void SslSocket::connectionClose()
120 {
123 }
124 
125 bool SslSocket::requestFinished()
126 {
127  bool disconnected = state() != ConnectedState;
128  if (!--processing && disconnected) {
129  Q_EMIT finished();
130  }
131  return !disconnected;
132 }
133 
134 bool SslSocket::flush()
135 {
136  return QSslSocket::flush();
137 }
138 
139 void SslSocket::socketDisconnected()
140 {
141  if (!processing) {
142  Q_EMIT finished();
143  } else {
144  protoData->socketDisconnected();
145  }
146 }
147 
148 #endif // QT_NO_SSL
149 
150 #include "moc_socket.cpp"
SocketState state() const const
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
void disconnectFromServer()
The Cutelyst namespace holds all public Cutelyst API.
virtual void disconnectFromHost()
void disconnected()
DirectConnection
The Cutelyst Engine.
Definition: engine.h:19
LocalSocketState state() const const
Q_EMITQ_EMIT