Commit e6f27587 authored by Olivier Crête's avatar Olivier Crête
Browse files

pseudotcp: Add async accept to match async connect

parent 60eef190
......@@ -1412,15 +1412,12 @@ pseudo_tcp_socket_connect_async (PseudoTcpSocket *self,
task = g_task_new (self, cancellable, callback, user_data);
g_task_set_source_tag (task, pseudo_tcp_socket_connect_async);
if (self->priv->state == TCP_LISTEN)
pseudo_tcp_socket_connect (self);
if (self->priv->state != TCP_ESTABLISHED) {
self->priv->connect_task = task;
task = NULL;
}
else if (self->priv->state == TCP_LISTEN) {
pseudo_tcp_socket_connect_locked (self);
if (self->priv->state == TCP_LISTEN) {
pseudo_tcp_socket_connect_locked (self);
}
}
if (task == NULL && cancellable) {
......@@ -1447,6 +1444,57 @@ pseudo_tcp_socket_connect_finish (PseudoTcpSocket *self, GAsyncResult *res,
return g_task_propagate_boolean (G_TASK(res), error);
}
void
pseudo_tcp_socket_accept_async (PseudoTcpSocket *self,
GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data)
{
GTask *task = NULL;
g_rec_mutex_lock (&self->priv->mutex);
if (self->priv->connect_task) {
g_rec_mutex_unlock (&self->priv->mutex);
g_task_report_new_error (self, callback, user_data,
pseudo_tcp_socket_connect_async,
G_IO_ERROR, G_IO_ERROR_PENDING,
"Connect operation already pending");
return;
}
task = g_task_new (self, cancellable, callback, user_data);
g_task_set_source_tag (task, pseudo_tcp_socket_accept_async);
if (self->priv->state != TCP_ESTABLISHED) {
pseudo_tcp_socket_listen_locked (self);
self->priv->connect_task = task;
task = NULL;
}
if (task == NULL && cancellable) {
g_cancellable_connect (cancellable, G_CALLBACK (connect_cancelled),
g_object_ref (self), (GDestroyNotify) g_object_unref);
}
g_rec_mutex_unlock (&self->priv->mutex);
if (task) {
g_task_return_boolean (task, TRUE);
g_object_unref (task);
}
}
gboolean
pseudo_tcp_socket_accept_finish (PseudoTcpSocket *self, GAsyncResult *res,
GError **error)
{
g_return_val_if_fail (g_task_is_valid (res, self), FALSE);
g_return_val_if_fail (g_async_result_is_tagged (res,
pseudo_tcp_socket_accept_async), FALSE);
return g_task_propagate_boolean (G_TASK(res), error);
}
void
pseudo_tcp_socket_notify_mtu(PseudoTcpSocket *self, guint16 mtu)
{
......
......@@ -306,6 +306,22 @@ void pseudo_tcp_socket_connect_async (PseudoTcpSocket *self,
gboolean pseudo_tcp_socket_connect_finish (PseudoTcpSocket *self,
GAsyncResult *res, GError **error);
/**
* pseudo_tcp_socket_accept_async:
*
* TODO: Docs
*/
void pseudo_tcp_socket_accept_async (PseudoTcpSocket *self,
GCancellable *cancellable, GAsyncReadyCallback callback,
gpointer user_data);
/**
* pseudo_tcp_socket_accept_finish:
*
* TODO: Docs
*/
gboolean pseudo_tcp_socket_accept_finish (PseudoTcpSocket *self,
GAsyncResult *res, GError **error);
/**
* pseudo_tcp_socket_recv:
* @self: The #PseudoTcpSocket object.
......
......@@ -66,6 +66,8 @@ nice_interfaces_get_ip_for_interface
nice_interfaces_get_local_interfaces
nice_interfaces_get_local_ips
pseudo_tcp_set_debug_level
pseudo_tcp_socket_accept_async
pseudo_tcp_socket_accept_finish
pseudo_tcp_socket_close
pseudo_tcp_socket_close_async
pseudo_tcp_socket_close_finish
......
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