diff options
author | bellard <bellard@c046a42c-6fe2-441c-8c8c-71466251a162> | 2006-04-30 22:53:25 +0000 |
---|---|---|
committer | bellard <bellard@c046a42c-6fe2-441c-8c8c-71466251a162> | 2006-04-30 22:53:25 +0000 |
commit | 6ca957f08f272321e32ccef2f4053e93dc10f4ad (patch) | |
tree | 8c061b32dda461926dab9d5ac366668461755228 | |
parent | f3548328783d49bb3f22c16b644b1156361e6678 (diff) | |
download | qemu-6ca957f08f272321e32ccef2f4053e93dc10f4ad.zip qemu-6ca957f08f272321e32ccef2f4053e93dc10f4ad.tar.gz qemu-6ca957f08f272321e32ccef2f4053e93dc10f4ad.tar.bz2 |
win32 socket fixes
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@1876 c046a42c-6fe2-441c-8c8c-71466251a162
-rw-r--r-- | qemu_socket.h | 30 | ||||
-rw-r--r-- | vl.c | 13 | ||||
-rw-r--r-- | vnc.c | 27 |
3 files changed, 43 insertions, 27 deletions
diff --git a/qemu_socket.h b/qemu_socket.h new file mode 100644 index 0000000..64b7d4e --- /dev/null +++ b/qemu_socket.h @@ -0,0 +1,30 @@ +/* headers to use the BSD sockets */ +#ifndef QEMU_SOCKET_H +#define QEMU_SOCKET_H + +#ifdef _WIN32 + +#include <windows.h> +#include <winsock2.h> +#include <ws2tcpip.h> + +#define socket_error() WSAGetLastError() +#undef EINTR +#define EWOULDBLOCK WSAEWOULDBLOCK +#define EINTR WSAEINTR +#define EINPROGRESS WSAEINPROGRESS + +#else + +#include <sys/socket.h> +#include <netinet/in.h> +#include <netinet/tcp.h> + +#define socket_error() errno +#define closesocket(s) close(s) + +#endif /* !_WIN32 */ + +void socket_set_nonblock(int fd); + +#endif /* QEMU_SOCKET_H */ @@ -66,12 +66,12 @@ #include <malloc.h> #include <sys/timeb.h> #include <windows.h> -#include <winsock2.h> -#include <ws2tcpip.h> #define getopt_long_only getopt_long #define memalign(align, size) malloc(size) #endif +#include "qemu_socket.h" + #ifdef CONFIG_SDL #ifdef __APPLE__ #include <SDL/SDL.h> @@ -1085,12 +1085,6 @@ CharDriverState *qemu_chr_open_null(void) #ifdef _WIN32 -#define socket_error() WSAGetLastError() -#undef EINTR -#define EWOULDBLOCK WSAEWOULDBLOCK -#define EINTR WSAEINTR -#define EINPROGRESS WSAEINPROGRESS - static void socket_cleanup(void) { WSACleanup(); @@ -1142,9 +1136,6 @@ void socket_set_nonblock(int fd) #else -#define socket_error() errno -#define closesocket(s) close(s) - static int unix_write(int fd, const uint8_t *buf, int len1) { int ret, len; @@ -1,9 +1,5 @@ #include "vl.h" - -#include <sys/socket.h> -#include <netinet/in.h> -#include <netinet/tcp.h> -#include <fcntl.h> +#include "qemu_socket.h" #define VNC_REFRESH_INTERVAL (1000 / 30) @@ -386,14 +382,14 @@ static void buffer_append(Buffer *buffer, const void *data, size_t len) buffer->offset += len; } -static int vnc_client_io_error(VncState *vs, int ret) +static int vnc_client_io_error(VncState *vs, int ret, int last_errno) { if (ret == 0 || ret == -1) { - if (ret == -1 && (errno == EINTR || errno == EAGAIN)) + if (ret == -1 && (last_errno == EINTR || last_errno == EAGAIN)) return 0; qemu_set_fd_handler2(vs->csock, NULL, NULL, NULL, NULL); - close(vs->csock); + closesocket(vs->csock); vs->csock = -1; buffer_reset(&vs->input); buffer_reset(&vs->output); @@ -405,8 +401,7 @@ static int vnc_client_io_error(VncState *vs, int ret) static void vnc_client_error(VncState *vs) { - errno = EINVAL; - vnc_client_io_error(vs, -1); + vnc_client_io_error(vs, -1, EINVAL); } static void vnc_client_write(void *opaque) @@ -414,8 +409,8 @@ static void vnc_client_write(void *opaque) ssize_t ret; VncState *vs = opaque; - ret = write(vs->csock, vs->output.buffer, vs->output.offset); - ret = vnc_client_io_error(vs, ret); + ret = send(vs->csock, vs->output.buffer, vs->output.offset, 0); + ret = vnc_client_io_error(vs, ret, socket_error()); if (!ret) return; @@ -440,8 +435,8 @@ static void vnc_client_read(void *opaque) buffer_reserve(&vs->input, 4096); - ret = read(vs->csock, buffer_end(&vs->input), 4096); - ret = vnc_client_io_error(vs, ret); + ret = recv(vs->csock, buffer_end(&vs->input), 4096, 0); + ret = vnc_client_io_error(vs, ret, socket_error()); if (!ret) return; @@ -812,7 +807,7 @@ static void vnc_listen_read(void *opaque) vs->csock = accept(vs->lsock, (struct sockaddr *)&addr, &addrlen); if (vs->csock != -1) { - fcntl(vs->csock, F_SETFL, O_NONBLOCK); + socket_set_nonblock(vs->csock); qemu_set_fd_handler2(vs->csock, NULL, vnc_client_read, NULL, opaque); vnc_write(vs, "RFB 003.003\n", 12); vnc_flush(vs); @@ -862,7 +857,7 @@ void vnc_display_init(DisplayState *ds, int display) reuse_addr = 1; ret = setsockopt(vs->lsock, SOL_SOCKET, SO_REUSEADDR, - &reuse_addr, sizeof(reuse_addr)); + (const char *)&reuse_addr, sizeof(reuse_addr)); if (ret == -1) { fprintf(stderr, "setsockopt() failed\n"); exit(1); |