From: Thadeu Lima de Souza Cascardo Date: Fri, 3 Jul 2009 17:26:47 +0000 (-0300) Subject: Check for driver methods before calling them and reset them on close. X-Git-Tag: v0.1.3~44 X-Git-Url: http://git.cascardo.eti.br/?p=cascardo%2Frnetproxy.git;a=commitdiff_plain;h=1516afb0ad6c38be922c304d2d002161cfeb8b7a Check for driver methods before calling them and reset them on close. This may avoid some hickups when methods are improperly called. --- diff --git a/hcconn.c b/hcconn.c index aac7cc1..02f1572 100644 --- a/hcconn.c +++ b/hcconn.c @@ -173,7 +173,9 @@ hc_conn_set_callback (HCConn *conn, HCClientFunc func, gpointer data) ssize_t hc_conn_read (HCConn *conn, char *buffer, size_t len) { - return conn->read (conn->layer, buffer, len); + if (conn->read) + return conn->read (conn->layer, buffer, len); + return 0; } void @@ -182,12 +184,18 @@ 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); + if (conn->write) + conn->write (conn->layer, buffer, len); } void hc_conn_close (HCConn *conn) { - conn->close (conn->layer); + if (conn->close) + conn->close (conn->layer); + conn->read = NULL; + conn->write = NULL; + conn->close = NULL; + conn->func = NULL; g_slice_free (HCConn, conn); }