Added SILC Thread Queue API
[crypto.git] / apps / irssi / src / core / net-sendbuffer.c
index 04eab80aabde7927f2b5495ee26b50b62c55bd29..f8aac80ce2e95212a0aa1a63387e543f5d574e07 100644 (file)
 #include "network.h"
 #include "net-sendbuffer.h"
 
-struct _NET_SENDBUF_REC {
-       GIOChannel *handle;
-
-        int send_tag;
-       int bufsize;
-       int bufpos;
-       char *buffer; /* Buffer is NULL until it's actually needed. */
-};
-
 static GSList *buffers;
 
 /* Create new buffer - if `bufsize' is zero or less, DEFAULT_BUFFER_SIZE
@@ -62,7 +53,7 @@ void net_sendbuffer_destroy(NET_SENDBUF_REC *rec, int close)
        g_free(rec);
 }
 
-/* Transmit all data from buffer - return TRUE if successful */
+/* Transmit all data from buffer - return TRUE if the whole buffer was sent */
 static int buffer_send(NET_SENDBUF_REC *rec)
 {
        int ret;
@@ -140,6 +131,25 @@ int net_sendbuffer_send(NET_SENDBUF_REC *rec, const void *data, int size)
        return buffer_add(rec, data, size) ? 0 : -1;
 }
 
+/* Flush the buffer, blocks until finished. */
+void net_sendbuffer_flush(NET_SENDBUF_REC *rec)
+{
+       int handle;
+
+       if (rec->buffer == NULL)
+               return;
+
+        /* set the socket blocking while doing this */
+       handle = g_io_channel_unix_get_fd(rec->handle);
+#ifndef WIN32
+       fcntl(handle, F_SETFL, 0);
+#endif
+       while (!buffer_send(rec)) ;
+#ifndef WIN32
+       fcntl(handle, F_SETFL, O_NONBLOCK);
+#endif
+}
+
 /* Returns the socket handle */
 GIOChannel *net_sendbuffer_handle(NET_SENDBUF_REC *rec)
 {