From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1KFBEN-0001Dy-C7 for qemu-devel@nongnu.org; Sat, 05 Jul 2008 13:07:27 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1KFBEM-0001C8-Al for qemu-devel@nongnu.org; Sat, 05 Jul 2008 13:07:26 -0400 Received: from [199.232.76.173] (port=58860 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KFBEL-0001BC-Hy for qemu-devel@nongnu.org; Sat, 05 Jul 2008 13:07:25 -0400 Received: from mx20.gnu.org ([199.232.41.8]:22375) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1KFAmC-0001yp-Md for qemu-devel@nongnu.org; Sat, 05 Jul 2008 12:38:21 -0400 Received: from wr-out-0506.google.com ([64.233.184.235]) by mx20.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1KF6P5-0001ER-63 for qemu-devel@nongnu.org; Sat, 05 Jul 2008 07:58:11 -0400 Received: by wr-out-0506.google.com with SMTP id c46so1227913wra.18 for ; Sat, 05 Jul 2008 04:58:09 -0700 (PDT) Message-ID: <5b31733c0807050458w41aebd89re70cc859602c3681@mail.gmail.com> Date: Sat, 5 Jul 2008 13:58:08 +0200 From: "Filip Navara" Sender: filip.navara@gmail.com Subject: Re: [Qemu-devel] [PATCH] Fix compilation of nbd on Windows In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <20080704092849.5BC0.20F538E7@nsfocus.com> <20080704023451.GO7007@networkno.de> <20080704115101.5BC9.20F538E7@nsfocus.com> <1215160927.3802.4.camel@frecb07144> <20080704203231.GB31670@networkno.de> Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Laurent Vivier , chenqing Closing sockets with "close" doesn't work on WinSock. Add "#define close closesocket" to the top of file to fix it. Otherwise, good job! Best regards, Filip Navara On Sat, Jul 5, 2008 at 12:02 AM, Johannes Schindelin wrote: > > This still only supports the client side, and only the TCP version of > it, since Windows does not have Unix sockets. > > Signed-off-by: Johannes Schindelin > --- > > This is only compile-tested, since I can only work in an emulated > environment. > > Oh, and feel free to reorder nbd.h so that it has only one > #ifndef..#endif. > > If I find some time next week, I might try to actually compile > qemu-nbd and get it to run on Windows. > > Makefile | 1 + > block-nbd.c | 11 ++++++++++- > nbd.c | 36 +++++++++++++++++++++++++++++++++++- > nbd.h | 6 ++++++ > 4 files changed, 52 insertions(+), 2 deletions(-) > > diff --git a/Makefile b/Makefile > index adb36c6..ef55952 100644 > --- a/Makefile > +++ b/Makefile > @@ -70,6 +70,7 @@ endif > > ifdef CONFIG_WIN32 > OBJS+=tap-win32.o > +LIBS+= -lws2_32 > endif > > AUDIO_OBJS = audio.o noaudio.o wavaudio.o mixeng.o > diff --git a/block-nbd.c b/block-nbd.c > index f350050..a2adbde 100644 > --- a/block-nbd.c > +++ b/block-nbd.c > @@ -31,11 +31,17 @@ > > #include > #include > +#ifdef _WIN32 > +#include > +#include > +#include > +#else > #include > #include > #include > #include > #include > +#endif > > typedef struct BDRVNBDState { > int sock; > @@ -61,11 +67,14 @@ static int nbd_open(BlockDriverState *bs, const char* filename, int flags) > > if (strstart(host, "unix:", &unixpath)) { > > +#ifdef _WIN32 > + return -EINVAL; > +#else > if (unixpath[0] != '/') > return -EINVAL; > > sock = unix_socket_outgoing(unixpath); > - > +#endif > } else { > uint16_t port; > char *p, *r; > diff --git a/nbd.c b/nbd.c > index e9308ee..d783cd0 100644 > --- a/nbd.c > +++ b/nbd.c > @@ -21,15 +21,45 @@ > > #include > #include > -#include > #include > #include > +#ifdef _WIN32 > +#include > +#include > +#include > + > +#define socket_error() WSAGetLastError() > +#undef EAGAIN > +#undef EINTR > +#undef EINVAL > +#define EAGAIN WSAEWOULDBLOCK > +#define EINTR WSAEINTR > +#define EINVAL WSAEINVAL > + > +static inline int inet_aton(const char *cp, struct in_addr *inp) > +{ > + unsigned long result = inet_addr(cp); > + if (result == INADDR_NONE) > + return 0; > + inp->s_addr = result; > + return 1; > +} > + > +static inline int mingw_setsockopt(int s, int level, int optname, > + const void *optval, socklen_t optlen) > +{ > + return setsockopt(s, level, optname, (const char *)optval, optlen); > +} > +#define setsockopt mingw_setsockopt > +#else > +#include > #include > #include > #include > #include > #include > #include > +#endif > > #if defined(QEMU_NBD) > extern int verbose; > @@ -188,6 +218,7 @@ error: > return -1; > } > > +#ifndef _WIN32 > int unix_socket_incoming(const char *path) > { > int s; > @@ -245,6 +276,7 @@ error: > errno = serrno; > return -1; > } > +#endif > > > /* Basic flow > @@ -334,6 +366,7 @@ int nbd_receive_negotiate(int csock, off_t *size, size_t *blocksize) > return 0; > } > > +#ifndef _WIN32 > int nbd_init(int fd, int csock, off_t size, size_t blocksize) > { > TRACE("Setting block size to %lu", (unsigned long)blocksize); > @@ -407,6 +440,7 @@ int nbd_client(int fd, int csock) > errno = serrno; > return ret; > } > +#endif > > int nbd_send_request(int csock, struct nbd_request *request) > { > diff --git a/nbd.h b/nbd.h > index 55ba1ba..387246d 100644 > --- a/nbd.h > +++ b/nbd.h > @@ -47,17 +47,23 @@ enum { > size_t nbd_wr_sync(int fd, void *buffer, size_t size, bool do_read); > int tcp_socket_outgoing(const char *address, uint16_t port); > int tcp_socket_incoming(const char *address, uint16_t port); > +#ifndef _WIN32 > int unix_socket_outgoing(const char *path); > int unix_socket_incoming(const char *path); > +#endif > > int nbd_negotiate(BlockDriverState *bs, int csock, off_t size); > int nbd_receive_negotiate(int csock, off_t *size, size_t *blocksize); > +#ifndef _WIN32 > int nbd_init(int fd, int csock, off_t size, size_t blocksize); > +#endif > int nbd_send_request(int csock, struct nbd_request *request); > int nbd_receive_reply(int csock, struct nbd_reply *reply); > int nbd_trip(BlockDriverState *bs, int csock, off_t size, uint64_t dev_offset, > off_t *offset, bool readonly, uint8_t *data, int data_size); > +#ifndef _WIN32 > int nbd_client(int fd, int csock); > int nbd_disconnect(int fd); > +#endif > > #endif > -- > 1.5.6.1.376.g6b0fd > > > > >