src/sock_tcp_internal.h
author Tero Marttila <terom@fixme.fi>
Mon, 04 May 2009 20:55:04 +0300
branchnew-transport
changeset 168 a58ad50911fc
parent 155 c59d3eaff0fb
permissions -rw-r--r--
refactor test.c into tests/*
154
f4472119de3b initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents: 117
diff changeset
     1
#ifndef SOCK_TCP_INTERNAL_H
f4472119de3b initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents: 117
diff changeset
     2
#define SOCK_TCP_INTERNAL_H
1
cf0e1bb6bcab a fancy socket abstraction layer, with TCP, next, SSL. Also, .hgignore
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     3
28
9c1050bc8709 add sock_stream_release/line_proto_release/irc_conn_release functions, and add proper cleanup to irc_net_create
Tero Marttila <terom@fixme.fi>
parents: 12
diff changeset
     4
/**
9c1050bc8709 add sock_stream_release/line_proto_release/irc_conn_release functions, and add proper cleanup to irc_net_create
Tero Marttila <terom@fixme.fi>
parents: 12
diff changeset
     5
 * @file
9c1050bc8709 add sock_stream_release/line_proto_release/irc_conn_release functions, and add proper cleanup to irc_net_create
Tero Marttila <terom@fixme.fi>
parents: 12
diff changeset
     6
 *
154
f4472119de3b initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents: 117
diff changeset
     7
 * Internal interface of the sock_tcp transport implementation.
1
cf0e1bb6bcab a fancy socket abstraction layer, with TCP, next, SSL. Also, .hgignore
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     8
 */
155
c59d3eaff0fb most of the new transport/sock code compiles, but things are still missing
Tero Marttila <terom@fixme.fi>
parents: 154
diff changeset
     9
#include "sock_tcp.h"
c59d3eaff0fb most of the new transport/sock code compiles, but things are still missing
Tero Marttila <terom@fixme.fi>
parents: 154
diff changeset
    10
