cutelyst 4.3.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
11Q_LOGGING_CATEGORY(C_SERVER_SOCK, "cutelyst.server.socket", QtWarningMsg)
12
13using namespace Cutelyst;
14
15Socket::Socket(bool secure, Cutelyst::Engine *_engine)
16 : engine(_engine)
17 , isSecure(secure)
18{
19}
20
21Socket::~Socket()
22{
23 delete protoData;
24}
25
27 : QTcpSocket(parent)
28 , Socket(false, engine)
29{
30 connect(this,
32 this,
33 &TcpSocket::socketDisconnected,
35}
36
37void TcpSocket::connectionClose()
38{
41}
42
43bool TcpSocket::requestFinished()
44{
46 if (!--processing && disconnected) {
47 Q_EMIT finished();
48 }
49 return !disconnected;
50}
51
52bool TcpSocket::flush()
53{
54 return QTcpSocket::flush();
55}
56
57void TcpSocket::socketDisconnected()
58{
59 if (!processing) {
60 Q_EMIT finished();
61 } else {
62 protoData->socketDisconnected();
63 }
64}
65
66LocalSocket::LocalSocket(Cutelyst::Engine *engine, QObject *parent)
67 : QLocalSocket(parent)
68 , Socket(false, engine)
69{
70 connect(this,
72 this,
73 &LocalSocket::socketDisconnected,
75}
76
77void LocalSocket::connectionClose()
78{
81}
82
83bool LocalSocket::requestFinished()
84{
86 if (!--processing && disconnected) {
87 Q_EMIT finished();
88 }
89 return !disconnected;
90}
91
92bool LocalSocket::flush()
93{
94 return QLocalSocket::flush();
95}
96
97void LocalSocket::socketDisconnected()
98{
99 if (!processing) {
100 Q_EMIT finished();
101 } else {
102 protoData->socketDisconnected();
103 }
104}
105
106#ifndef QT_NO_SSL
107
108SslSocket::SslSocket(Cutelyst::Engine *engine, QObject *parent)
109 : QSslSocket(parent)
110 , Socket(true, engine)
111{
112 connect(this,
114 this,
115 &SslSocket::socketDisconnected,
117}
118
119void SslSocket::connectionClose()
120{
123}
124
125bool SslSocket::requestFinished()
126{
128 if (!--processing && disconnected) {
129 Q_EMIT finished();
130 }
131 return !disconnected;
132}
133
134bool SslSocket::flush()
135{
136 return QSslSocket::flush();
137}
138
139void 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"
The Cutelyst Engine.
Definition engine.h:20
The Cutelyst namespace holds all public Cutelyst API.
virtual void disconnectFromHost()
QAbstractSocket::SocketState state() const const
void disconnectFromServer()
void disconnected()
QLocalSocket::LocalSocketState state() const const
Q_EMITQ_EMIT
DirectConnection
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)