diff options
Diffstat (limited to 'gatosocket.h')
-rw-r--r-- | gatosocket.h | 54 |
1 files changed, 54 insertions, 0 deletions
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 <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 |