Commit 6055c5c9 authored by Colomban Wendling's avatar Colomban Wendling
Browse files

Add asynchronous version of message sending and receiving

The implementation may not be perfect, bu seem to work OK.
parent 71bb1fa0
......@@ -81,6 +81,27 @@ namespace OVCC.Network
return message;
}
public static async Message receive_async (DataInputStream stream,
Cancellable? cancel = null)
throws Error
{
Message result = null;
Error? err = null;
Thread.create<void> (() => {
try {
result = Message.receive (stream, cancel);
} catch (Error e) {
err = e;
}
Idle.add (receive_async.callback);
}, false);
yield;
if (err != null) {
throw err;
}
return result;
}
public bool send (DataOutputStream stream,
Cancellable? cancel = null)
throws Error
......@@ -89,5 +110,26 @@ namespace OVCC.Network
this.serialize (stream, cancel);
return true;
}
public async bool send_async (DataOutputStream stream,
Cancellable? cancel = null)
throws Error
{
bool result = true;
Error? err = null;
Thread.create<void> (() => {
try {
result = this.send (stream, cancel);
} catch (Error e) {
err = e;
}
Idle.add (send_async.callback);
}, false);
yield;
if (err != null) {
throw err;
}
return result;
}
}
}
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