src/sock_tcp.h
changeset 169 e6a1ce44aecc
parent 117 9cb405164250
parent 155 c59d3eaff0fb
--- a/src/sock_tcp.h	Fri Apr 24 23:01:34 2009 +0300
+++ b/src/sock_tcp.h	Mon May 04 20:55:43 2009 +0300
@@ -4,79 +4,25 @@
 /**
  * @file
  *
- * TCP implementation of sock_stream interface.
- */
-#include "sock_internal.h"
-#include "sock_fd.h"
-#include <netdb.h>
-
-/**
- * Contains the base sock_stream struct, and the file descriptor
+ * TCP transport implementation.
+ *
+ * XXX: provide some TCP-specific type/functions?
  */
-struct sock_tcp {
-    /** The base struct for sock_stream_* functions */
-    struct sock_fd base_fd;
-    
-    /** The current connect_async resolved address */
-    struct addrinfo *async_res, *async_cur;
-};
-
-/**
- * Get a sock_fd pointer from a sock_tcp pointer
- */
-#define SOCK_TCP_FD(sock_ptr) (&(sock_ptr)->base_fd)
-
-/**
- * Get a sock_base pointer from a sock_tcp pointer
- */
-#define SOCK_TCP_BASE(sock_ptr) SOCK_FD_BASE(SOCK_TCP_FD(sock_ptr))
-
-/**
- * Get the sock_stream.err pointer from a sock_tcp pointer
- */
-#define SOCK_TCP_ERR(sock_ptr) SOCK_ERR(SOCK_TCP_BASE(sock_ptr))
+#include "transport.h"
 
 /**
- * Initialize a blank sock_tcp by creating a new socket (using the socket() syscall), but doesn't do anything further.
+ * Connect the given transport via TCP to the given host/service. The transport will not be ready for use until the
+ * transport_callbacks::on_connect callback has been invoked.
  *
- * This uses the ai_family, ai_socktype and ai_protocol fields from the given addrinfo.
- */
-err_t sock_tcp_init_socket (struct sock_tcp *sock, struct addrinfo *addr, struct error_info *err);
-
-/**
- * Initiate an async connection operation on the given socket to the given address. Once the connect() completes,
- * either the on_connect or the on_error callback will be called.
+ * XXX: blocking DNS resolution
  *
- * If, for some weird reason, this ends up doing a blocking connect(), the on_connect callback will be called directly.
- * If the async connect fails, this just returns the error.
- *
- * @param sock the unconnected TCP sockect to connect with
- * @param addr the address to connect to
+ * @param info the transport setup info
+ * @param transport_ptr returned transport
+ * @param host the hostname to connect to
+ * @param service the service name (i.e. port) to connect to
  * @param err returned error info
  */
-err_t sock_tcp_connect_async_addr (struct sock_tcp *sock, struct addrinfo *addr, struct error_info *err);
+err_t sock_tcp_connect (const struct transport_info *info, transport_t **transport_ptr, 
+        const char *host, const char *service, error_t *err);
 
-/**
- * Attempt to connect asyncronously to the given hostname/service. Once a connection has been established, the
- * on_connect() callback will be called.
- *
- * In case of errors, either on_error() will be called, or an error returned - depending on when the error happaned.
- *
- * @param sock the unconnected TCP socket to connect with
- * @param hostname the hostname to resolve
- * @param service the service to connect to
- * @param err returned error info
- */
-err_t sock_tcp_connect_async_begin (struct sock_tcp *sock, const char *hostname, const char *service, struct error_info *err);
-
-/**
- * Initialize a blank sock_tcp by connecting in a blocking fashion.
- */
-err_t sock_tcp_connect_blocking (struct sock_tcp *sock, const char *hostname, const char *service, struct error_info *err);
-
-/**
- * Free a non-connected sock_tcp
- */
-void sock_tcp_free (struct sock_tcp *sock);
-
-#endif /* SOCK_TCP_H */
+#endif