From: Saverio Proto Date: Sat, 28 Jun 2014 13:13:19 +0000 (+0200) Subject: Find first available descriptor in bit array X-Git-Url: https://git.meshlink.io/?a=commitdiff_plain;h=0360a8180701f7b3e0288d4412e04c7a9bdb80a1;p=meshlink Find first available descriptor in bit array --- diff --git a/src/meshlink.c b/src/meshlink.c index 7d717e5a..538a9e5c 100644 --- a/src/meshlink.c +++ b/src/meshlink.c @@ -1374,6 +1374,18 @@ meshlink_connection_t* meshlink_open_rchannel(meshlink_handle_t *mesh, meshlink_ //TODO: check in mesh->socketsbitmap for a free descriptor and allocate a source port for this connection + int descriptor=-1; + + for (int i=0; i < 1024 ;i++) { + if (mesh->socketsbitmap.bitValues[i].bit == 0) { + mesh->socketsbitmap.bitValues[i].bit=1; + descriptor=i; + break; + } + } + + if (descriptor == -1 ) return NULL; + //TODO: register a callback for the data that will be received from this connection //TODO: return a description value that the user will use to write on this channel