Merge pull request #167 from xobs/network-flag-check

litex_server: check socket flags exist before using them
This commit is contained in:
enjoy-digital 2019-04-20 12:23:24 +02:00 committed by GitHub
commit 67a79d7c92
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 1 deletions

View File

@ -21,8 +21,13 @@ class RemoteServer(EtherboneIPC):
def open(self):
if hasattr(self, "socket"):
return
socket_flags = 0
if hasattr(socket, "SO_REUSEADDR"):
socket_flags = socket_flags | socket.SO_REUSEADDR
if hasattr(socket, "SO_REUSEPORT"):
socket_flags = socket_flags | socket.SO_REUSEPORT
self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEPORT, 1)
self.socket.setsockopt(socket.SOL_SOCKET, socket_flags, 1)
self.socket.bind((self.bind_ip, self.bind_port))
print("tcp port: {:d}".format(self.bind_port))
self.socket.listen(1)