1 #ifndef TRM_QT_WEBSOCKETSERVER_H
2 #define TRM_QT_WEBSOCKETSERVER_H
4 #include <openssl/ssl.h>
7 #include <QtCore/QObject>
10 #include <unordered_map>
22 int setUpServer(
const char* ipAddress,
unsigned short port_num,
const char *ca_pem,
23 const char *cert_pem,
const char *key_pem);
27 void connected (
int clientId, QString msg);
28 void messageReceived (
int clientId,
char* message,
size_t len);
29 void disconnected (
int clientId);
30 void socketError (QString err);
31 void sslErrors (QString err);
32 void acceptError (QString err);
33 void peerVerifyError (QString err);
37 void freeSSLContext(SSL_CTX *ctx);
38 SSL_CTX * get_server_context_pk12(
const char *ca_pem,
39 const char *cert_pk12,
const char *pass);
40 int get_socket(
const char* ipAddress,
unsigned short port_num);
41 bool SetSocketBlockingEnabled(
int fd,
bool blocking);
43 void onSocketError (QString err);
44 void setPingMsg (
int clientId,
const char* uniqueId,
int len);
45 std::unordered_map <int, std::chrono::high_resolution_clock::time_point> m_clientPingTimeList;
48 bool m_isServerprocessingEnabled;
49 std::unordered_map <int, SSL*> m_clientSSLCtxList;
50 std::unordered_map <int, bool*> m_clientSSLIsReadEnabledList;
51 std::unordered_map <int, std::string> m_clientPingMsgList;
52 SSL_CTX *m_serverSSlCtx;
53 int m_serverSocketListenfd;
56 std::function<void(
int,
char*,
unsigned int)> onMessageReceivedCallBack;
57 std::function<void(
int,
long long unsigned int, QByteArray&)> onPongCallBack;
59 void closeClient(
int clientId);
60 void closeAllClients();
64 void onConnected (
int clientId, QString msg);
65 void onMessageReceived (
int clientId,
char* message,
size_t len);
66 void onDisconnected (
int clientId);
67 void onSslErrors (QString err);
68 void onPeerVerifyError (QString err);
69 void onAcceptError (QString err);
71 void sendTextMessage (
int clientId,
const char* buffer,
int len);
72 void ping (
int clientId);
73 void onPong (
int clientId,
char* msg,
int len);
76 #endif //TRM_QT_WEBSOCKETSERVER_H