Esempio n. 1
0
int
libcfs_socketpair(cfs_socket_t **sockp)
{
        int rc, i, fdp[2];

        LIBCFS_ALLOC(sockp[0], sizeof(cfs_socket_t));
        if (sockp[0] == NULL) {
                CERROR ("Can't alloc memory for cfs_socket_t (1)\n");
                return -ENOMEM;
        }

        LIBCFS_ALLOC(sockp[1], sizeof(cfs_socket_t));
        if (sockp[1] == NULL) {
                CERROR ("Can't alloc memory for cfs_socket_t (2)\n");
                LIBCFS_FREE(sockp[0], sizeof(cfs_socket_t));
                return -ENOMEM;
        }

        rc = socketpair(AF_UNIX, SOCK_STREAM, 0, fdp);
        if (rc != 0) {
                rc = -errno;
                CERROR ("Cannot create socket pair\n");
                LIBCFS_FREE(sockp[0], sizeof(cfs_socket_t));
                LIBCFS_FREE(sockp[1], sizeof(cfs_socket_t));
                return rc;
        }

        sockp[0]->s_fd = fdp[0];
        sockp[1]->s_fd = fdp[1];

        for (i = 0; i < 2; i++) {
                rc = libcfs_fcntl_nonblock(sockp[i]);
                if (rc) {
                        libcfs_sock_release(sockp[0]);
                        libcfs_sock_release(sockp[1]);
                        return rc;
                }
        }

        return 0;
}
Esempio n. 2
0
int
libcfs_socketpair(int *fdp)
{
	int rc, i;

	rc = socketpair(AF_UNIX, SOCK_STREAM, 0, fdp);
	if (rc != 0) {
		rc = -errno;
		CERROR ("Cannot create socket pair: %s\n", strerror(errno));
		return rc;
	}

	for (i = 0; i < 2; i++) {
		rc = libcfs_fcntl_nonblock(fdp[i]);
		if (rc) {
			close(fdp[0]);
			close(fdp[1]);
			return rc;
		}
	}

	return 0;
}