mirror of
https://github.com/Syncplay/syncplay
synced 2025-02-06 14:11:48 +00:00
Check if the server is listening on either IPv4 or IPv6, avoid errors happening in dual stack configurations
This commit is contained in:
parent
cb66180328
commit
285428fb03
@ -18,6 +18,28 @@ from twisted.internet.endpoints import TCP4ServerEndpoint, TCP6ServerEndpoint
|
||||
|
||||
from syncplay.server import SyncFactory, ConfigurationGetter
|
||||
|
||||
class ServerStatus: pass
|
||||
|
||||
def isListening6(f):
|
||||
ServerStatus.listening6 = True
|
||||
|
||||
def isListening4(f):
|
||||
ServerStatus.listening4 = True
|
||||
|
||||
def failed6(f):
|
||||
ServerStatus.listening6 = False
|
||||
print(f.value)
|
||||
print("IPv6 listening failed.")
|
||||
|
||||
def failed4(f):
|
||||
ServerStatus.listening4 = False
|
||||
if ServerStatus.listening6 and "Address already in use" in str(f.value):
|
||||
pass
|
||||
else:
|
||||
print(f.value)
|
||||
print("IPv4 listening failed.")
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
argsGetter = ConfigurationGetter()
|
||||
args = argsGetter.getConfiguration()
|
||||
@ -34,8 +56,12 @@ if __name__ == '__main__':
|
||||
args.stats_db_file,
|
||||
args.tls
|
||||
)
|
||||
endpoint4 = TCP4ServerEndpoint(reactor, int(args.port))
|
||||
endpoint4.listen(factory)
|
||||
endpoint6 = TCP6ServerEndpoint(reactor, int(args.port))
|
||||
endpoint6.listen(factory)
|
||||
reactor.run()
|
||||
endpoint6.listen(factory).addCallbacks(isListening6, failed6)
|
||||
endpoint4 = TCP4ServerEndpoint(reactor, int(args.port))
|
||||
endpoint4.listen(factory).addCallbacks(isListening4, failed4)
|
||||
if ServerStatus.listening6 or ServerStatus.listening4:
|
||||
reactor.run()
|
||||
else:
|
||||
print("Unable to listen using either IPv4 and IPv6 protocols. Quitting the server now.")
|
||||
sys.exit()
|
||||
|
Loading…
Reference in New Issue
Block a user