Blob Blame Raw

#include "tunnel.h"
#include "connection.h"



Connection::Connection(const Args &args):
	tunnel(args.tunnel),
	id(args.id),
	tcpSockId(args.tcpSockId),
	udpActive(true),
	lastUdpInputTime(tunnel.time),
	lastUdpOutputTime(tunnel.time),
	tcpSendQueue(*this),
	tcpRecvQueue(*this),
	udpSendQueue(*this),
	udpRecvQueue(*this)
	{ }


Connection::~Connection() { }


bool Connection::wantReadFromTcp() const
	{ return tcpSockId >= 0 && udpActive && tcpRecvQueue.freeSize() > 0; }


bool Connection::wantWriteToTcp() const
	{ return tcpSockId >= 0 && (tcpSendQueue.busySize() > 0 || udpRecvQueue.canSentToTcp()); }


Time Connection::whenWriteToUdp() const {
	Time t = lastUdpOutputTime + tunnel.udpKeepAliveDuration;
	udpSendQueue.whenWriteToUdp(t);
	udpRecvQueue.whenWriteToUdp(t);
	return t;
}