From 74915af509e4a6b215aebe5f53fde53c5e646df7 Mon Sep 17 00:00:00 2001 From: Maciek Borzecki Date: Sat, 14 Oct 2017 19:13:05 +0200 Subject: [PATCH] share, transfer-manager: handle a case when all ports are busy --- src/mconnect/share.vala | 4 ++++ src/mconnect/transfer-manager.vala | 3 ++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/mconnect/share.vala b/src/mconnect/share.vala index af5181b..35acf49 100644 --- a/src/mconnect/share.vala +++ b/src/mconnect/share.vala @@ -193,6 +193,10 @@ class ShareHandler : Object, PacketHandlerInterface { uint16 port; var listener = Core.instance().transfer_manager.make_listener(out port); + if (listener == null) { + warning("coult not allodate a listener"); + return; + } debug("allocated listener on port %u", port); var t = new UploadTransfer(dev, listener, input, size); diff --git a/src/mconnect/transfer-manager.vala b/src/mconnect/transfer-manager.vala index 9d8999c..48101a6 100644 --- a/src/mconnect/transfer-manager.vala +++ b/src/mconnect/transfer-manager.vala @@ -32,7 +32,7 @@ class TransferManager : Object { new_transfer(job); } - public SocketService make_listener(out uint16 listen_port) { + public SocketService? make_listener(out uint16 listen_port) { var ss = new SocketService(); for (var port = PORT_MIN; port <= PORT_MAX; port++) { var added = false; @@ -49,6 +49,7 @@ class TransferManager : Object { return ss; } } + ss.close(); warning("could not find a free port to listen on"); return null; }