Skip to content

Commit

Permalink
#2424 allow TCP_NODELAY and TCP_CORK to be configured per-socket
Browse files Browse the repository at this point in the history
git-svn-id: https://xpra.org/svn/Xpra/trunk@23896 3bb7dfac-3a0b-4e04-842a-767bc560f471
  • Loading branch information
totaam committed Sep 23, 2019
1 parent ff5d901 commit fc4b039
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 10 deletions.
1 change: 1 addition & 0 deletions src/man/xpra.1
Original file line number Diff line number Diff line change
Expand Up @@ -641,6 +641,7 @@ Although this is still supported as a fallback, the recommended
way is to specify authentication options using bind properties.
ie: \fIbind-tcp=0.0.0.0:14500,auth=file:filename=password.txt\fP.
For more details on authentication configuration, see \fIauth=\fP.
The properties can also define extra configuration options.

\fB--bind\fP=\fIBIND_LOCATION[,PROPERTIES]\fP
Create a local Unix domain socket (on Unix)
Expand Down
35 changes: 25 additions & 10 deletions src/xpra/net/bytestreams.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,27 +276,42 @@ def __init__(self, sock, local, remote, target, socktype, info=None, socket_opti
self.local = local
self.remote = remote
self.protocol_type = "socket"
self.nodelay = None
self.cork = None
if self.socktype_wrapped in TCP_SOCKTYPES:
def boolget(k, default_value):
v = self.options.get(k)
if v is None:
return default_value
try:
return bool(int(v))
except ValueError:
return default_value
self.cork = boolget("cork", SOCKET_CORK)
self.nodelay = boolget("nodelay", SOCKET_NODELAY)
log("%s options: cork=%s, nodelay=%s", self.socktype_wrapped, self.cork, self.nodelay)
if self.nodelay:
self.do_set_nodelay(self.nodelay)
else:
self.cork = False
self.nodelay = False
self.nodelay_value = None
self.cork_value = None
if isinstance(remote, str):
self.filename = remote
if SOCKET_NODELAY is not None and self.socktype in TCP_SOCKTYPES:
self.do_set_nodelay(SOCKET_NODELAY)

def set_nodelay(self, nodelay : bool):
if SOCKET_NODELAY is None and self.socktype_wrapped in TCP_SOCKTYPES and self.nodelay!=nodelay:
if self.nodelay is None and self.nodelay_value!=nodelay:
self.do_set_nodelay(nodelay)

def do_set_nodelay(self, nodelay : bool):
self._socket.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, nodelay)
self.nodelay = nodelay
log("changed %s socket to nodelay=%s", self.socktype, nodelay)
self.nodelay_value = nodelay
log.info("changed %s socket to nodelay=%s", self.socktype, nodelay)

def set_cork(self, cork : bool):
if SOCKET_CORK and self.socktype_wrapped in TCP_SOCKTYPES and self.cork!=cork:
if self.cork and self.cork_value!=cork:
self._socket.setsockopt(socket.IPPROTO_TCP, socket.TCP_CORK, cork)
self.cork = cork
log("changed %s socket to cork=%s", self.socktype, cork)
self.cork_value = cork
log.info("changed %s socket to cork=%s", self.socktype, cork)

def peek(self, n : int):
return self._socket.recv(n, socket.MSG_PEEK)
Expand Down

0 comments on commit fc4b039

Please sign in to comment.