Merge branch 'gsoc2010' of git://anongit.freedesktop.org/~chr/libxcb
authorPeter Harris <pharris@opentext.com>
Wed, 8 Sep 2010 18:41:52 +0000 (14:41 -0400)
committerPeter Harris <pharris@opentext.com>
Wed, 8 Sep 2010 18:41:52 +0000 (14:41 -0400)
NEWS
configure.ac
doc/tutorial/index.html
src/xcb.h
src/xcb_auth.c
src/xcb_conn.c
src/xcb_in.c
src/xcb_util.c
src/xcb_windefs.h [new file with mode: 0644]

diff --git a/NEWS b/NEWS
index 4570598..7969813 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -1,3 +1,12 @@
+Release 1.7 (2010-08-13)
+========================
+- Always wake up readers after writing
+- Get rid of PATH_MAX and MAXPATHLEN
+- Add ~ operator support in code generator
+- xcb_open: Improve protocol/host parsing
+- xcb_connect_to_display_with_auth_info: Fix memory leak
+- Report which extensions are being built
+
 Release 1.6 (2010-04-09)
 ========================
 - darwin: xnu doesn't support poll on ttys on the master side
index 67295f8..848310e 100644 (file)
@@ -3,7 +3,7 @@
 
 AC_PREREQ(2.57)
 AC_INIT([libxcb],
-        1.6,
+        1.7,
         [xcb@lists.freedesktop.org])
 AC_CONFIG_SRCDIR([xcb.pc.in])
 AM_INIT_AUTOMAKE([foreign dist-bzip2])
