#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>
#ifdef _WIN32
-#define socket_error() WSAGetLastError()
-#undef EINTR
-#define EWOULDBLOCK WSAEWOULDBLOCK
-#define EINTR WSAEINTR
-#define EINPROGRESS WSAEINPROGRESS
-
static void socket_cleanup(void)
{
WSACleanup();
#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;
#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)
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);
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)
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;
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;
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);
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);