Re: [spice-server v2 4/6] reds-stream: Introduce reds_stream_get_no_delay() helper

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



> 
> This new function removes one place outside of RedsStream which needs to
> access RedsStream::socket
> 
> Signed-off-by: Christophe Fergeau <cfergeau@xxxxxxxxxx>
> ---
>  server/net-utils.c          | 14 ++++++++++++++
>  server/net-utils.h          |  1 +
>  server/red-channel-client.c |  7 ++-----
>  server/reds-stream.c        |  5 +++++
>  server/reds-stream.h        |  1 +
>  5 files changed, 23 insertions(+), 5 deletions(-)
> 
> diff --git a/server/net-utils.c b/server/net-utils.c
> index 995b0d4..c7a179e 100644
> --- a/server/net-utils.c
> +++ b/server/net-utils.c
> @@ -87,3 +87,17 @@ bool red_socket_set_non_blocking(int fd, bool
> non_blocking)
>  
>      return true;
>  }
> +
> +int red_socket_get_no_delay(int fd)
> +{
> +    int delay_val;
> +    socklen_t opt_size = sizeof(delay_val);
> +
> +    if (getsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &delay_val,
> +                   &opt_size) == -1) {
> +            spice_warning("getsockopt failed, %s", strerror(errno));
> +            return -1;
> +    }
> +
> +    return delay_val;
> +}
> diff --git a/server/net-utils.h b/server/net-utils.h
> index d06932d..a256d27 100644
> --- a/server/net-utils.h
> +++ b/server/net-utils.h
> @@ -20,6 +20,7 @@
>  
>  bool red_socket_set_keepalive(int fd, bool enable, int timeout);
>  bool red_socket_set_no_delay(int fd, bool no_delay);
> +int red_socket_get_no_delay(int fd);
>  bool red_socket_set_non_blocking(int fd, bool non_blocking);
>  
>  #endif
> diff --git a/server/red-channel-client.c b/server/red-channel-client.c
> index 9fca8c1..ffebc6a 100644
> --- a/server/red-channel-client.c
> +++ b/server/red-channel-client.c
> @@ -556,7 +556,6 @@ static void red_channel_client_send_ping(RedChannelClient
> *rcc)
>  
>      if (!rcc->priv->latency_monitor.warmup_was_sent) { // latency test start
>          int delay_val;
> -        socklen_t opt_size = sizeof(delay_val);
>  
>          rcc->priv->latency_monitor.warmup_was_sent = TRUE;
>          /*
> @@ -565,10 +564,8 @@ static void
> red_channel_client_send_ping(RedChannelClient *rcc)
>           * roundtrip measurement is less accurate (bigger).
>           */
>          rcc->priv->latency_monitor.tcp_nodelay = 1;
> -        if (getsockopt(rcc->priv->stream->socket, IPPROTO_TCP, TCP_NODELAY,
> &delay_val,
> -                       &opt_size) == -1) {
> -            spice_warning("getsockopt failed, %s", strerror(errno));
> -        }  else {
> +        delay_val = reds_stream_get_no_delay(rcc->priv->stream);
> +        if (delay_val != -1) {
>              rcc->priv->latency_monitor.tcp_nodelay = delay_val;
>              if (!delay_val) {
>                  reds_stream_set_no_delay(rcc->priv->stream, TRUE);
> diff --git a/server/reds-stream.c b/server/reds-stream.c
> index f9cdcf0..1d815c1 100644
> --- a/server/reds-stream.c
> +++ b/server/reds-stream.c
> @@ -266,6 +266,11 @@ bool reds_stream_set_no_delay(RedsStream *stream, bool
> no_delay)
>      return red_socket_set_no_delay(stream->socket, no_delay);
>  }
>  
> +int reds_stream_get_no_delay(RedsStream *stream)
> +{
> +    return red_socket_get_no_delay(stream->socket);
> +}
> +
>  int reds_stream_send_msgfd(RedsStream *stream, int fd)
>  {
>      struct msghdr msgh = { 0, };
> diff --git a/server/reds-stream.h b/server/reds-stream.h
> index 37ba87c..b4fc8b2 100644
> --- a/server/reds-stream.h
> +++ b/server/reds-stream.h
> @@ -73,6 +73,7 @@ int reds_stream_enable_ssl(RedsStream *stream, SSL_CTX
> *ctx);
>  int reds_stream_get_family(const RedsStream *stream);
>  bool reds_stream_is_plain_unix(const RedsStream *stream);
>  bool reds_stream_set_no_delay(RedsStream *stream, bool no_delay);
> +int reds_stream_get_no_delay(RedsStream *stream);
>  int reds_stream_send_msgfd(RedsStream *stream, int fd);
>  
>  typedef enum {

Maybe I'm cheating but I would return just a bool and if is not
a socket I would return true.

Frediano
_______________________________________________
Spice-devel mailing list
Spice-devel@xxxxxxxxxxxxxxxxxxxxx
https://lists.freedesktop.org/mailman/listinfo/spice-devel




[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]     [Monitors]