Commit b71513d7 authored by Colomban Wendling's avatar Colomban Wendling
Browse files

Make sure the client's listen thread stops listening upon disconnection

parent e34c9445
......@@ -34,6 +34,7 @@ namespace OVCCClient
private DataInputStream input;
private DataOutputStream output;
private SignalHandle signal_handle = null;
private Cancellable? listen_loop_cancel = null;
public Server (string host,
uint16 port)
......@@ -110,11 +111,15 @@ namespace OVCCClient
throws ServerError
requires (connection != null)
{
if (listen_loop_cancel != null) {
listen_loop_cancel.cancel ();
}
try {
send_message (new DisconnectMessage ());
connection.socket.close();
} catch {
} catch (Error e) {
/* FIXME ? */
warning ("disconnection failed: %s", e.message);
}
signal_handle = null;
connection = null;
......@@ -171,11 +176,13 @@ namespace OVCCClient
private void listen_loop ()
{
var running = true;
while (running) {
while (running && ! listen_loop_cancel.is_cancelled ()) {
Message? msg;
try {
msg = Message.receive (input);
msg = Message.receive (input, listen_loop_cancel);
} catch (IOError.CANCELLED e) {
break;
} catch (Error e) {
warning ("error receiving data: %s", e.message);
break;
......@@ -199,6 +206,7 @@ namespace OVCCClient
public void start_communication (Game game, Player player)
{
listen_loop_cancel = new Cancellable ();
signal_handle = new SignalHandle (game, player, input, output);
Thread.create<void> (listen_loop, false);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment