From a45977185a485624095bff1a15024e9199eee676 Mon Sep 17 00:00:00 2001 From: Javier Date: Fri, 1 Jan 2016 22:05:42 +0100 Subject: reorganize source files into SAP and agents --- sap/sapsocket.h | 76 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 sap/sapsocket.h (limited to 'sap/sapsocket.h') diff --git a/sap/sapsocket.h b/sap/sapsocket.h new file mode 100644 index 0000000..59fcb3c --- /dev/null +++ b/sap/sapsocket.h @@ -0,0 +1,76 @@ +#ifndef SAPSOCKET_H +#define SAPSOCKET_H + +#include +#include +#include + +#include "sapchannelinfo.h" + +class SAPConnection; +class SAPPeer; + +class SAPSocket : public QObject +{ + Q_OBJECT + + SAPSocket(SAPConnection *conn, int sessionId, const SAPChannelInfo &chanInfo); + +public: + SAPPeer *peer(); + SAPConnection *connection(); + + SAPChannelInfo channelInfo() const; + + bool isOpen() const; + + bool messageAvailable() const; + QByteArray receive(); + bool send(const QByteArray &data); + +signals: + void connected(); + void disconnected(); + void messageReceived(); + +protected: + void setOpen(bool open); + void acceptIncomingData(const QByteArray &data); + void acceptIncomingControl(const QByteArray &data); + + int sessionId() const; + + virtual void timerEvent(QTimerEvent *event) override; + +private: + bool isReliable() const; + bool supportsFragmentation() const; + + void sendBlockAck(int seqNum); + void sendPacket(int seqNum, const QByteArray &data); + + void handleBlockAck(int seqNum); + void sendPacketsFromQueue(); + +private: + const int _sessionId; + const SAPChannelInfo _info; + bool _open; + QQueue _in; + QQueue _out; + QBasicTimer _ackTimer; + QBasicTimer _resendTimer; + + /** Last acknowledged sent message. */ + quint16 _outLastAck; + quint16 _outFlyingPkts; + + /** Next expected incoming sequence number */ + quint16 _inLastSeqNum; + /** Last acknowledged sequence number */ + quint16 _inLastAck; + + friend class SAPPeer; +}; + +#endif // SAPSOCKET_H -- cgit v1.2.3