qemu-devel
[Top][All Lists]
Advanced

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

Re: [Qemu-devel] [PATCH v4 08/47] socket shutdown


From: Paolo Bonzini
Subject: Re: [Qemu-devel] [PATCH v4 08/47] socket shutdown
Date: Tue, 07 Oct 2014 13:10:33 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.1.1

Il 07/10/2014 12:00, Dr. David Alan Gilbert ha scritto:
> * Paolo Bonzini (address@hidden) wrote:
>> Il 03/10/2014 19:47, Dr. David Alan Gilbert (git) ha scritto:
>>> +#ifndef WIN32
>>> +    if (rd) {
>>> +        how = SHUT_RD;
>>> +    }
>>> +
>>> +    if (wr) {
>>> +        how = rd ? SHUT_RDWR : SHUT_WR;
>>> +    }
>>> +
>>> +#else
>>> +    /* Untested */
>>> +    if (rd) {
>>> +        how = SD_RECEIVE;
>>> +    }
>>> +
>>> +    if (wr) {
>>> +        how = rd ? SD_BOTH : SD_SEND;
>>> +    }
>>> +
>>> +#endif
>>> +
>>
>>
>> These are the same on Windows and non-Windows actually.  Just #define
>> SHUT_* to 0/1/2 and avoid the wrapper.
> 
> OK, something like this? (the qemu-file.c abstraction is still needed
> to cover QEMUFile's that aren't simple sockets, but I've removed the 
> second layer in util/qemu-sockets.c).

Yes.  Or just pass SHUT_* directly to socket_shutdown, of course.

Paolo

> 
> --- a/include/qemu/sockets.h
> +++ b/include/qemu/sockets.h
> @@ -44,6 +44,13 @@ int socket_set_fast_reuse(int fd);
>  int send_all(int fd, const void *buf, int len1);
>  int recv_all(int fd, void *buf, int len1, bool single_read);
>  
> +#ifdef WIN32
> +/* Windows has different names for the same constants with the same values */
> +#define SHUT_RD   0
> +#define SHUT_WR   1
> +#define SHUT_RDWR 2
> +#endif
> +
>  /* callback function for nonblocking connect
>   * valid fd on success, negative error code on failure
>   */
> 
> --- a/qemu-file.c
> +++ b/qemu-file.c
> @@ -90,6 +90,13 @@ static int socket_close(void *opaque)
>      return 0;
>  }
>  
> +static int socket_shutdown(void *opaque, bool rd, bool wr)
> +{
> +    QEMUFileSocket *s = opaque;
> +
> +    return shutdown(s->fd, rd ? (wr ? SHUT_RDWR : SHUT_RD) : SHUT_WR);
> +}
> +
>  static int stdio_get_fd(void *opaque)
>  {
>      QEMUFileStdio *s = opaque;
> --
> Dr. David Alan Gilbert / address@hidden / Manchester, UK
> 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]