annotate th_network.h @ 657:253a341216b7

Doxygen fixes.
author Matti Hamalainen <ccr@tnsp.org>
date Mon, 27 Jan 2020 00:38:40 +0200
parents 3c9205d52376
children c17a1072974a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
102
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1 /*
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
2 * Simple TCP network connection handling
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
3 * Programmed and designed by Matti 'ccr' Hamalainen
553
3a852e9f70a6 Bump copyright years.
Matti Hamalainen <ccr@tnsp.org>
parents: 481
diff changeset
4 * (C) Copyright 2013-2020 Tecnic Software productions (TNSP)
102
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
5 *
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
6 * Please read file 'COPYING' for information on license and distribution.
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
7 */
657
253a341216b7 Doxygen fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 653
diff changeset
8 /// @file
253a341216b7 Doxygen fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 653
diff changeset
9 /// @brief Simple TCP network connection handling helpers
102
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
10 #ifndef TH_NETWORK_H
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
11 #define TH_NETWORK_H
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
12
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
13 #include <stdio.h>
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
14 #include <unistd.h>
577
70d44ba005ac Define a helper macro for __attribute__ ((__format__ (__printf__, 2, 3)))
Matti Hamalainen <ccr@tnsp.org>
parents: 570
diff changeset
15 #include "th_util.h"
270
6cfa9bc91ee6 Remember to include th_datastruct.h where needed.
Matti Hamalainen <ccr@tnsp.org>
parents: 191
diff changeset
16 #include "th_datastruct.h"
102
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
17
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
18
191
cc5411cb85de Use TH_PLAT_WINDOWS define for #ifdef logic.
Matti Hamalainen <ccr@tnsp.org>
parents: 190
diff changeset
19 #ifdef TH_PLAT_WINDOWS
457
85fa3d333556 Actually, revert the boolean changes .. meh.
Matti Hamalainen <ccr@tnsp.org>
parents: 454
diff changeset
20 # define __OBJC_BOOL // A nasty hack
191
cc5411cb85de Use TH_PLAT_WINDOWS define for #ifdef logic.
Matti Hamalainen <ccr@tnsp.org>
parents: 190
diff changeset
21 # include <windows.h>
cc5411cb85de Use TH_PLAT_WINDOWS define for #ifdef logic.
Matti Hamalainen <ccr@tnsp.org>
parents: 190
diff changeset
22 # include <winsock.h>
102
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
23 typedef uint16_t in_port_t;
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
24 typedef uint32_t in_addr_t;
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
25 #else
191
cc5411cb85de Use TH_PLAT_WINDOWS define for #ifdef logic.
Matti Hamalainen <ccr@tnsp.org>
parents: 190
diff changeset
26 # include <sys/select.h>
cc5411cb85de Use TH_PLAT_WINDOWS define for #ifdef logic.
Matti Hamalainen <ccr@tnsp.org>
parents: 190
diff changeset
27 # include <sys/socket.h>
cc5411cb85de Use TH_PLAT_WINDOWS define for #ifdef logic.
Matti Hamalainen <ccr@tnsp.org>
parents: 190
diff changeset
28 # ifdef HAVE_NETINET_IN_H
cc5411cb85de Use TH_PLAT_WINDOWS define for #ifdef logic.
Matti Hamalainen <ccr@tnsp.org>
parents: 190
diff changeset
29 # include <netinet/in.h>
cc5411cb85de Use TH_PLAT_WINDOWS define for #ifdef logic.
Matti Hamalainen <ccr@tnsp.org>
parents: 190
diff changeset
30 # endif
cc5411cb85de Use TH_PLAT_WINDOWS define for #ifdef logic.
Matti Hamalainen <ccr@tnsp.org>
parents: 190
diff changeset
31 # include <arpa/inet.h>
cc5411cb85de Use TH_PLAT_WINDOWS define for #ifdef logic.
Matti Hamalainen <ccr@tnsp.org>
parents: 190
diff changeset
32 # include <netdb.h>
102
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
33 #endif
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
34
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
35
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
36 #ifdef __cplusplus
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
37 extern "C" {
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
38 #endif
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
39
189
2d2a3ed27684 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 144
diff changeset
40
102
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
41 /* Global defines
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
42 */
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
43 #define TH_CONNBUF_SIZE (64 * 1024)
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
44 #define TH_DELAY_USEC (15 * 1000)
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
45 #define TH_DUMP_BYTES 16
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
46
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
47
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
48 enum
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
49 {
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
50 TH_CONN_UNINIT = 0,
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
51 TH_CONN_PROXY_NEG,
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
52 TH_CONN_OPEN,
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
53 TH_CONN_CLOSED,
441
2991e6b52d95 Get rid of trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 432
diff changeset
54
102
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
55 TH_CONN_ERROR,
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
56 TH_CONN_DATA_AVAIL,
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
57 TH_CONN_NO_DATA,
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
58 };
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
59
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
60 enum
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
61 {
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
62 TH_PROXY_NONE = 0,
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
63 TH_PROXY_SOCKS4,
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
64 TH_PROXY_SOCKS4A,
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
65 TH_PROXY_SOCKS5,
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
66
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
67 TH_PROXY_LAST
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
68 };
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
69
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
70 enum
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
71 {
121
8c39e8e90dbd More work on proxy handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 117
diff changeset
72 TH_PROXY_ADDR_IPV4 = 0,
8c39e8e90dbd More work on proxy handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 117
diff changeset
73 TH_PROXY_ADDR_DOMAIN,
8c39e8e90dbd More work on proxy handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 117
diff changeset
74 TH_PROXY_ADDR_IPV6,
8c39e8e90dbd More work on proxy handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 117
diff changeset
75 };
8c39e8e90dbd More work on proxy handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 117
diff changeset
76
8c39e8e90dbd More work on proxy handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 117
diff changeset
77 enum
8c39e8e90dbd More work on proxy handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 117
diff changeset
78 {
102
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
79 TH_PROXY_AUTH_NONE,
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
80 TH_PROXY_AUTH_USER,
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
81 };
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
82
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
83 enum
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
84 {
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
85 TH_PROXY_CMD_CONNECT = 1,
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
86 TH_PROXY_CMD_BIND = 2,
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
87 TH_PROXY_CMD_ASSOC_UDP = 3,
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
88 };
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
89
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
90
653
3c9205d52376 Doxygen fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 577
diff changeset
91 typedef struct
102
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
92 {
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
93 // Target host data
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
94 char *host;
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
95 struct hostent *hst;
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
96 int port;
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
97
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
98 // Socket data
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
99 int socket;
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
100 struct in_addr addr;
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
101 fd_set sockfds;
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
102
132
11fa2bf90251 Network API changes due to preparation for fixes in proxy support.
Matti Hamalainen <ccr@tnsp.org>
parents: 129
diff changeset
103 // Data buffer
11fa2bf90251 Network API changes due to preparation for fixes in proxy support.
Matti Hamalainen <ccr@tnsp.org>
parents: 129
diff changeset
104 char *buf, *ptr, *in_ptr;
11fa2bf90251 Network API changes due to preparation for fixes in proxy support.
Matti Hamalainen <ccr@tnsp.org>
parents: 129
diff changeset
105 ssize_t bufsize, got_bytes, total_bytes;
11fa2bf90251 Network API changes due to preparation for fixes in proxy support.
Matti Hamalainen <ccr@tnsp.org>
parents: 129
diff changeset
106
11fa2bf90251 Network API changes due to preparation for fixes in proxy support.
Matti Hamalainen <ccr@tnsp.org>
parents: 129
diff changeset
107 } th_base_conn_t;
11fa2bf90251 Network API changes due to preparation for fixes in proxy support.
Matti Hamalainen <ccr@tnsp.org>
parents: 129
diff changeset
108
11fa2bf90251 Network API changes due to preparation for fixes in proxy support.
Matti Hamalainen <ccr@tnsp.org>
parents: 129
diff changeset
109
653
3c9205d52376 Doxygen fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 577
diff changeset
110 typedef struct th_conn_t
132
11fa2bf90251 Network API changes due to preparation for fixes in proxy support.
Matti Hamalainen <ccr@tnsp.org>
parents: 129
diff changeset
111 {
11fa2bf90251 Network API changes due to preparation for fixes in proxy support.
Matti Hamalainen <ccr@tnsp.org>
parents: 129
diff changeset
112 // Connection
11fa2bf90251 Network API changes due to preparation for fixes in proxy support.
Matti Hamalainen <ccr@tnsp.org>
parents: 129
diff changeset
113 th_base_conn_t base;
11fa2bf90251 Network API changes due to preparation for fixes in proxy support.
Matti Hamalainen <ccr@tnsp.org>
parents: 129
diff changeset
114
11fa2bf90251 Network API changes due to preparation for fixes in proxy support.
Matti Hamalainen <ccr@tnsp.org>
parents: 129
diff changeset
115 // Proxy settings and data
11fa2bf90251 Network API changes due to preparation for fixes in proxy support.
Matti Hamalainen <ccr@tnsp.org>
parents: 129
diff changeset
116 struct
11fa2bf90251 Network API changes due to preparation for fixes in proxy support.
Matti Hamalainen <ccr@tnsp.org>
parents: 129
diff changeset
117 {
11fa2bf90251 Network API changes due to preparation for fixes in proxy support.
Matti Hamalainen <ccr@tnsp.org>
parents: 129
diff changeset
118 th_base_conn_t conn;
11fa2bf90251 Network API changes due to preparation for fixes in proxy support.
Matti Hamalainen <ccr@tnsp.org>
parents: 129
diff changeset
119 int type, auth_type;
11fa2bf90251 Network API changes due to preparation for fixes in proxy support.
Matti Hamalainen <ccr@tnsp.org>
parents: 129
diff changeset
120 int mode, addr_type;
11fa2bf90251 Network API changes due to preparation for fixes in proxy support.
Matti Hamalainen <ccr@tnsp.org>
parents: 129
diff changeset
121 char *userid, *passwd;
11fa2bf90251 Network API changes due to preparation for fixes in proxy support.
Matti Hamalainen <ccr@tnsp.org>
parents: 129
diff changeset
122 } proxy;
11fa2bf90251 Network API changes due to preparation for fixes in proxy support.
Matti Hamalainen <ccr@tnsp.org>
parents: 129
diff changeset
123
11fa2bf90251 Network API changes due to preparation for fixes in proxy support.
Matti Hamalainen <ccr@tnsp.org>
parents: 129
diff changeset
124 // Status
11fa2bf90251 Network API changes due to preparation for fixes in proxy support.
Matti Hamalainen <ccr@tnsp.org>
parents: 129
diff changeset
125 int err;
11fa2bf90251 Network API changes due to preparation for fixes in proxy support.
Matti Hamalainen <ccr@tnsp.org>
parents: 129
diff changeset
126 int status;
11fa2bf90251 Network API changes due to preparation for fixes in proxy support.
Matti Hamalainen <ccr@tnsp.org>
parents: 129
diff changeset
127
102
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
128 // Error handling and status message functors
653
3c9205d52376 Doxygen fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 577
diff changeset
129 void (*errfunc)(struct th_conn_t *conn, int err, const char *msg);
3c9205d52376 Doxygen fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 577
diff changeset
130 void (*msgfunc)(struct th_conn_t *conn, int loglevel, const char *msg);
102
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
131
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
132 void *node;
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
133 } th_conn_t;
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
134
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
135
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
136 int th_network_init();
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
137 void th_network_close(void);
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
138
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
139 struct hostent *th_resolve_host(th_conn_t *conn, const char *name);
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
140 th_conn_t * th_conn_new(
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
141 void (*errfunc)(th_conn_t *conn, int err, const char *msg),
103
f7bec3f7181d Change connection creation API to specify incoming buffer size.
Matti Hamalainen <ccr@tnsp.org>
parents: 102
diff changeset
142 void (*msgfunc)(th_conn_t *conn, int loglevel, const char *msg),
f7bec3f7181d Change connection creation API to specify incoming buffer size.
Matti Hamalainen <ccr@tnsp.org>
parents: 102
diff changeset
143 ssize_t bufsize);
102
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
144
570
262411458cde Add __attribute__(__format__ ..) specifiers for functions that use printf() style format specifiers.
Matti Hamalainen <ccr@tnsp.org>
parents: 553
diff changeset
145 void th_conn_err(th_conn_t *conn, int err, const char *fmt, ...)
577
70d44ba005ac Define a helper macro for __attribute__ ((__format__ (__printf__, 2, 3)))
Matti Hamalainen <ccr@tnsp.org>
parents: 570
diff changeset
146 TH_ATTR_PRINTF_FMT(3, 4);
570
262411458cde Add __attribute__(__format__ ..) specifiers for functions that use printf() style format specifiers.
Matti Hamalainen <ccr@tnsp.org>
parents: 553
diff changeset
147 void th_conn_msg(th_conn_t *conn, int loglevel, const char *fmt, ...)
577
70d44ba005ac Define a helper macro for __attribute__ ((__format__ (__printf__, 2, 3)))
Matti Hamalainen <ccr@tnsp.org>
parents: 570
diff changeset
148 TH_ATTR_PRINTF_FMT(3, 4);
102
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
149
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
150 int th_conn_set_proxy(th_conn_t *conn, int type, int port, const char *host, int auth_type);
121
8c39e8e90dbd More work on proxy handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 117
diff changeset
151 int th_conn_set_proxy_mode(th_conn_t *conn, const int mode);
8c39e8e90dbd More work on proxy handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 117
diff changeset
152 int th_conn_set_proxy_addr_type(th_conn_t *conn, const int atype);
102
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
153 int th_conn_set_proxy_auth_user(th_conn_t *conn, const char *userid, const char *passwd);
132
11fa2bf90251 Network API changes due to preparation for fixes in proxy support.
Matti Hamalainen <ccr@tnsp.org>
parents: 129
diff changeset
154
102
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
155 int th_conn_open(th_conn_t *conn, const int port, const char *host);
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
156 int th_conn_close(th_conn_t *);
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
157 void th_conn_free(th_conn_t *);
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
158 void th_conn_reset(th_conn_t *);
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
159
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
160 int th_conn_pull(th_conn_t *);
116
bc540c5bfaf9 More work on network module.
Matti Hamalainen <ccr@tnsp.org>
parents: 105
diff changeset
161 int th_conn_send_buf(th_conn_t *, const void *buf, const size_t len);
117
bfae4758fa6f More work on network module.
Matti Hamalainen <ccr@tnsp.org>
parents: 116
diff changeset
162 int th_conn_send_growbuf(th_conn_t *, th_growbuf_t *buf);
457
85fa3d333556 Actually, revert the boolean changes .. meh.
Matti Hamalainen <ccr@tnsp.org>
parents: 454
diff changeset
163 BOOL th_conn_check(th_conn_t *);
102
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
164
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
165
457
85fa3d333556 Actually, revert the boolean changes .. meh.
Matti Hamalainen <ccr@tnsp.org>
parents: 454
diff changeset
166 BOOL th_conn_buf_check(th_conn_t *conn, size_t n);
85fa3d333556 Actually, revert the boolean changes .. meh.
Matti Hamalainen <ccr@tnsp.org>
parents: 454
diff changeset
167 BOOL th_conn_buf_skip(th_conn_t *conn, size_t n);
102
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
168 int th_conn_buf_strncmp(th_conn_t *conn, const char *str, const size_t n);
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
169 int th_conn_buf_strcmp(th_conn_t *conn, const char *str);
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
170 char * th_conn_buf_strstr(th_conn_t *conn, const char *str);
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
171
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
172 void th_conn_dump_buffer(FILE *f, th_conn_t *conn);
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
173
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
174
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
175 #ifdef __cplusplus
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
176 }
6ca407bfbeaf New TCP network module, rather simple and only useful for client applications now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
177 #endif
129
aa2d608fb3f3 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 121
diff changeset
178 #endif // TH_NETWORK_H