@@ -156,7 +156,7 @@ XCB_EXTENSION(XvMC, "yes")
 AC_ARG_WITH(launchd, AS_HELP_STRING([--with-launchd], [Build with support for Apple's launchd (default: auto)]), [LAUNCHD=$withval], [LAUNCHD=auto])
 if test "x$LAUNCHD" = xauto; then
        unset LAUNCHD
-       AC_CHECK_PROG(LAUNCHD, [launchd], [yes], [no])
+       AC_CHECK_PROG(LAUNCHD, [launchd], [yes], [no], [$PATH$PATH_SEPARATOR/sbin])
 fi
 
 if test "x$LAUNCHD" = xyes ; then
@@ -214,6 +214,31 @@ echo "    XDM support.........: ${have_xdmcp}"
 echo "    Build unit tests....: ${HAVE_CHECK}"
 echo "    XCB buffer size.....: ${xcb_queue_buffer_size}"
 echo ""
+echo "  X11 extensions"
+echo "    Composite...........: ${BUILD_COMPOSITE}"
+echo "    Damage..............: ${BUILD_DAMAGE}"
+echo "    Dpms................: ${BUILD_DPMS}"
+echo "    Dri2................: ${BUILD_DRI2}"
+echo "    Glx.................: ${BUILD_GLX}"
+echo "    Randr...............: ${BUILD_RANDR}"
+echo "    Record..............: ${BUILD_RECORD}"
+echo "    Render..............: ${BUILD_RENDER}"
+echo "    Resource............: ${BUILD_RESOURCE}"
+echo "    Screensaver.........: ${BUILD_SCREENSAVER}"
+echo "    selinux.............: ${BUILD_SELINUX}"
+echo "    Shape...............: ${BUILD_SHAPE}"
+echo "    Shm.................: ${BUILD_SHM}"
+echo "    Sync................: ${BUILD_SYNC}"
+echo "    Xevie...............: ${BUILD_XEVIE}"
+echo "    Xfixes..............: ${BUILD_XFIXES}"
+echo "    Xfree86-dri.........: ${BUILD_XFREE86_DRI}"
+echo "    xinerama............: ${BUILD_XINERAMA}"
+echo "    xinput..............: ${BUILD_XINPUT}"
+echo "    xprint..............: ${BUILD_XPRINT}"
+echo "    xtest...............: ${BUILD_XTEST}"
+echo "    xv..................: ${BUILD_XV}"
+echo "    xvmc................: ${BUILD_XVMC}"
+echo ""
 echo "  Used CFLAGS:"
 echo "    CPPFLAGS............: ${CPPFLAGS}"
 echo "    CFLAGS..............: ${CFLAGS}"
index aa3ae17..adec0ac 100644 (file)
@@ -1453,7 +1453,7 @@ typedef enum {
 </pre>
         <p>
         If the window has already been created, we can use the
-        <span class="code">xcb_configure_window()</span> function to set
+        <span class="code">xcb_change_window_attributes()</span> function to set
         the events that the window will receive. The subsection
         <a href="#winconf">Configuring a window</a> shows its
         prototype. As an example, here is a piece of code that
@@ -1466,7 +1466,7 @@ const static uint32_t values[] = { XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_BUTT
 
 /* The connection c and the window win are supposed to be defined */
 
-xcb_configure_window (c, win, XCB_CW_EVENT_MASK, values);
+xcb_change_window_attributes (c, win, XCB_CW_EVENT_MASK, values);
 </pre>
         <div class="emph">
         <p>
index 35d8768..14244a7 100644 (file)
--- a/src/xcb.h
+++ b/src/xcb.h
 #include <stdint.h>
 #endif
 
+#ifndef _WIN32
 #include <sys/uio.h>
+#else
+#include "xcb_windefs.h"
+#endif
 #include <pthread.h>
 
 
index d774d10..1af27fc 100644 (file)
 
 #include <assert.h>
 #include <X11/Xauth.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <sys/un.h>
 #include <sys/param.h>
 #include <unistd.h>
 #include <stdlib.h>
 
+#ifdef _WIN32
+#include "xcb_windefs.h"
+#else
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <sys/un.h>
+#endif /* _WIN32 */
+
 #include "xcb.h"
 #include "xcbint.h"
 
index 50a662b..f2a2636 100644 (file)
@@ -30,7 +30,6 @@
 #include <stdio.h>
 #include <unistd.h>
 #include <stdlib.h>
-#include <netinet/in.h>
 #include <fcntl.h>
 #include <errno.h>
 
 #include "xcbint.h"
 #if USE_POLL
 #include <poll.h>
-#else
+#elif !defined _WIN32
 #include <sys/select.h>
 #endif
 
+#ifdef _WIN32
+#include "xcb_windefs.h"
+#else
+#include <netinet/in.h>
+#endif /* _WIN32 */
+
+/* SHUT_RDWR is fairly recent and is not available on all platforms */
+#if !defined(SHUT_RDWR)
+#define SHUT_RDWR 2
+#endif
+
 typedef struct {
     uint8_t  status;
     uint8_t  pad0[5];
@@ -52,6 +62,17 @@ static const int error_connection = 1;
 
 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);
     if(flags == -1)
         return 0;
@@ -61,6 +82,7 @@ static int set_fd_flags(const int fd)
     if(fcntl(fd, F_SETFD, FD_CLOEXEC) == -1)
         return 0;
     return 1;
+#endif /* _WIN32 */
 }
 
 static int write_setup(xcb_connection_t *c, xcb_auth_info_t *auth_info)
@@ -153,9 +175,37 @@ static int write_vec(xcb_connection_t *c, struct iovec **vector, int *count)
 {
     int n;
     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);
     if(n < 0 && errno == EAGAIN)
         return 1;
+#endif /* _WIN32 */    
+
     if(n <= 0)
     {
         _xcb_conn_shutdown(c);
@@ -247,6 +297,9 @@ void xcb_disconnect(xcb_connection_t *c)
         return;
 
     free(c->setup);
+
+    /* disallow further sends and receives */
+    shutdown(c->fd, SHUT_RDWR);
     close(c->fd);
 
     pthread_mutex_destroy(&c->iolock);
@@ -310,15 +363,22 @@ int _xcb_conn_wait(xcb_connection_t *c, pthread_cond_t *cond, struct iovec **vec
     pthread_mutex_unlock(&c->iolock);
     do {
 #if USE_POLL
-    ret = poll(&fd, 1, -1);
+        ret = poll(&fd, 1, -1);
+        /* If poll() returns an event we didn't expect, such as POLLNVAL, treat
+         * it as if it failed. */
+        if(ret >= 0 && (fd.revents & ~fd.events))
+        {
+            ret = -1;
+            break;
+        }
 #else
-       ret = select(c->fd + 1, &rfds, &wfds, 0, 0);
+        ret = select(c->fd + 1, &rfds, &wfds, 0, 0);
 #endif
     } while (ret == -1 && errno == EINTR);
-    if (ret < 0)
+    if(ret < 0)
     {
         _xcb_conn_shutdown(c);
-       ret = 0;
+        ret = 0;
     }
     pthread_mutex_lock(&c->iolock);
 
index 6dd358c..57d7e01 100644 (file)
 #include "xcbint.h"
 #if USE_POLL
 #include <poll.h>
-#else
+#endif
+#ifndef _WIN32
 #include <sys/select.h>
+#include <sys/socket.h>
 #endif
 
+#ifdef _WIN32
+#include "xcb_windefs.h"
+#endif /* _WIN32 */
+
 #define XCB_ERROR 0
 #define XCB_REPLY 1
 #define XCB_XGE_EVENT 35
 
+/* required for compiling for Win32 using MinGW */
+#ifndef MSG_WAITALL
+#define MSG_WAITALL 0
+#endif
+
 struct event_list {
     xcb_generic_event_t *event;
     struct event_list *next;
@@ -255,10 +266,14 @@ static int read_block(const int fd, void *buf, const ssize_t len)
     int done = 0;
     while(done < len)
     {
-        int ret = read(fd, ((char *) buf) + done, len - done);
+        int ret = recv(fd, ((char *) buf) + done, len - done,MSG_WAITALL);
         if(ret > 0)
             done += ret;
+#ifndef _WIN32
         if(ret < 0 && errno == EAGAIN)
+#else
+        if(ret == SOCKET_ERROR && WSAGetLastError() == WSAEWOULDBLOCK)
+#endif /* !_Win32 */
         {
 #if USE_POLL
             struct pollfd pfd;
@@ -272,10 +287,13 @@ static int read_block(const int fd, void *buf, const ssize_t len)
             fd_set fds;
             FD_ZERO(&fds);
             FD_SET(fd, &fds);
+
+           /* Initializing errno here makes sure that for Win32 this loop will execute only once */
+           errno = 0;  
            do {
                ret = select(fd + 1, &fds, 0, 0, 0);
            } while (ret == -1 && errno == EINTR);
-#endif
+#endif /* USE_POLL */
         }
         if(ret <= 0)
             return ret;
@@ -564,7 +582,7 @@ xcb_generic_error_t *xcb_request_check(xcb_connection_t *c, xcb_void_cookie_t co
     void *reply;
     if(c->has_error)
         return 0;
-    if(XCB_SEQUENCE_COMPARE_32(cookie.sequence,>,c->in.request_expected)
+    if(XCB_SEQUENCE_COMPARE_32(cookie.sequence,>=,c->in.request_expected)
        && XCB_SEQUENCE_COMPARE_32(cookie.sequence,>,c->in.request_completed))
     {
         free(xcb_get_input_focus_reply(c, xcb_get_input_focus(c), &ret));
@@ -663,12 +681,16 @@ void _xcb_in_replies_done(xcb_connection_t *c)
 
 int _xcb_in_read(xcb_connection_t *c)
 {
-    int n = read(c->fd, c->in.queue + c->in.queue_len, sizeof(c->in.queue) - c->in.queue_len);
+    int n = recv(c->fd, c->in.queue + c->in.queue_len, sizeof(c->in.queue) - c->in.queue_len,MSG_WAITALL);
     if(n > 0)
         c->in.queue_len += n;
     while(read_packet(c))
         /* empty */;
+#ifndef _WIN32
     if((n > 0) || (n < 0 && errno == EAGAIN))
+#else
+    if((n > 0) || (n < 0 && WSAGetLastError() == WSAEWOULDBLOCK))
+#endif /* !_WIN32 */
         return 1;
     _xcb_conn_shutdown(c);
     return 0;
index 58bd12d..c14d9d5 100644 (file)
 
 #include <assert.h>
 #include <sys/types.h>
-#include <sys/socket.h>
 #include <limits.h>
-#include <sys/un.h>
-#include <netinet/in.h>
-#include <netinet/tcp.h>
 #ifdef DNETCONN
 #include <netdnet/dnetdb.h>
 #include <netdnet/dn.h>
 #endif
-#include <netdb.h>
 #include <errno.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <stddef.h>
 #include <unistd.h>
-#include <fcntl.h>
 #include <string.h>
 
+#ifdef _WIN32
+#include "xcb_windefs.h"
+#else
+#include <sys/socket.h>
+#include <sys/un.h>
+#include <netinet/in.h>
+#include <netinet/tcp.h>
+#include <fcntl.h>
+#include <netdb.h>
+#endif /* _WIN32 */
+
 #include "xcb.h"
 #include "xcbext.h"
 #include "xcbint.h"
@@ -74,6 +79,7 @@ static int _xcb_parse_display(const char *name, char **host, char **protocol,
 {
     int len, display, screen;
     char *slash, *colon, *dot, *end;
+
     if(!name || !*name)
         name = getenv("DISPLAY");
     if(!name)
@@ -102,35 +108,43 @@ static int _xcb_parse_display(const char *name, char **host, char **protocol,
 
     colon = strrchr(name, ':');
     if(!colon)
-        return 0;
+        goto error_out;
     len = colon - name;
     ++colon;
     display = strtoul(colon, &dot, 10);
     if(dot == colon)
-        return 0;
+        goto error_out;
     if(*dot == '\0')
         screen = 0;
     else
     {
         if(*dot != '.')
-            return 0;
+            goto error_out;
         ++dot;
         screen = strtoul(dot, &end, 10);
         if(end == dot || *end != '\0')
-            return 0;
+            goto error_out;
     }
     /* At this point, the display string is fully parsed and valid, but
      * the caller's memory is untouched. */
 
     *host = malloc(len + 1);
     if(!*host)
-        return 0;
+        goto error_out;
     memcpy(*host, name, len);
     (*host)[len] = '\0';
     *displayp = display;
     if(screenp)
         *screenp = screen;
     return 1;
+
+error_out:
+    if (protocol) {
+        free(*protocol);
+        *protocol = NULL;
+    }
+
+    return 0;
 }
 
 int xcb_parse_display(const char *name, char **host, int *displayp,
@@ -140,7 +154,9 @@ int xcb_parse_display(const char *name, char **host, int *displayp,
 }
 
 static int _xcb_open_tcp(const char *host, char *protocol, const unsigned short port);
+#ifndef _WIN32
 static int _xcb_open_unix(char *protocol, const char *file);
+#endif /* !WIN32 */
 #ifdef DNETCONN
 static int _xcb_open_decnet(const char *host, char *protocol, const unsigned short port);
 #endif
@@ -189,6 +205,7 @@ static int _xcb_open(const char *host, char *protocol, const int display)
             }
     }
 
+#ifndef _WIN32
     filelen = strlen(base) + 1 + sizeof(display) * 3 + 1;
     file = malloc(filelen);
     if(file == NULL)
@@ -221,6 +238,8 @@ static int _xcb_open(const char *host, char *protocol, const int display)
     free(file);
 
     return fd;
+#endif /* !_WIN32 */
+    return -1; /* if control reaches here then something has gone wrong */
 }
 
 static int _xcb_socket(int family, int type, int proto)
@@ -233,8 +252,10 @@ static int _xcb_socket(int family, int type, int proto)
 #endif
     {
        fd = socket(family, type, proto);
+#ifndef _WIN32
        if (fd >= 0)
            fcntl(fd, F_SETFD, FD_CLOEXEC);
+#endif
     }
     return fd;
 }
@@ -341,6 +362,7 @@ static int _xcb_open_tcp(const char *host, char *protocol, const unsigned short
     return fd;
 }
 
+#ifndef _WIN32
 static int _xcb_open_unix(char *protocol, const char *file)
 {
     int fd;
@@ -363,6 +385,7 @@ static int _xcb_open_unix(char *protocol, const char *file)
     }
     return fd;
 }
+#endif /* !_WIN32 */
 
 #ifdef HAVE_ABSTRACT_SOCKETS
 static int _xcb_open_abstract(char *protocol, const char *file, size_t filelen)
@@ -399,24 +422,28 @@ xcb_connection_t *xcb_connect(const char *displayname, int *screenp)
 xcb_connection_t *xcb_connect_to_display_with_auth_info(const char *displayname, xcb_auth_info_t *auth, int *screenp)
 {
     int fd, display = 0;
-    char *host;
-    char *protocol;
+    char *host = NULL;
+    char *protocol = NULL;
     xcb_auth_info_t ourauth;
     xcb_connection_t *c;
 
     int parsed = _xcb_parse_display(displayname, &host, &protocol, &display, screenp);
     
-    if(!parsed)
-        return (xcb_connection_t *) &error_connection;
-    else
+    if(!parsed) {
+        c = (xcb_connection_t *) &error_connection;
+        goto out;
+    } else
         fd = _xcb_open(host, protocol, display);
-    free(host);
 
-    if(fd == -1)
-        return (xcb_connection_t *) &error_connection;
+    if(fd == -1) {
+        c = (xcb_connection_t *) &error_connection;
+        goto out;
+    }
 
-    if(auth)
-        return xcb_connect_to_fd(fd, auth);
+    if(auth) {
+        c = xcb_connect_to_fd(fd, auth);
+        goto out;
+    }
 
     if(_xcb_get_auth_info(fd, &ourauth, display))
     {
@@ -427,5 +454,8 @@ xcb_connection_t *xcb_connect_to_display_with_auth_info(const char *displayname,
     else
         c = xcb_connect_to_fd(fd, 0);
 
+out:
+    free(host);
+    free(protocol);
     return c;
 }
diff --git a/src/xcb_windefs.h b/src/xcb_windefs.h
new file mode 100644 (file)
index 0000000..d6c7329
--- /dev/null
@@ -0,0 +1,45 @@
+/* Copyright (C) 2009 Jatin Golani.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ * 
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ * 
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ * 
+ * Except as contained in this notice, the names of the authors or their
+ * institutions shall not be used in advertising or otherwise to promote the
+ * sale, use or other dealings in this Software without prior written
+ * authorization from the authors.
+ */
+
+
+#ifndef _XCB_WINDEFS_H
+#define _XCB_WINDEFS_H
+
+#ifndef WINVER
+#define WINVER 0x0501 /* required for getaddrinfo/freeaddrinfo defined only for WinXP and above */
+#endif
+
+#include <winsock2.h>
+#include <ws2tcpip.h>
+#include <windef.h>
+
+struct iovec  {
+    void *iov_base;    /* Pointer to data.  */
+    int iov_len;       /* Length of data.  */ 
+};
+
+typedef unsigned int in_addr_t;
+
+#endif /* xcb_windefs.h */