]> git.meshlink.io Git - meshlink/commitdiff
Take the global lock in meshlink_channel_send().
authorGuus Sliepen <guus@meshlink.io>
Sat, 1 Nov 2014 13:24:41 +0000 (14:24 +0100)
committerGuus Sliepen <guus@meshlink.io>
Sat, 1 Nov 2014 13:24:41 +0000 (14:24 +0100)
src/meshlink.c

index 8f0ae7d2fba0702c1701145b64910f81dddab06c..df257bf6e2a81ce535350491a4b5201a3dac11eb 100644 (file)
@@ -2076,11 +2076,18 @@ ssize_t meshlink_channel_send(meshlink_handle_t *mesh, meshlink_channel_t *chann
                return -1;
        }
 
                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.
        // 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) {
 }
 
 void update_node_status(meshlink_handle_t *mesh, node_t *n) {