X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=blobdiff_plain;f=net.c;h=9698e427868e212646f682d9b8dc2d7e8f6235ae;hp=c28cf0964b0468bc9e616dc2c014536bc84e2ad0;hb=00e95557839f3fef5fa06702f3864e8376d2a29b;hpb=6b291ea777418071bb21c20aa7804447d95422bc;ds=sidebyside diff --git a/net.c b/net.c index c28cf096..9698e427 100644 --- a/net.c +++ b/net.c @@ -845,19 +845,19 @@ static int init_unix_addr(struct sockaddr_un *u, const char *name) } /** - * Prepare, create, and bind a socket for local communication. + * Create a socket for local communication and listen on it. * * \param name The socket pathname. * \param mode The desired permissions of the socket. * - * This function creates a local socket for sequenced, reliable, - * two-way, connection-based byte streams. + * This function creates a passive local socket for sequenced, reliable, + * two-way, connection-based byte streams. The socket file descriptor is set to + * nonblocking mode and listen(2) is called to prepare the socket for + * accepting incoming connection requests. * - * \return The file descriptor, on success, negative on errors. + * \return The file descriptor on success, negative error code on failure. * - * \sa socket(2) - * \sa bind(2) - * \sa chmod(2) + * \sa socket(2), \sa bind(2), \sa chmod(2), listen(2), unix(7). */ int create_local_socket(const char *name, mode_t mode) { @@ -871,6 +871,9 @@ int create_local_socket(const char *name, mode_t mode) if (ret < 0) return -ERRNO_TO_PARA_ERROR(errno); fd = ret; + ret = mark_fd_nonblocking(fd); + if (ret < 0) + goto err; ret = bind(fd, (struct sockaddr *)&unix_addr, UNIX_PATH_MAX); if (ret < 0) { ret = -ERRNO_TO_PARA_ERROR(errno); @@ -879,6 +882,10 @@ int create_local_socket(const char *name, mode_t mode) ret = -E_CHMOD; if (chmod(name, mode) < 0) goto err; + if (listen(fd , 5) < 0) { + ret = -ERRNO_TO_PARA_ERROR(errno); + goto err; + } return fd; err: close(fd);