mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2025-06-07 13:03:45 +02:00
Reduce TCP relay latency -- see GitHub issue #564
This commit is contained in:
parent
ba07a60c44
commit
4352202349
1 changed files with 24 additions and 13 deletions
|
@ -2142,9 +2142,14 @@ public:
|
||||||
const uint64_t now = OSUtils::now();
|
const uint64_t now = OSUtils::now();
|
||||||
if (((now - _lastDirectReceiveFromGlobal) > ZT_TCP_FALLBACK_AFTER)&&((now - _lastRestart) > ZT_TCP_FALLBACK_AFTER)) {
|
if (((now - _lastDirectReceiveFromGlobal) > ZT_TCP_FALLBACK_AFTER)&&((now - _lastRestart) > ZT_TCP_FALLBACK_AFTER)) {
|
||||||
if (_tcpFallbackTunnel) {
|
if (_tcpFallbackTunnel) {
|
||||||
|
bool flushNow = false;
|
||||||
|
{
|
||||||
Mutex::Lock _l(_tcpFallbackTunnel->writeq_m);
|
Mutex::Lock _l(_tcpFallbackTunnel->writeq_m);
|
||||||
if (_tcpFallbackTunnel->writeq.length() == 0)
|
if (_tcpFallbackTunnel->writeq.size() < (1024 * 64)) {
|
||||||
|
if (_tcpFallbackTunnel->writeq.length() == 0) {
|
||||||
_phy.setNotifyWritable(_tcpFallbackTunnel->sock,true);
|
_phy.setNotifyWritable(_tcpFallbackTunnel->sock,true);
|
||||||
|
flushNow = true;
|
||||||
|
}
|
||||||
const unsigned long mlen = len + 7;
|
const unsigned long mlen = len + 7;
|
||||||
_tcpFallbackTunnel->writeq.push_back((char)0x17);
|
_tcpFallbackTunnel->writeq.push_back((char)0x17);
|
||||||
_tcpFallbackTunnel->writeq.push_back((char)0x03);
|
_tcpFallbackTunnel->writeq.push_back((char)0x03);
|
||||||
|
@ -2155,6 +2160,12 @@ public:
|
||||||
_tcpFallbackTunnel->writeq.append(reinterpret_cast<const char *>(reinterpret_cast<const void *>(&(reinterpret_cast<const struct sockaddr_in *>(addr)->sin_addr.s_addr))),4);
|
_tcpFallbackTunnel->writeq.append(reinterpret_cast<const char *>(reinterpret_cast<const void *>(&(reinterpret_cast<const struct sockaddr_in *>(addr)->sin_addr.s_addr))),4);
|
||||||
_tcpFallbackTunnel->writeq.append(reinterpret_cast<const char *>(reinterpret_cast<const void *>(&(reinterpret_cast<const struct sockaddr_in *>(addr)->sin_port))),2);
|
_tcpFallbackTunnel->writeq.append(reinterpret_cast<const char *>(reinterpret_cast<const void *>(&(reinterpret_cast<const struct sockaddr_in *>(addr)->sin_port))),2);
|
||||||
_tcpFallbackTunnel->writeq.append((const char *)data,len);
|
_tcpFallbackTunnel->writeq.append((const char *)data,len);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (flushNow) {
|
||||||
|
void *tmpptr = (void *)_tcpFallbackTunnel;
|
||||||
|
phyOnTcpWritable(_tcpFallbackTunnel->sock,&tmpptr);
|
||||||
|
}
|
||||||
} else if (((now - _lastSendToGlobalV4) < ZT_TCP_FALLBACK_AFTER)&&((now - _lastSendToGlobalV4) > (ZT_PING_CHECK_INVERVAL / 2))) {
|
} else if (((now - _lastSendToGlobalV4) < ZT_TCP_FALLBACK_AFTER)&&((now - _lastSendToGlobalV4) > (ZT_PING_CHECK_INVERVAL / 2))) {
|
||||||
const InetAddress addr(ZT_TCP_FALLBACK_RELAY);
|
const InetAddress addr(ZT_TCP_FALLBACK_RELAY);
|
||||||
TcpConnection *tc = new TcpConnection();
|
TcpConnection *tc = new TcpConnection();
|
||||||
|
|
Loading…
Add table
Reference in a new issue