]> git.cworth.org Git - ttt/blobdiff - src/ttt-socket.c
2005-11-14 Carl Worth <cworth@cworth.org>
[ttt] / src / ttt-socket.c
index 18577ffa378468088938985545f8d758507ee50a..199535f300e200d0970341ea6177e53cf35bbf70 100644 (file)
@@ -146,11 +146,45 @@ ttt_socket_create_server (const char *host, const char *port)
 
 /* Exported: see ttt-socket.h for documentation. */
 void
 
 /* Exported: see ttt-socket.h for documentation. */
 void
-ttt_socket_accept (int listen_socket, ttt_socket_dispatch_func_t dispatch)
+ttt_socket_accept (int                          listen_socket,
+                  ttt_socket_accept_func_t      accept,
+                  void                         *closure)
 {
     int connected_socket;
 
     connected_socket = _wait_for_connection (listen_socket);
 
 {
     int connected_socket;
 
     connected_socket = _wait_for_connection (listen_socket);
 
-    (dispatch) (connected_socket);
+    (accept) (closure, connected_socket);
+}
+
+/* Exported: see ttt-socket.h for documentation. */
+void
+ttt_socket_read (int    socket,
+                void   *buf,
+                size_t  count)
+{
+    int bytes_read;
+    char *cbuf = buf;
+
+    while (count) {
+       bytes_read = xread (socket, cbuf, count);
+       cbuf += bytes_read;
+       count -= bytes_read;
+    }
+}
+
+/* Exported: see ttt-socket.h for documentation. */
+void
+ttt_socket_write (int           socket,
+                 const void    *buf,
+                 size_t         count)
+{
+    int written;
+    const char *cbuf = buf;
+
+    while (count) {
+       written = xwrite (socket, cbuf, count);
+       cbuf += written;
+       count -= written;
+    }
 }
 }