--- a/src/sock.c Sun Apr 12 23:27:15 2009 +0300
+++ b/src/sock.c Thu Apr 16 01:20:09 2009 +0300
@@ -20,13 +20,15 @@
return SUCCESS;
}
-void sock_stream_init (struct sock_stream *sock, struct sock_stream_type *type)
+void sock_stream_init (struct sock_stream *sock, struct sock_stream_type *type, sock_stream_connect_cb cb_func, void *cb_arg)
{
// be strict
assert(sock->type == NULL);
- // store type
+ // store
sock->type = type;
+ sock->conn_cb_func = cb_func;
+ sock->conn_cb_arg = cb_arg;
}
int sock_stream_read (struct sock_stream *sock, void *buf, size_t len)
@@ -92,6 +94,22 @@
sock->cb_info->on_read(sock, sock->cb_arg);
}
+void sock_stream_invoke_conn_cb (struct sock_stream *sock, struct error_info *err, bool direct)
+{
+ if (!direct && sock->type->methods._conn_cb) {
+ // invoke indirectly
+ sock->type->methods._conn_cb(sock, err);
+
+ } else {
+ sock_stream_connect_cb cb_func = sock->conn_cb_func;
+
+ // invoke directly
+ sock->conn_cb_func = NULL;
+ cb_func(sock, err, sock->conn_cb_arg);
+ sock->conn_cb_arg = NULL;
+ }
+}
+
void sock_stream_release (struct sock_stream *sock)
{
sock->type->methods.release(sock);