author | Tero Marttila <terom@fixme.fi> |
Wed, 08 Apr 2009 01:28:46 +0300 | |
changeset 120 | 576bab0a1c5a |
parent 117 | 9cb405164250 |
child 169 | e6a1ce44aecc |
permissions | -rw-r--r-- |
1
cf0e1bb6bcab
a fancy socket abstraction layer, with TCP, next, SSL. Also, .hgignore
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
1 |
#ifndef SOCK_TCP_H |
cf0e1bb6bcab
a fancy socket abstraction layer, with TCP, next, SSL. Also, .hgignore
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
2 |
#define SOCK_TCP_H |
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 |
* |
1
cf0e1bb6bcab
a fancy socket abstraction layer, with TCP, next, SSL. Also, .hgignore
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
7 |
* TCP implementation of sock_stream interface. |
cf0e1bb6bcab
a fancy socket abstraction layer, with TCP, next, SSL. Also, .hgignore
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
8 |
*/ |
cf0e1bb6bcab
a fancy socket abstraction layer, with TCP, next, SSL. Also, .hgignore
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
9 |
#include "sock_internal.h" |
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
|
10 |
#include "sock_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 |
/** |
1
cf0e1bb6bcab
a fancy socket abstraction layer, with TCP, next, SSL. Also, .hgignore
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
14 |
* Contains the base sock_stream struct, and the file descriptor |
cf0e1bb6bcab
a fancy socket abstraction layer, with TCP, next, SSL. Also, .hgignore
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
15 |
*/ |
cf0e1bb6bcab
a fancy socket abstraction layer, with TCP, next, SSL. Also, .hgignore
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
16 |
struct sock_tcp { |
85 | 17 |
/** The base struct for sock_stream_* functions */ |
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
|
18 |
struct sock_fd base_fd; |
1
cf0e1bb6bcab
a fancy socket abstraction layer, with TCP, next, SSL. Also, .hgignore
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
19 |
|
85 | 20 |
/** The current connect_async resolved address */ |
21 |
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
|
22 |
}; |
cf0e1bb6bcab
a fancy socket abstraction layer, with TCP, next, SSL. Also, .hgignore
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
23 |
|
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
|
24 |
/** |
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
|
25 |
* Get a sock_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
|
26 |
*/ |
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
|
27 |
#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
|
28 |
|
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
|
29 |
/** |
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
|
30 |
* Get a sock_base pointer from a sock_tcp pointer |
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
|
31 |
*/ |
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_BASE(sock_ptr) SOCK_FD_BASE(SOCK_TCP_FD(sock_ptr)) |
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
|
33 |
|
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
|
34 |
/** |
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
|
35 |
* Get the sock_stream.err pointer from a sock_tcp pointer |
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 |
*/ |
3 | 37 |
#define SOCK_TCP_ERR(sock_ptr) SOCK_ERR(SOCK_TCP_BASE(sock_ptr)) |
1
cf0e1bb6bcab
a fancy socket abstraction layer, with TCP, next, SSL. Also, .hgignore
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
38 |
|
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
|
39 |
/** |
85 | 40 |
* Initialize a blank sock_tcp by creating a new socket (using the socket() syscall), but doesn't do anything further. |
41 |
* |
|
42 |
* This uses the ai_family, ai_socktype and ai_protocol fields from the given addrinfo. |
|
43 |
*/ |
|
44 |
err_t sock_tcp_init_socket (struct sock_tcp *sock, struct addrinfo *addr, struct error_info *err); |
|
45 |
||
46 |
/** |
|
47 |
* Initiate an async connection operation on the given socket to the given address. Once the connect() completes, |
|
48 |
* either the on_connect or the on_error callback will be called. |
|
49 |
* |
|
50 |
* If, for some weird reason, this ends up doing a blocking connect(), the on_connect callback will be called directly. |
|
51 |
* If the async connect fails, this just returns the error. |
|
52 |
* |
|
53 |
* @param sock the unconnected TCP sockect to connect with |
|
54 |
* @param addr the address to connect to |
|
55 |
* @param err returned error info |
|
56 |
*/ |
|
57 |
err_t sock_tcp_connect_async_addr (struct sock_tcp *sock, struct addrinfo *addr, struct error_info *err); |
|
58 |
||
59 |
/** |
|
60 |
* Attempt to connect asyncronously to the given hostname/service. Once a connection has been established, the |
|
61 |
* on_connect() callback will be called. |
|
62 |
* |
|
63 |
* In case of errors, either on_error() will be called, or an error returned - depending on when the error happaned. |
|
64 |
* |
|
65 |
* @param sock the unconnected TCP socket to connect with |
|
66 |
* @param hostname the hostname to resolve |
|
67 |
* @param service the service to connect to |
|
68 |
* @param err returned error info |
|
69 |
*/ |
|
70 |
err_t sock_tcp_connect_async_begin (struct sock_tcp *sock, const char *hostname, const char *service, struct error_info *err); |
|
71 |
||
72 |
/** |
|
73 |
* Initialize a blank sock_tcp by connecting in a blocking fashion. |
|
74 |
*/ |
|
75 |
err_t sock_tcp_connect_blocking (struct sock_tcp *sock, const char *hostname, const char *service, struct error_info *err); |
|
3 | 76 |
|
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
|
77 |
/** |
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
|
78 |
* Free a non-connected sock_tcp |
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
|
79 |
*/ |
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
|
80 |
void sock_tcp_free (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
|
81 |
|
cf0e1bb6bcab
a fancy socket abstraction layer, with TCP, next, SSL. Also, .hgignore
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
82 |
#endif /* SOCK_TCP_H */ |