aboutsummaryrefslogtreecommitdiff
path: root/Hotline/Library/NetSocket.swift
diff options
context:
space:
mode:
authorDustin Mierau <dustin@mierau.me>2025-10-25 17:03:02 -0700
committerDustin Mierau <dustin@mierau.me>2025-10-25 17:03:02 -0700
commit9857e39c81ce73d4347fa026a031c8389e42c3f3 (patch)
tree80fef947642aacb33d6e588cb7d8756bf4ad8eb8 /Hotline/Library/NetSocket.swift
parent3b3b965842c47939ca54d0d1cbdf469346847f14 (diff)
Experiement with better socket options.
Diffstat (limited to 'Hotline/Library/NetSocket.swift')
-rw-r--r--Hotline/Library/NetSocket.swift25
1 files changed, 15 insertions, 10 deletions
diff --git a/Hotline/Library/NetSocket.swift b/Hotline/Library/NetSocket.swift
index a7d44ce..b1f1742 100644
--- a/Hotline/Library/NetSocket.swift
+++ b/Hotline/Library/NetSocket.swift
@@ -254,16 +254,21 @@ final class NetSocket: NSObject, StreamDelegate {
if setsockopt(socketHandle, SOL_SOCKET, SO_KEEPALIVE, &value, size) != 0 {
print("NetSocket: failed to set SO_KEEPALIVE");
}
-// // Number of keepalives before close (including first keepalive packet)
-// value = 5
-// if setsockopt(socketHandle, IPPROTO_TCP, TCP_KEEPCNT, &value, size) != 0 {
-// print("NetSocket: failed to set TCP_KEEPCNT");
-// }
-// // Idle time used when SO_KEEPALIVE is enabled. Sets how long connection must be idle before keepalive is sent.
-// value = 60
-// if setsockopt(socketHandle, IPPROTO_TCP, TCP_KEEPALIVE, &value, size) != 0 {
-// print("NetSocket: failed to set TCP_KEEPALIVE")
-// }
+ // Number of keepalives before close (including first keepalive packet)
+ value = 5
+ if setsockopt(socketHandle, IPPROTO_TCP, TCP_KEEPCNT, &value, size) != 0 {
+ print("NetSocket: failed to set TCP_KEEPCNT");
+ }
+ // Idle time used when SO_KEEPALIVE is enabled. Sets how long connection must be idle before keepalive is sent.
+ value = 30
+ if setsockopt(socketHandle, IPPROTO_TCP, TCP_KEEPALIVE, &value, size) != 0 {
+ print("NetSocket: failed to set TCP_KEEPALIVE")
+ }
+ // Idle time used when TCP_KEEPINTVL is enabled. Sets how long to wait between probes.
+ value = 10
+ if setsockopt(socketHandle, IPPROTO_TCP, TCP_KEEPINTVL, &value, size) != 0 {
+ print("NetSocket: failed to set TCP_KEEPINTVL")
+ }
}
}
}