Blame connection.cpp

873e9f
873e9f
#include "tunnel.h"
873e9f
#include "connection.h"
873e9f
873e9f
c47604
c47604
Connection::Connection(const Args &args):
c47604
	tunnel(args.tunnel),
c47604
	id(args.id),
c47604
	tcpSockId(args.tcpSockId),
873e9f
	udpActive(true),
c47604
	lastUdpInputTime(tunnel.time),
c47604
	lastUdpOutputTime(tunnel.time),
873e9f
	tcpSendQueue(*this),
873e9f
	tcpRecvQueue(*this),
873e9f
	udpSendQueue(*this),
873e9f
	udpRecvQueue(*this)
873e9f
	{ }
873e9f
c47604
873e9f
Connection::~Connection() { }
873e9f
c47604
c47604
bool Connection::wantReadFromTcp() const
c47604
	{ return tcpSockId >= 0 && udpActive && tcpRecvQueue.freeSize() > 0; }
c47604
c47604
c47604
bool Connection::wantWriteToTcp() const
c47604
	{ return tcpSockId >= 0 && (tcpSendQueue.busySize() > 0 || udpRecvQueue.canSentToTcp()); }
c47604
c47604
1d16df
void Connection::whenWriteToUdp(Time &t) const {
1d16df
	if (timeLess(lastUdpOutputTime + tunnel.udpKeepAliveDuration, t))
1d16df
		t = lastUdpOutputTime + tunnel.udpKeepAliveDuration;
c47604
	udpSendQueue.whenWriteToUdp(t);
c47604
	udpRecvQueue.whenWriteToUdp(t);
c47604
}
c47604