Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stream server source fix #134

Merged
merged 10 commits into from
Jan 4, 2022
Merged
35 changes: 16 additions & 19 deletions bspump/ipc/datagram.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,16 @@ def __init__(self, app, pipeline, id=None, config=None):
self.ReceiveBufferSize = int(self.Config['receiver_buffer_size'])

addrline = self.Address.strip()
if " " in addrline:
host, port = self.Address.rsplit(" ", maxsplit=1)
elif addrline.count(":") == 1:
if addrline.count(":") == 1:
host, port = self.Address.rsplit(":", maxsplit=1)
(family, socktype, proto, canonname, sockaddr) = socket.getaddrinfo(host, port)[0]
(family, socktype, proto, canonname, sockaddr) = socket.getaddrinfo(host, port)[0]

self.Socket = socket.socket(family, socket.SOCK_DGRAM)
self.Socket.setblocking(False)
self.Socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
self.Socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEPORT, 1)
if self.ReceiveBufferSize > 0:
self.Socket.setsockopt(socket.SOL_SOCKET, socket.SO_RCVBUF, self.ReceiveBufferSize)
self.Socket = socket.socket(family, socket.SOCK_DGRAM)
self.Socket.setblocking(False)
self.Socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
self.Socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEPORT, 1)
if self.ReceiveBufferSize > 0:
self.Socket.setsockopt(socket.SOL_SOCKET, socket.SO_RCVBUF, self.ReceiveBufferSize)

self.Socket.bind(sockaddr)

Expand Down Expand Up @@ -114,19 +112,18 @@ def __init__(self, app, pipeline, id=None, config=None):
host, port = self.Address.rsplit(" ", maxsplit=1)
elif addrline.count(":") == 1:
host, port = self.Address.rsplit(":", maxsplit=1)
(family, socktype, proto, canonname, sockaddr) = socket.getaddrinfo(host, port)[0]
(family, socktype, proto, canonname, sockaddr) = socket.getaddrinfo(host, port)[0]

self.Socket = socket.socket(family, socket.SOCK_DGRAM)
self.Socket.setblocking(False)
self.Socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
self.Socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEPORT, 1)
if self.ReceiveBufferSize > 0:
self.Socket.setsockopt(socket.SOL_SOCKET, socket.SO_RCVBUF, self.ReceiveBufferSize)
self.Socket = socket.socket(family, socket.SOCK_DGRAM)
self.Socket.setblocking(False)
self.Socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
self.Socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEPORT, 1)
if self.ReceiveBufferSize > 0:

self.Socket.connect(sockaddr)
self.Socket.setsockopt(socket.SOL_SOCKET, socket.SO_RCVBUF, self.ReceiveBufferSize)

self.Socket.connect(sockaddr)
else:

self.Socket = socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM)
self.Socket.setblocking(False)
self.Socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
Expand Down
39 changes: 19 additions & 20 deletions bspump/ipc/stream_server_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,28 +54,27 @@ def start(self, loop):
# Create all required sockets, bind them to specific ports and start listening
for addrline in self.Address.split('\n'):
addrline = addrline.strip()
if " " in addrline:
# IP server socket server
host, port = addrline.rsplit(" ", maxsplit=1)
elif addrline.count(":") == 1:

if addrline.count(":") == 1:
host, port = self.Address.rsplit(":", maxsplit=1)

addrinfo = socket.getaddrinfo(host, port, family=socket.AF_UNSPEC, type=socket.SOCK_STREAM, flags=socket.AI_PASSIVE)
for family, socktype, proto, canonname, sockaddr in addrinfo:
s = socket.socket(family, socktype, proto)
try:
s.bind(sockaddr)
except OSError as e:
L.warning("Failed to start listening at '{}': {}".format(addrline, e))
continue

backlog = self.Config['backlog']
if backlog == '':
s.listen()
else:
s.listen(int(backlog))
s.setblocking(False)
self.AcceptingSockets.append(s)
addrinfo = socket.getaddrinfo(host, port, family=socket.AF_UNSPEC, type=socket.SOCK_STREAM, flags=socket.AI_PASSIVE)

for family, socktype, proto, canonname, sockaddr in addrinfo:
s = socket.socket(family, socktype, proto)
try:
s.bind(sockaddr)
except OSError as e:
L.warning("Failed to start listening at '{}': {}".format(addrline, e))
continue

backlog = self.Config['backlog']
if backlog == '':
s.listen()
else:
s.listen(int(backlog))
s.setblocking(False)
self.AcceptingSockets.append(s)
else:
self.Socket = socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM)
self.Socket.setblocking(False)
Expand Down