Added some comments and reminders in connection system.
authorThadeu Lima de Souza Cascardo <cascardo@holoscopio.com>
Fri, 3 Jul 2009 05:14:52 +0000 (02:14 -0300)
committerThadeu Lima de Souza Cascardo <cascardo@holoscopio.com>
Fri, 3 Jul 2009 05:14:52 +0000 (02:14 -0300)
hcconn.c

index 479db92..3b2a890 100644 (file)
--- a/hcconn.c
+++ b/hcconn.c
@@ -22,6 +22,8 @@
 #include <fcntl.h>
 #include "hcconn_internal.h"
 
+/* The server connection watch */
+
 struct hc_server_cb
 {
   GIOChannel *channel;
@@ -58,17 +60,20 @@ hc_server_add_watch (int fd,
   cb->channel = g_io_channel_unix_new (fd);
   cb->func = func;
   cb->data = data;
+  /* TODO: we should have some way to remove this watch */
   g_io_add_watch_full (cb->channel, G_PRIORITY_DEFAULT, G_IO_IN,
                        hc_server_watch, cb, hc_server_cb_destroy);
 }
 
+
+/* The IOChannel (simple socket) layer */
+
 struct channel_layer
 {
   GIOChannel *channel;
   guint watch;
 };
 
-
 ssize_t
 hc_conn_channel_read (gpointer data, char *buffer, size_t len)
 {
@@ -100,6 +105,7 @@ gboolean
 hc_conn_watch (GIOChannel *channel, GIOCondition cond, gpointer data)
 {
   HCConn *conn = data;
+  /* TODO: What about other events, like closing? */
   HCEvent event = HC_EVENT_READ;
   if (conn->func)
     conn->func (conn, event, conn->data);
@@ -115,12 +121,17 @@ hc_conn_set_driver_channel (HCConn *conn, int fd)
   conn->read = hc_conn_channel_read;
   conn->write = hc_conn_channel_write;
   conn->close = hc_conn_channel_close;
+  /* TODO: We must watch other events */
   layer->watch = g_io_add_watch (layer->channel, G_IO_IN, hc_conn_watch, conn);
+  /* TODO: connection should be asynchronous so this could make sense */
   if (conn->func)
     conn->func (conn, HC_EVENT_CONNECT, conn->data);
   fcntl (fd, F_SETFL, fcntl (fd, F_GETFL, 0) | O_NONBLOCK);
 }
 
+
+/* The core connection system */
+
 HCConn *
 hc_conn_new (HCClientFunc func, gpointer data)
 {
@@ -148,6 +159,8 @@ void
 hc_conn_write (HCConn *conn, char *buffer, size_t len)
 {
   /* TODO: Do buffering or something like that */
+  /* Do we really need to? */
+  /* In case of error, we should do something */
   conn->write (conn->layer, buffer, len);
 }