From: Guus Sliepen Date: Sat, 1 Nov 2014 13:24:41 +0000 (+0100) Subject: Take the global lock in meshlink_channel_send(). X-Git-Url: http://git.meshlink.io/?a=commitdiff_plain;ds=sidebyside;h=529b4d002a9b8cfb9be829b1d1422b4a2e1205d2;p=meshlink Take the global lock in meshlink_channel_send(). --- 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) {