aboutsummaryrefslogtreecommitdiffstats
path: root/mock-server/EchoServer.h
blob: c0a41c9ee646cf3caec1dae0cd0d6cb45933bef4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
/**
 * @file   EchoServer.h
 * @brief  Mock XPL2 server for a single port.
 */
#pragma once

#include <QList>
#include <QTcpServer>
#include <QTimer>

class QTcpSocket;

class EchoServer : public QTcpServer
{
  Q_OBJECT

public:
  EchoServer (quint16 port, const char *name, QObject *parent = nullptr);

private slots:
  void onNewConnection ();
  void onClientMessageReady ();
  void onClientDisconnected ();
  void sendKaPing ();

private:
  void handleCommand (QTcpSocket *client, const QByteArray &line);

  const char *m_name;
  quint16 m_port;
  QList<QTcpSocket *> m_clients;
  QTimer m_pingTimer;
};