blob: 6bb6998024ab731217fc5574fa385b50c03adc67 (
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
#ifndef GATOSOCKET_H
#define GATOSOCKET_H
#include <QtCore/QObject>
#include <QtCore/QQueue>
#include <QtCore/QSocketNotifier>
#include "gatoaddress.h"
class GatoSocket : public QObject
{
Q_OBJECT
Q_ENUMS(State)
public:
explicit GatoSocket(QObject *parent);
~GatoSocket();
enum State {
StateDisconnected,
StateConnecting,
StateConnected
};
State state() const;
bool connectTo(const GatoAddress &addr, unsigned short cid);
void close();
QByteArray receive();
void send(const QByteArray &pkt);
signals:
void connected();
void disconnected();
void readyRead();
private:
bool transmit(const QByteArray &pkt);
private slots:
void readNotify();
void writeNotify();
private:
State s;
int fd;
QSocketNotifier *readNotifier;
QQueue<QByteArray> readQueue;
QSocketNotifier *writeNotifier;
QQueue<QByteArray> writeQueue;
};
#endif // GATOSOCKET_H
|