p2p: Do not return an error when a service name is already bound
authorSamuel Ortiz <sameo@linux.intel.com>
Fri, 22 Jun 2012 13:34:20 +0000 (15:34 +0200)
committerSamuel Ortiz <sameo@linux.intel.com>
Fri, 22 Jun 2012 13:40:55 +0000 (15:40 +0200)
When trying to re-use the same service name, bind will fail but it means
a server is already listening on this service.

plugins/p2p.c

index 31bd2bc..52004c3 100644 (file)
@@ -225,7 +225,12 @@ static int p2p_bind(struct near_p2p_driver *driver, uint32_t adapter_idx,
        err = bind(fd, (struct sockaddr *)&addr,
                        sizeof(struct sockaddr_nfc_llcp));
        if (err < 0) {
-               near_error("%s bind failed %d", driver->name, err);
+               if (errno == EADDRINUSE) {
+                       DBG("%s is already bound", driver->name);
+                       return 0;
+               }
+
+               near_error("%s bind failed %d %d", driver->name, err, errno);
 
                close(fd);
                return err;