[Spice-devel] [spice-server v3 3/6] net: Introduce red_socket_set_non_blocking() helper

Jeremy White jwhite at codeweavers.com
Thu Mar 30 17:27:06 UTC 2017


Hi,

On 03/16/2017 10:02 AM, Christophe Fergeau wrote:
> This allows to move some low-level code out of reds.c
> 
> Signed-off-by: Christophe Fergeau <cfergeau at redhat.com>
> ---
>  server/net-utils.c | 24 ++++++++++++++++++++++++
>  server/net-utils.h |  1 +
>  server/reds.c      | 13 ++-----------
>  3 files changed, 27 insertions(+), 11 deletions(-)
> 
> diff --git a/server/net-utils.c b/server/net-utils.c
> index 10f447b..0e533f5 100644
> --- a/server/net-utils.c
> +++ b/server/net-utils.c
> @@ -52,3 +52,27 @@ bool red_socket_set_no_delay(int fd, bool no_delay)
>  
>      return true;
>  }
> +
> +/**
> + * red_socket_set_non_blocking:
> + * @fd: a socket file descriptor
> + * @non_blocking: whether to enable O_NONBLOCK on @fd
> + *
> + * Returns: #true if the operation succeeded, #false otherwise.
> + */
> +bool red_socket_set_non_blocking(int fd, bool non_blocking)
> +{
> +    int flags;
> +
> +    if ((flags = fcntl(fd, F_GETFL)) == -1) {
> +        spice_warning("fnctl(F_GETFL) failed, %s", strerror(errno));
> +        return false;
> +    }
> +
> +    if (fcntl(fd, F_SETFL, flags | O_NONBLOCK) == -1) {
> +        spice_warning("fnctl(F_SETFL) failed, %s", strerror(errno));
> +        return false;
> +    }
> +
> +    return true;
> +}

Doesn't this ignore the non_blocking parameter?

Cheers,

Jeremy


More information about the Spice-devel mailing list