Win32 code for xcb-1.5
This commit is contained in:
parent
53a9834e4c
commit
bce72f63d2
|
@ -35,7 +35,11 @@
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef _WIN32
|
||||||
#include <sys/uio.h>
|
#include <sys/uio.h>
|
||||||
|
#else
|
||||||
|
#include "windefs.h"
|
||||||
|
#endif
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -27,13 +27,18 @@
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <X11/Xauth.h>
|
#include <X11/Xauth.h>
|
||||||
#include <sys/socket.h>
|
|
||||||
#include <netinet/in.h>
|
|
||||||
#include <sys/un.h>
|
|
||||||
#include <sys/param.h>
|
#include <sys/param.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
#include "windefs.h"
|
||||||
|
#else
|
||||||
|
#include <sys/socket.h>
|
||||||
|
#include <netinet/in.h>
|
||||||
|
#include <sys/un.h>
|
||||||
|
#endif /* _WIN32 */
|
||||||
|
|
||||||
#include "xcb.h"
|
#include "xcb.h"
|
||||||
#include "xcbint.h"
|
#include "xcbint.h"
|
||||||
|
|
||||||
|
|
|
@ -30,7 +30,6 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <netinet/in.h>
|
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
||||||
|
@ -38,10 +37,16 @@
|
||||||
#include "xcbint.h"
|
#include "xcbint.h"
|
||||||
#if USE_POLL
|
#if USE_POLL
|
||||||
#include <poll.h>
|
#include <poll.h>
|
||||||
#else
|
#elif !defined WIN32
|
||||||
#include <sys/select.h>
|
#include <sys/select.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
#include "windefs.h"
|
||||||
|
#else
|
||||||
|
#include <netinet/in.h>
|
||||||
|
#endif /* _WIN32 */
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint8_t status;
|
uint8_t status;
|
||||||
uint8_t pad0[5];
|
uint8_t pad0[5];
|
||||||
|
@ -52,6 +57,17 @@ static const int error_connection = 1;
|
||||||
|
|
||||||
static int set_fd_flags(const int fd)
|
static int set_fd_flags(const int fd)
|
||||||
{
|
{
|
||||||
|
/* Win32 doesn't have file descriptors and the fcntl function. This block sets the socket in non-blocking mode */
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
u_long iMode = 1; /* non-zero puts it in non-blocking mode, 0 in blocking mode */
|
||||||
|
int ret = 0;
|
||||||
|
|
||||||
|
ret = ioctlsocket(fd, FIONBIO, &iMode);
|
||||||
|
if(ret != 0)
|
||||||
|
return 0;
|
||||||
|
return 1;
|
||||||
|
#else
|
||||||
int flags = fcntl(fd, F_GETFL, 0);
|
int flags = fcntl(fd, F_GETFL, 0);
|
||||||
if(flags == -1)
|
if(flags == -1)
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -61,6 +77,7 @@ static int set_fd_flags(const int fd)
|
||||||
if(fcntl(fd, F_SETFD, FD_CLOEXEC) == -1)
|
if(fcntl(fd, F_SETFD, FD_CLOEXEC) == -1)
|
||||||
return 0;
|
return 0;
|
||||||
return 1;
|
return 1;
|
||||||
|
#endif /* WIN32 */
|
||||||
}
|
}
|
||||||
|
|
||||||
static int write_setup(xcb_connection_t *c, xcb_auth_info_t *auth_info)
|
static int write_setup(xcb_connection_t *c, xcb_auth_info_t *auth_info)
|
||||||
|
@ -156,9 +173,37 @@ static int write_vec(xcb_connection_t *c, struct iovec **vector, int *count)
|
||||||
{
|
{
|
||||||
int n;
|
int n;
|
||||||
assert(!c->out.queue_len);
|
assert(!c->out.queue_len);
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
int i = 0;
|
||||||
|
int ret = 0,err = 0;
|
||||||
|
struct iovec *vec;
|
||||||
|
n = 0;
|
||||||
|
|
||||||
|
/* Could use the WSASend win32 function for scatter/gather i/o but setting up the WSABUF struct from
|
||||||
|
an iovec would require more work and I'm not sure of the benefit....works for now */
|
||||||
|
vec = *vector;
|
||||||
|
while(i < *count)
|
||||||
|
{
|
||||||
|
ret = send(c->fd,vec->iov_base,vec->iov_len,0);
|
||||||
|
if(ret == SOCKET_ERROR)
|
||||||
|
{
|
||||||
|
err = WSAGetLastError();
|
||||||
|
if(err == WSAEWOULDBLOCK)
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
n += ret;
|
||||||
|
*vec++;
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
#else
|
||||||
n = writev(c->fd, *vector, *count);
|
n = writev(c->fd, *vector, *count);
|
||||||
if(n < 0 && errno == EAGAIN)
|
if(n < 0 && errno == EAGAIN)
|
||||||
return 1;
|
return 1;
|
||||||
|
#endif /* _WIN32 */
|
||||||
|
|
||||||
if(n <= 0)
|
if(n <= 0)
|
||||||
{
|
{
|
||||||
_xcb_conn_shutdown(c);
|
_xcb_conn_shutdown(c);
|
||||||
|
|
33
src/xcb_in.c
33
src/xcb_in.c
|
@ -37,10 +37,14 @@
|
||||||
#include "xcbint.h"
|
#include "xcbint.h"
|
||||||
#if USE_POLL
|
#if USE_POLL
|
||||||
#include <poll.h>
|
#include <poll.h>
|
||||||
#else
|
#elif !defined WIN32
|
||||||
#include <sys/select.h>
|
#include <sys/select.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
#include "windefs.h"
|
||||||
|
#endif /* _WIN32 */
|
||||||
|
|
||||||
#define XCB_ERROR 0
|
#define XCB_ERROR 0
|
||||||
#define XCB_REPLY 1
|
#define XCB_REPLY 1
|
||||||
#define XCB_XGE_EVENT 35
|
#define XCB_XGE_EVENT 35
|
||||||
|
@ -267,12 +271,22 @@ static int read_block(const int fd, void *buf, const ssize_t len)
|
||||||
int done = 0;
|
int done = 0;
|
||||||
while(done < len)
|
while(done < len)
|
||||||
{
|
{
|
||||||
|
#ifndef _WIN32
|
||||||
int ret = read(fd, ((char *) buf) + done, len - done);
|
int ret = read(fd, ((char *) buf) + done, len - done);
|
||||||
|
#else
|
||||||
|
int ret = recv(fd, ((char *) buf) + done, len - done,0);
|
||||||
|
#endif /* !_WIN32 */
|
||||||
|
|
||||||
if(ret > 0)
|
if(ret > 0)
|
||||||
done += ret;
|
done += ret;
|
||||||
|
#ifndef _WIN32
|
||||||
if(ret < 0 && errno == EAGAIN)
|
if(ret < 0 && errno == EAGAIN)
|
||||||
|
#else
|
||||||
|
if(ret == SOCKET_ERROR && WSAGetLastError() == WSAEWOULDBLOCK)
|
||||||
|
#endif /* !_Win32 */
|
||||||
{
|
{
|
||||||
#if USE_POLL
|
#if USE_POLL
|
||||||
|
#ifndef _WIN32
|
||||||
struct pollfd pfd;
|
struct pollfd pfd;
|
||||||
pfd.fd = fd;
|
pfd.fd = fd;
|
||||||
pfd.events = POLLIN;
|
pfd.events = POLLIN;
|
||||||
|
@ -280,14 +294,21 @@ static int read_block(const int fd, void *buf, const ssize_t len)
|
||||||
do {
|
do {
|
||||||
ret = poll(&pfd, 1, -1);
|
ret = poll(&pfd, 1, -1);
|
||||||
} while (ret == -1 && errno == EINTR);
|
} while (ret == -1 && errno == EINTR);
|
||||||
|
#endif /* !_WIN32 */
|
||||||
#else
|
#else
|
||||||
fd_set fds;
|
fd_set fds;
|
||||||
FD_ZERO(&fds);
|
FD_ZERO(&fds);
|
||||||
FD_SET(fd, &fds);
|
FD_SET(fd, &fds);
|
||||||
|
#ifndef _WIN32
|
||||||
do {
|
do {
|
||||||
ret = select(fd + 1, &fds, 0, 0, 0);
|
ret = select(fd + 1, &fds, 0, 0, 0);
|
||||||
} while (ret == -1 && errno == EINTR);
|
} while (ret == -1 && errno == EINTR);
|
||||||
#endif
|
#else
|
||||||
|
/* the do while loop used for the non-windows version isn't required*/
|
||||||
|
/* for windows since there are no signals in Windows hence no EINTR*/
|
||||||
|
ret = select(fd + 1, &fds, 0, 0, 0);
|
||||||
|
#endif /* !_WIN32 */
|
||||||
|
#endif /* USE_POLL */
|
||||||
}
|
}
|
||||||
if(ret <= 0)
|
if(ret <= 0)
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -665,12 +686,20 @@ void _xcb_in_replies_done(xcb_connection_t *c)
|
||||||
|
|
||||||
int _xcb_in_read(xcb_connection_t *c)
|
int _xcb_in_read(xcb_connection_t *c)
|
||||||
{
|
{
|
||||||
|
#ifndef _WIN32
|
||||||
int n = read(c->fd, c->in.queue + c->in.queue_len, sizeof(c->in.queue) - c->in.queue_len);
|
int n = read(c->fd, c->in.queue + c->in.queue_len, sizeof(c->in.queue) - c->in.queue_len);
|
||||||
|
#else
|
||||||
|
int n = recv(c->fd, c->in.queue + c->in.queue_len, sizeof(c->in.queue) - c->in.queue_len,0);
|
||||||
|
#endif /* !_WIN32 */
|
||||||
if(n > 0)
|
if(n > 0)
|
||||||
c->in.queue_len += n;
|
c->in.queue_len += n;
|
||||||
while(read_packet(c))
|
while(read_packet(c))
|
||||||
/* empty */;
|
/* empty */;
|
||||||
|
#ifndef _WIN32
|
||||||
if((n > 0) || (n < 0 && errno == EAGAIN))
|
if((n > 0) || (n < 0 && errno == EAGAIN))
|
||||||
|
#else
|
||||||
|
if((n > 0) || (n < 0 && WSAGetLastError() == WSAEWOULDBLOCK))
|
||||||
|
#endif /* !_WIN32 */
|
||||||
return 1;
|
return 1;
|
||||||
_xcb_conn_shutdown(c);
|
_xcb_conn_shutdown(c);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -27,23 +27,26 @@
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/socket.h>
|
|
||||||
#include <sys/un.h>
|
|
||||||
#include <netinet/in.h>
|
|
||||||
#include <netinet/tcp.h>
|
|
||||||
#ifdef DNETCONN
|
#ifdef DNETCONN
|
||||||
#include <netdnet/dnetdb.h>
|
#include <netdnet/dnetdb.h>
|
||||||
#include <netdnet/dn.h>
|
#include <netdnet/dn.h>
|
||||||
#endif
|
#endif
|
||||||
#include <netdb.h>
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <fcntl.h>
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
#include "windefs.h"
|
||||||
|
#else
|
||||||
|
#include <sys/socket.h>
|
||||||
|
#include <sys/un.h>
|
||||||
|
#include <netinet/in.h>
|
||||||
|
#include <netdb.h>
|
||||||
|
#endif /* _WIN32 */
|
||||||
|
|
||||||
#include "xcb.h"
|
#include "xcb.h"
|
||||||
#include "xcbext.h"
|
#include "xcbext.h"
|
||||||
#include "xcbint.h"
|
#include "xcbint.h"
|
||||||
|
@ -122,7 +125,9 @@ int xcb_parse_display(const char *name, char **host, int *displayp,
|
||||||
}
|
}
|
||||||
|
|
||||||
static int _xcb_open_tcp(char *host, char *protocol, const unsigned short port);
|
static int _xcb_open_tcp(char *host, char *protocol, const unsigned short port);
|
||||||
|
#ifndef _WIN32
|
||||||
static int _xcb_open_unix(char *protocol, const char *file);
|
static int _xcb_open_unix(char *protocol, const char *file);
|
||||||
|
#endif /* !WIN32 */
|
||||||
#ifdef DNETCONN
|
#ifdef DNETCONN
|
||||||
static int _xcb_open_decnet(const char *host, char *protocol, const unsigned short port);
|
static int _xcb_open_decnet(const char *host, char *protocol, const unsigned short port);
|
||||||
#endif
|
#endif
|
||||||
|
@ -162,7 +167,7 @@ static int _xcb_open(char *host, char *protocol, const int display)
|
||||||
return _xcb_open_tcp(host, protocol, port);
|
return _xcb_open_tcp(host, protocol, port);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#ifndef _WIN32
|
||||||
/* display specifies Unix socket */
|
/* display specifies Unix socket */
|
||||||
filelen = snprintf(file, sizeof(file), "%s%d", base, display);
|
filelen = snprintf(file, sizeof(file), "%s%d", base, display);
|
||||||
if(filelen < 0)
|
if(filelen < 0)
|
||||||
|
@ -176,6 +181,7 @@ static int _xcb_open(char *host, char *protocol, const int display)
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
return _xcb_open_unix(protocol, file);
|
return _xcb_open_unix(protocol, file);
|
||||||
|
#endif /* !_WIN32 */
|
||||||
}
|
}
|
||||||
|
|
||||||
static int _xcb_socket(int family, int type, int proto)
|
static int _xcb_socket(int family, int type, int proto)
|
||||||
|
@ -188,8 +194,10 @@ static int _xcb_socket(int family, int type, int proto)
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
fd = socket(family, type, proto);
|
fd = socket(family, type, proto);
|
||||||
|
#ifndef _WIN32
|
||||||
if (fd >= 0)
|
if (fd >= 0)
|
||||||
fcntl(fd, F_SETFD, FD_CLOEXEC);
|
fcntl(fd, F_SETFD, FD_CLOEXEC);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
return fd;
|
return fd;
|
||||||
}
|
}
|
||||||
|
@ -289,6 +297,7 @@ static int _xcb_open_tcp(char *host, char *protocol, const unsigned short port)
|
||||||
return fd;
|
return fd;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifndef _WIN32
|
||||||
static int _xcb_open_unix(char *protocol, const char *file)
|
static int _xcb_open_unix(char *protocol, const char *file)
|
||||||
{
|
{
|
||||||
int fd;
|
int fd;
|
||||||
|
@ -311,6 +320,7 @@ static int _xcb_open_unix(char *protocol, const char *file)
|
||||||
}
|
}
|
||||||
return fd;
|
return fd;
|
||||||
}
|
}
|
||||||
|
#endif /* !_WIN32 */
|
||||||
|
|
||||||
#ifdef HAVE_ABSTRACT_SOCKETS
|
#ifdef HAVE_ABSTRACT_SOCKETS
|
||||||
static int _xcb_open_abstract(char *protocol, const char *file, size_t filelen)
|
static int _xcb_open_abstract(char *protocol, const char *file, size_t filelen)
|
||||||
|
|
Loading…
Reference in New Issue