From 529b4d002a9b8cfb9be829b1d1422b4a2e1205d2 Mon Sep 17 00:00:00 2001 From: Guus Sliepen Date: Sat, 1 Nov 2014 14:24:41 +0100 Subject: [PATCH] Take the global lock in meshlink_channel_send(). --- src/meshlink.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/meshlink.c b/src/meshlink.c index 8f0ae7d2..df257bf6 100644 --- a/src/meshlink.c +++ b/src/meshlink.c @@ -2076,11 +2076,18 @@ ssize_t meshlink_channel_send(meshlink_handle_t *mesh, meshlink_channel_t *chann return -1; } - // TODO: locking. + // TODO: more finegrained locking. // Ideally we want to put the data into the UTCP connection's send buffer. // Then, preferrably only if there is room in the receiver window, // kick the meshlink thread to go send packets. - return utcp_send(channel->c, data, len); + + pthread_mutex_lock(&mesh->mesh_mutex); + ssize_t retval = utcp_send(channel->c, data, len); + pthread_mutex_unlock(&mesh->mesh_mutex); + + if(retval < 0) + meshlink_errno = MESHLINK_ENETWORK; + return retval; } void update_node_status(meshlink_handle_t *mesh, node_t *n) { -- 2.39.5