--- a/src/transport_internal.h Tue Apr 28 17:52:48 2009 +0300
+++ b/src/transport_internal.h Tue Apr 28 20:27:45 2009 +0300
@@ -8,6 +8,8 @@
*/
#include "transport.h"
+#include <stdbool.h>
+
/**
* Method table for implementation stuff
*/
@@ -18,8 +20,24 @@
/** For transport_write() */
err_t (*write) (transport_t *transport, const void *buf, size_t *len, error_t *err);
- /** Release the transport's state, but not the transport itself */
+ /**
+ * Release the transport's internal state, but not the transport itself.
+ *
+ * In other words, this should release everything inside the transport_t, but not free() the transport_t itself.
+ */
void (*destroy) (transport_t *transport);
+
+ /**
+ * Used by layered transports to handle transport_connected.
+ *
+ * If this is NULL, transport_connected will call the user callback directly, otherwise, it will proxy through this.
+ *
+ * The \a err param follows the same rules as for transport_connected() - NULL for success, error info otherwise.
+ *
+ * @param transport the transport state
+ * @param err error info if the connect failed
+ */
+ void (*_connected) (transport_t *transport, const error_t *err);
};
/**
@@ -39,6 +57,9 @@
/** User info */
struct transport_info info;
+
+ /** Are we connected? */
+ bool connected;
};
/**
@@ -46,7 +67,7 @@
*
* It is a bug to call this with a transport that is already bound.
*/
-void transport_bind (transport_t *transport, const struct transport_type *type, const struct transport_info *info);
+void transport_init (transport_t *transport, const struct transport_type *type, const struct transport_info *info);
/**
* Check the type of the transport, and return the transport as a void* suitable for casting to the appropriate struct
@@ -56,5 +77,33 @@
*/
void* transport_check (transport_t *transport, const struct transport_type *type);
+/**
+ * Mark the transport as connected, calling transport_methods::_connected if it exists and \a direct is not given,
+ * transport_callbacks::on_connected/transport_callbacks::on_error otherwise.
+ *
+ * If the connect succeeded, \a err should be given as NULL. If the connect failed, \a err should contain the error
+ * info.
+ *
+ * If called from the transport_methods::_connected method, pass in direct to avoid recursion.
+ *
+ * This sets the transport::connected flag, regardless of which callback it invokes.
+ *
+ * XXX: implement proper layering of types, linkig transport_type's together
+ *
+ * @param transport the transport state
+ * @param err NULL for success, otherwise connect error code
+ * @param direct call the user callback directly, ignoring any method
+ */
+void transport_connected (transport_t *transport, const error_t *err, bool direct);
+
+/**
+ * Invoke the user callbacks based on the given TRANSPORT_* flags
+ */
+void transport_invoke (transport_t *transport, short what);
+
+/**
+ * Mark the transport as failed, calling transport_methods::on_error with the given error code.
+ */
+void transport_error (transport_t *transport, const error_t *err);
#endif /* TRANSPORT_INTERNAL_H */