cutelyst 4.3.0
A C++ Web Framework built on top of Qt, using the simple approach of Catalyst (Perl) framework.
socket.h
1/*
2 * SPDX-FileCopyrightText: (C) 2016-2018 Daniel Nicoletti <dantti12@gmail.com>
3 * SPDX-License-Identifier: BSD-3-Clause
4 */
5#ifndef SOCKET_H
6#define SOCKET_H
7
9#include "protocol.h"
10#include "serverengine.h"
11
12#include <Cutelyst/Headers>
13
14#include <QHostAddress>
15#include <QLocalSocket>
16#include <QSslSocket>
17#include <QTcpSocket>
18
19class QIODevice;
20
21namespace Cutelyst {
22
23class Engine;
24class Socket
25{
26 Q_GADGET
27public:
28 Socket(bool secure, Engine *_engine);
29 virtual ~Socket();
30
31 virtual void connectionClose() = 0;
32
33 // Returns false if disconnected
34 virtual bool requestFinished() = 0;
35 virtual bool flush() = 0;
36
37 inline void resetSocket()
38 {
39 if (protoData->upgradedFrom) {
40 ProtocolData *data = protoData->upgradedFrom;
41 delete protoData;
42 protoData = data;
43 }
44 processing = 0;
45
46 protoData->resetData();
47 }
48
49 QByteArray serverAddress;
50 QHostAddress remoteAddress;
51 quint16 remotePort = 0;
52 Engine *engine;
53 Protocol *proto = nullptr;
54 ProtocolData *protoData = nullptr;
55 qint8 processing = 0;
56 bool isSecure;
57 bool timeout = false;
58};
59
60class TcpSocket final
61 : public QTcpSocket
62 , public Socket
63{
65public:
66 explicit TcpSocket(Cutelyst::Engine *engine, QObject *parent = nullptr);
67
68 void connectionClose() override final;
69 bool requestFinished() override final;
70 bool flush() override final;
71 void socketDisconnected();
72
74 // Always connect this in queued mode as the client might have
75 // triggered the disconnect event like websocket close, and deleting
76 // it's context from this event will crash
77 void finished();
78};
79
80#ifndef QT_NO_SSL
81
82class SslSocket final
83 : public QSslSocket
84 , public Socket
85{
87public:
88 explicit SslSocket(Cutelyst::Engine *engine, QObject *parent = nullptr);
89
90 void connectionClose() override final;
91 bool requestFinished() override final;
92 bool flush() override final;
93 void socketDisconnected();
94
96 // See TcpSocket note
97 void finished();
98};
99
100#endif // QT_NO_SSL
101
102class LocalSocket final
103 : public QLocalSocket
104 , public Socket
105{
107public:
108 explicit LocalSocket(Cutelyst::Engine *engine, QObject *parent = nullptr);
109
110 void connectionClose() override final;
111 bool requestFinished() override final;
112 bool flush() override final;
113 void socketDisconnected();
114
116 // See TcpSocket note
117 void finished();
118};
119
120} // namespace Cutelyst
121
122#endif // SOCKET_H
The Cutelyst Engine.
Definition engine.h:20
The Cutelyst namespace holds all public Cutelyst API.
Q_OBJECTQ_OBJECT
Q_SIGNALSQ_SIGNALS
QObject * parent() const const