From 47ada94baa424e56d2ded256fddc91e6aa4d3090 Mon Sep 17 00:00:00 2001 From: "Javier S. Pedro" Date: Tue, 3 Dec 2013 03:05:47 +0100 Subject: initial import --- gatosocket.h | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 gatosocket.h (limited to 'gatosocket.h') diff --git a/gatosocket.h b/gatosocket.h new file mode 100644 index 0000000..6bb6998 --- /dev/null +++ b/gatosocket.h @@ -0,0 +1,54 @@ +#ifndef GATOSOCKET_H +#define GATOSOCKET_H + +#include +#include +#include + +#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 readQueue; + QSocketNotifier *writeNotifier; + QQueue writeQueue; +}; + +#endif // GATOSOCKET_H -- cgit v1.2.3