#ifndef SOCK_TCP_INTERNAL_H
#define SOCK_TCP_INTERNAL_H
/**
* @file
*
* Internal interface of the sock_tcp transport implementation.
*/
#include "sock_tcp.h"
#include "transport_fd.h"
#include <netdb.h>
/**
* Our transport type struct
*/
extern struct transport_type sock_tcp_type;
/**
* TCP transport state
*/
struct sock_tcp {
/** Base fd-based transport state */
struct transport_fd base_fd;
/** The resolver state for the async connect process */
struct addrinfo *async_res, *async_cur;
};
/**
* Get a transport_fd pointer from a sock_tcp pointer
*/
#define SOCK_TCP_FD(sock_ptr) (&(sock_ptr)->base_fd)
/**
* Get a transport pointer from a sock_tcp pointer
*/
#define SOCK_TCP_TRANSPORT(sock_ptr) TRANSPORT_FD_BASE(SOCK_TCP_FD(sock_ptr))
/**
* Initialize the sock_tcp state
*/
void sock_tcp_init (struct sock_tcp *sock);
/**
* Attempt to connect asyncronously to the given hostname/service. Once a connection has been established, this will
* call transport_connected(), so you can register transport_methods::_connected if layering on top of TCP.
*
* In case of errors while starting the async connect process, an error code will be returned. If the connect fails
* later on, transport_connected() will be called with the error code.
*
* The sock must have been initialized using sock_tcp_init().
*
* @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 for immediate errors
*/
err_t sock_tcp_connect_async (struct sock_tcp *sock, const char *hostname, const char *service, error_t *err);
/**
* Destroy the sock_tcp's state, including the transport_fd state.
*/
void sock_tcp_destroy (struct sock_tcp *sock);
#endif /* SOCK_TCP_INTERNAL_H */