[sheepdog] [PATCH] sheep: add support for using unix domain socket

Liu Yuan namei.unix at gmail.com
Mon Nov 5 03:57:04 CET 2012


On 11/02/2012 09:19 PM, MORITA Kazutaka wrote:
> +	fd = socket(addr.sun_family, SOCK_STREAM, 0);
> +	if (fd < 0) {
> +		eprintf("failed to create socket, %m\n");
> +		return -1;
> +	}
> +
> +	ret = bind(fd, &addr, sizeof(addr));
> +	if (ret) {
> +		eprintf("failed to bind socket: %m\n");
> +		goto err;
> +	}
> +
> +	ret = listen(fd, SOMAXCONN);
> +	if (ret) {
> +		eprintf("failed to listen on socket: %m\n");
> +		goto err;
> +	}
> +
> +	ret = set_nonblocking(fd);
> +	if (ret < 0)
> +		goto err;
> +
> +	ret = callback(fd, data);
> +	if (ret)
> +		goto err;
> +
> +	return 0;
> +err:
> +	if (fd >= 0)

This if check is not necessary.

Thanks,
Yuan

> +		close(fd);





More information about the sheepdog mailing list