static int nn_inproc_bind (const char *addr, void *hint, struct nn_epbase **epbase) { struct nn_list_item *it; struct nn_binproc *binproc; struct nn_cinproc *cinproc; nn_mutex_lock (&self.sync); /* Check whether the endpoint isn't already bound. */ /* TODO: This is an O(n) algorithm! */ for (it = nn_list_begin (&self.bound); it != nn_list_end (&self.bound); it = nn_list_next (&self.bound, it)) { binproc = nn_cont (it, struct nn_binproc, item); if (strncmp (addr, nn_binproc_getaddr (binproc), NN_SOCKADDR_MAX) == 0) { nn_mutex_unlock (&self.sync); return -EADDRINUSE; } } /* Insert the entry into the endpoint repository. */ binproc = nn_binproc_create (hint); nn_list_insert (&self.bound, &binproc->item, nn_list_end (&self.bound)); /* During this process new pipes may be created. */ for (it = nn_list_begin (&self.connected); it != nn_list_end (&self.connected); it = nn_list_next (&self.connected, it)) { cinproc = nn_cont (it, struct nn_cinproc, item); if (strncmp (addr, nn_cinproc_getaddr (cinproc), NN_SOCKADDR_MAX) == 0) { /* Check whether the two sockets are compatible. */ if (!nn_epbase_ispeer (&binproc->epbase, cinproc->protocol)) continue; nn_assert (cinproc->connects == 0); cinproc->connects = 1; nn_binproc_connect (binproc, cinproc); } } nn_assert (epbase); *epbase = &binproc->epbase; nn_mutex_unlock (&self.sync); return 0; }
static int nn_inproc_bind (void *hint, struct nn_epbase **epbase) { return nn_binproc_create (hint, epbase); }