From: Thadeu Lima de Souza Cascardo Date: Fri, 3 Jul 2009 05:14:52 +0000 (-0300) Subject: Added some comments and reminders in connection system. X-Git-Tag: v0.1.3~49 X-Git-Url: http://git.cascardo.info/?p=cascardo%2Frnetproxy.git;a=commitdiff_plain;h=8aaec8d5c79aa2bc1eae9a6ac619a30ef80e9d2e Added some comments and reminders in connection system. --- diff --git a/hcconn.c b/hcconn.c index 479db92..3b2a890 100644 --- a/hcconn.c +++ b/hcconn.c @@ -22,6 +22,8 @@ #include #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); }