]> git.tdb.fi Git - gldbg.git/blobdiff - source/glwrap.c
Send as much of a packet as possible before calling the original function
[gldbg.git] / source / glwrap.c
index 52c6552e1f5c0c007939e62f07a31e233ba8e587..4c17edfca772755f16a983253e96d37cf3ef0de6 100644 (file)
@@ -8,7 +8,9 @@ Distributed under the GPL
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
+#include <errno.h>
 #include <dlfcn.h>
+#include <fcntl.h>
 #include <sys/uio.h>
 
 #define INTERNAL __attribute__((visibility("internal")))
@@ -175,17 +177,20 @@ INTERNAL inline void begin_packet(int func)
                buffer = (char *)malloc(1024);
        if(!iovecs)
                iovecs = (struct iovec *)malloc(16*sizeof(struct iovec));
+
        write_pos = buffer;
        cur_vec = iovecs;
        cur_vec->iov_base = write_pos;
        length = 0;
+
        write_int(0);
        write_short(func);
 }
 
-INTERNAL inline void send_packet(void)
+INTERNAL inline int get_out_fd(void)
 {
        static int fd = -1;
+
        if(fd<0)
        {
                const char *var = getenv("GLWRAP_FD");
@@ -194,8 +199,29 @@ INTERNAL inline void send_packet(void)
                else
                        fd = 2;
        }
+
+       return fd;
+}
+
+INTERNAL inline void send_partial_packet(void)
+{
+       next_vec();
+       write_pos = buffer;
+       write_int(length|0x80000000);
+       writev(get_out_fd(), iovecs, cur_vec-iovecs);
+
+       write_pos = buffer;
+       cur_vec = iovecs;
+       cur_vec->iov_base = write_pos;
+       length = 0;
+
+       write_int(0);
+}
+
+INTERNAL inline void send_packet(void)
+{
        next_vec();
        write_pos = buffer;
        write_int(length);
-       writev(fd, iovecs, cur_vec-iovecs);
+       writev(get_out_fd(), iovecs, cur_vec-iovecs);
 }