#include "transport_fd.h"
30
7f8dd120933f rework error to use a struct error_desc, and move ERR_SOCK/ERR_GNUTLS definitions to sock.h/sock_gnutls.h. error_desc definitions are still in error.c, though :(
Tero Marttila <terom@fixme.fi>
parents: 29
diff changeset
    11
#include <netdb.h>
1
cf0e1bb6bcab a fancy socket abstraction layer, with TCP, next, SSL. Also, .hgignore
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    12
28
9c1050bc8709 add sock_stream_release/line_proto_release/irc_conn_release functions, and add proper cleanup to irc_net_create
Tero Marttila <terom@fixme.fi>
parents: 12
diff changeset
    13
/**
155
c59d3eaff0fb most of the new transport/sock code compiles, but things are still missing
Tero Marttila <terom@fixme.fi>
parents: 154
diff changeset
    14
 * Our transport type struct
c59d3eaff0fb most of the new transport/sock code compiles, but things are still missing
Tero Marttila <terom@fixme.fi>
parents: 154
diff changeset
    15
 */
c59d3eaff0fb most of the new transport/sock code compiles, but things are still missing
Tero Marttila <terom@fixme.fi>
parents: 154
diff changeset
    16
extern struct transport_type sock_tcp_type;
c59d3eaff0fb most of the new transport/sock code compiles, but things are still missing
Tero Marttila <terom@fixme.fi>
parents: 154
diff changeset
    17
c59d3eaff0fb most of the new transport/sock code compiles, but things are still missing
Tero Marttila <terom@fixme.fi>
parents: 154
diff changeset
    18
/**
c59d3eaff0fb most of the new transport/sock code compiles, but things are still missing
Tero Marttila <terom@fixme.fi>
parents: 154
diff changeset
    19
 * TCP transport state
1
cf0e1bb6bcab a fancy socket abstraction layer, with TCP, next, SSL. Also, .hgignore
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    20
 */
cf0e1bb6bcab a fancy socket abstraction layer, with TCP, next, SSL. Also, .hgignore
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    21
struct sock_tcp {
155
c59d3eaff0fb most of the new transport/sock code compiles, but things are still missing
Tero Marttila <terom@fixme.fi>
parents: 154
diff changeset
    22
    /** Base fd-based transport state */
c59d3eaff0fb most of the new transport/sock code compiles, but things are still missing
Tero Marttila <terom@fixme.fi>
parents: 154
diff changeset
    23
    struct transport_fd base_fd;
1
cf0e1bb6bcab a fancy socket abstraction layer, with TCP, next, SSL. Also, .hgignore
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    24
    
155
c59d3eaff0fb most of the new transport/sock code compiles, but things are still missing
Tero Marttila <terom@fixme.fi>
parents: 154
diff changeset
    25
    /** The resolver state for the async connect process */
85
75bc8b164ef8 async TCP connects,
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
    26
    struct addrinfo *async_res, *async_cur;
1
cf0e1bb6bcab a fancy socket abstraction layer, with TCP, next, SSL. Also, .hgignore
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    27
};
cf0e1bb6bcab a fancy socket abstraction layer, with TCP, next, SSL. Also, .hgignore
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    28
28
9c1050bc8709 add sock_stream_release/line_proto_release/irc_conn_release functions, and add proper cleanup to irc_net_create
Tero Marttila <terom@fixme.fi>
parents: 12
diff changeset
    29
/**
155
c59d3eaff0fb most of the new transport/sock code compiles, but things are still missing
Tero Marttila <terom@fixme.fi>
parents: 154
diff changeset
    30
 * Get a transport_fd pointer from a sock_tcp pointer
28
9c1050bc8709 add sock_stream_release/line_proto_release/irc_conn_release functions, and add proper cleanup to irc_net_create
Tero Marttila <terom@fixme.fi>
parents: 12
diff changeset
    31
 */
117
9cb405164250 move irc_log.c to modules/irc_log.c, and restructure sock_* to split the basic fd-level stuff out of sock_tcp and into sock_fd
Tero Marttila <terom@fixme.fi>
parents: 85
diff changeset
    32
#define SOCK_TCP_FD(sock_ptr) (&(sock_ptr)->base_fd)
9cb405164250 move irc_log.c to modules/irc_log.c, and restructure sock_* to split the basic fd-level stuff out of sock_tcp and into sock_fd
Tero Marttila <terom@fixme.fi>
parents: 85
diff changeset
    33
9cb405164250 move irc_log.c to modules/irc_log.c, and restructure sock_* to split the basic fd-level stuff out of sock_tcp and into sock_fd
Tero Marttila <terom@fixme.fi>
parents: 85
diff changeset
    34
/**
155
c59d3eaff0fb most of the new transport/sock code compiles, but things are still missing
Tero Marttila <terom@fixme.fi>
parents: 154
diff changeset
    35
 * Get a transport pointer from a sock_tcp pointer
28
9c1050bc8709 add sock_stream_release/line_proto_release/irc_conn_release functions, and add proper cleanup to irc_net_create
Tero Marttila <terom@fixme.fi>
parents: 12
diff changeset
    36
 */
155
c59d3eaff0fb most of the new transport/sock code compiles, but things are still missing
Tero Marttila <terom@fixme.fi>
parents: 154
diff changeset
    37
#define SOCK_TCP_TRANSPORT(sock_ptr) TRANSPORT_FD_BASE(SOCK_TCP_FD(sock_ptr))
85
75bc8b164ef8 async TCP connects,
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
    38
75bc8b164ef8 async TCP connects,
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
    39
/**
155
c59d3eaff0fb most of the new transport/sock code compiles, but things are still missing
Tero Marttila <terom@fixme.fi>
parents: 154
diff changeset
    40
 * Initialize the sock_tcp state
85
75bc8b164ef8 async TCP connects,
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
    41
 */
155
c59d3eaff0fb most of the new transport/sock code compiles, but things are still missing
Tero Marttila <terom@fixme.fi>
parents: 154
diff changeset
    42
void sock_tcp_init (struct sock_tcp *sock);
85
75bc8b164ef8 async TCP connects,
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
    43
75bc8b164ef8 async TCP connects,
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
    44
/**
155
c59d3eaff0fb most of the new transport/sock code compiles, but things are still missing
Tero Marttila <terom@fixme.fi>
parents: 154
diff changeset
    45
 * Attempt to connect asyncronously to the given hostname/service. Once a connection has been established, this will
c59d3eaff0fb most of the new transport/sock code compiles, but things are still missing
Tero Marttila <terom@fixme.fi>
parents: 154
diff changeset
    46
 * call transport_connected(), so you can register transport_methods::_connected if layering on top of TCP.
85
75bc8b164ef8 async TCP connects,
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
    47
 *
155
c59d3eaff0fb most of the new transport/sock code compiles, but things are still missing
Tero Marttila <terom@fixme.fi>
parents: 154
diff changeset
    48
 * In case of errors while starting the async connect process, an error code will be returned. If the connect fails
c59d3eaff0fb most of the new transport/sock code compiles, but things are still missing
Tero Marttila <terom@fixme.fi>
parents: 154
diff changeset
    49
 * later on, transport_connected() will be called with the error code.
c59d3eaff0fb most of the new transport/sock code compiles, but things are still missing
Tero Marttila <terom@fixme.fi>
parents: 154
diff changeset
    50
 *
c59d3eaff0fb most of the new transport/sock code compiles, but things are still missing
Tero Marttila <terom@fixme.fi>
parents: 154
diff changeset
    51
 * The sock must have been initialized using sock_tcp_init().
85
75bc8b164ef8 async TCP connects,
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
    52
 *
75bc8b164ef8 async TCP connects,
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
    53
 * @param sock the unconnected TCP socket to connect with
75bc8b164ef8 async TCP connects,
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
    54
 * @param hostname the hostname to resolve
75bc8b164ef8 async TCP connects,
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
    55
 * @param service the service to connect to
155
c59d3eaff0fb most of the new transport/sock code compiles, but things are still missing
Tero Marttila <terom@fixme.fi>
parents: 154
diff changeset
    56
 * @param err returned error info for immediate errors
85
75bc8b164ef8 async TCP connects,
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
    57
 */
155
c59d3eaff0fb most of the new transport/sock code compiles, but things are still missing
Tero Marttila <terom@fixme.fi>
parents: 154
diff changeset
    58
err_t sock_tcp_connect_async (struct sock_tcp *sock, const char *hostname, const char *service, error_t *err);
85
75bc8b164ef8 async TCP connects,
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
    59
75bc8b164ef8 async TCP connects,
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
    60
/**
155
c59d3eaff0fb most of the new transport/sock code compiles, but things are still missing
Tero Marttila <terom@fixme.fi>
parents: 154
diff changeset
    61
 * Destroy the sock_tcp's state, including the transport_fd state.
85
75bc8b164ef8 async TCP connects,
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
    62
 */
155
c59d3eaff0fb most of the new transport/sock code compiles, but things are still missing
Tero Marttila <terom@fixme.fi>
parents: 154
diff changeset
    63
void sock_tcp_destroy (struct sock_tcp *sock);
1
cf0e1bb6bcab a fancy socket abstraction layer, with TCP, next, SSL. Also, .hgignore
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    64
154
f4472119de3b initial code towards transport implementation, doesn't compile
Tero Marttila <terom@fixme.fi>
parents: 117
diff changeset
    65
#endif /* SOCK_TCP_INTERNAL_H */