Message ID | 20141007100003.GD2404@work-vm |
---|---|
State | New |
Headers | show |
Il 07/10/2014 12:00, Dr. David Alan Gilbert ha scritto: > * Paolo Bonzini (pbonzini@redhat.com) 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 / dgilbert@redhat.com / Manchester, UK >
--- 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;