summaryrefslogtreecommitdiff
path: root/sapsocket.cc
diff options
context:
space:
mode:
authorJavier <dev.git@javispedro.com>2015-12-14 01:52:17 +0100
committerJavier <dev.git@javispedro.com>2015-12-14 01:52:17 +0100
commit702e018ca9e780bb076033ce5d1d370d4eb7319e (patch)
tree2012493213c630d7281718aadd1a6fa9a2c92885 /sapsocket.cc
parentce8a092a235c8d59f01631c80786f920eb6a777b (diff)
downloadsapd-702e018ca9e780bb076033ce5d1d370d4eb7319e.tar.gz
sapd-702e018ca9e780bb076033ce5d1d370d4eb7319e.zip
properly handle data frames with sequence numbers
Diffstat (limited to 'sapsocket.cc')
-rw-r--r--sapsocket.cc49
1 files changed, 45 insertions, 4 deletions
diff --git a/sapsocket.cc b/sapsocket.cc
index ce85c0c..472865c 100644
--- a/sapsocket.cc
+++ b/sapsocket.cc
@@ -4,8 +4,9 @@
#include "sapconnection.h"
#include "sapsocket.h"
-SAPSocket::SAPSocket(SAPConnection *conn, int sessionId) :
- QObject(conn), _sessionId(sessionId), _open(false)
+SAPSocket::SAPSocket(SAPConnection *conn, int sessionId, const SAPChannelInfo &chanInfo) :
+ QObject(conn), _sessionId(sessionId), _info(chanInfo), _open(false),
+ _seqNum(0), _expectedSeqNum(0)
{
}
@@ -19,6 +20,11 @@ SAPConnection * SAPSocket::connection()
return static_cast<SAPConnection*>(parent());
}
+SAPChannelInfo SAPSocket::channelInfo() const
+{
+ return _info;
+}
+
bool SAPSocket::isOpen() const
{
return _open;
@@ -40,7 +46,18 @@ QByteArray SAPSocket::receive()
bool SAPSocket::send(const QByteArray &data)
{
- return peer()->writeToSession(_sessionId, data);
+ SAProtocol::DataFrame frame;
+
+ frame.withSeqNum = isWithSeqNum();
+ if (isReliable()) {
+ frame.seqNum = _seqNum++;
+ } else {
+ frame.seqNum = 0;
+ }
+ frame.unk_1 = 0;
+ frame.data = data;
+
+ return peer()->writeToSession(_sessionId, SAProtocol::packDataFrame(frame));
}
void SAPSocket::setOpen(bool open)
@@ -51,7 +68,20 @@ void SAPSocket::setOpen(bool open)
void SAPSocket::acceptIncomingData(const QByteArray &data)
{
if (data.isEmpty()) return;
- _in.enqueue(data);
+ SAProtocol::DataFrame frame = SAProtocol::unpackDataFrame(data, isWithSeqNum());
+
+ if (isReliable()) {
+ if (frame.seqNum != _expectedSeqNum) {
+ qWarning() << "Unexpected sequence number" << frame.seqNum
+ << "on session" << _sessionId
+ << "(expected " << _expectedSeqNum << ")";
+ }
+ _expectedSeqNum = frame.seqNum + 1;
+
+ // TODO Do we actually need to ack this somehow?
+ }
+
+ _in.enqueue(frame.data);
emit messageReceived();
}
@@ -60,3 +90,14 @@ int SAPSocket::sessionId() const
{
return _sessionId;
}
+
+bool SAPSocket::isReliable() const
+{
+ return _info.qosType() == SAPChannelInfo::QoSReliabilityEnable;
+}
+
+bool SAPSocket::isWithSeqNum() const
+{
+ return _info.qosType() == SAPChannelInfo::QoSReliabilityDisable ||
+ _info.qosType() == SAPChannelInfo::QoSReliabilityEnable;
+}