return TRUE;
}
-void
+int
hc_conn_set_driver_channel (HCConn *conn, int fd)
{
struct channel_layer *layer = g_slice_new (struct channel_layer);
if (conn->func)
conn->func (conn, HC_EVENT_CONNECT, conn->data);
fcntl (fd, F_SETFL, fcntl (fd, F_GETFL, 0) | O_NONBLOCK);
+ return 0;
}
void hc_conn_close (HCConn *);
void hc_conn_set_callback (HCConn *, HCClientFunc, gpointer);
-void hc_conn_set_driver_channel (HCConn *, int);
-void hc_conn_set_driver_ssl_client (HCConn *, HCConn *);
+int hc_conn_set_driver_channel (HCConn *, int);
+int hc_conn_set_driver_ssl_client (HCConn *, HCConn *);
#endif
}
}
-static void
+static int
hc_conn_set_driver_ssl (HCConn *conn, HCConn *lowconn, int server)
{
struct ssl_data *ssl;
ssl = ssl_data_new (server);
+ if (ssl == NULL)
+ return -1;
ssl->lowconn = lowconn;
conn->layer = ssl;
conn->read = hc_conn_ssl_read;
conn->close = hc_conn_ssl_close;
hc_conn_set_callback (lowconn, hc_conn_ssl_watch, conn);
ssl_server_connect (conn);
+ return 0;
}
-void hc_conn_set_driver_ssl_client (HCConn *conn, HCConn *lowconn)
+int
+hc_conn_set_driver_ssl_client (HCConn *conn, HCConn *lowconn)
{
- hc_conn_set_driver_ssl (conn, lowconn, 0);
+ return hc_conn_set_driver_ssl (conn, lowconn, 0);
}
pop_destroy (pop);
}
-void
+int
hc_conn_set_driver_pop (HCConn *conn, HCConn *lowconn)
{
pop_t *pop;
conn->close = pop_close;
conn->layer = pop;
hc_conn_set_callback (lowconn, pop_watch, conn);
+ return 0;
}
#include "hcconn.h"
-void hc_conn_set_driver_pop (HCConn *, HCConn *);
+int hc_conn_set_driver_pop (HCConn *, HCConn *);
#endif
int fd;
HCConn *conn;
HCConn *ssl_conn;
+ int r;
fd = hc_tcp_connect (server, port);
if (fd < 0)
{
}
conn = hc_conn_new (NULL, NULL);
ssl_conn = hc_conn_new (NULL, NULL);
- hc_conn_set_driver_channel (conn, fd);
- hc_conn_set_driver_ssl_client (ssl_conn, conn);
+ r = hc_conn_set_driver_channel (conn, fd);
+ if (r != 0)
+ {
+ hc_conn_close (ssl_conn);
+ hc_conn_close (conn);
+ close (fd);
+ return NULL;
+ }
+ r = hc_conn_set_driver_ssl_client (ssl_conn, conn);
+ if (r != 0)
+ {
+ hc_conn_close (ssl_conn);
+ hc_conn_close (conn);
+ return NULL;
+ }
return ssl_conn;
}
HCConn *pop_conn;
HCConn *server_conn;
struct pop_address *address = data;
+ int r;
if (fd < 0)
{
g_critical ("Server has received an error event.");
}
conn = hc_conn_new (NULL, NULL);
- hc_conn_set_driver_channel (conn, fd);
+ r = hc_conn_set_driver_channel (conn, fd);
+ if (r != 0)
+ {
+ hc_conn_close (server_conn);
+ hc_conn_close (conn);
+ close (fd);
+ return;
+ }
pop_conn = hc_conn_new (NULL, NULL);
- hc_conn_set_driver_pop (pop_conn, conn);
-
+ r = hc_conn_set_driver_pop (pop_conn, conn);
+ if (r != 0)
+ {
+ hc_conn_close (server_conn);
+ hc_conn_close (pop_conn);
+ hc_conn_close (conn);
+ return;
+ }
hc_conn_set_callback (pop_conn, push_other, server_conn);
hc_conn_set_callback (server_conn, push_other, pop_conn);