ReactOS 0.4.16-dev-297-gc569aee
altcp.h
Go to the documentation of this file.
1
9/*
10 * Copyright (c) 2017 Simon Goldschmidt
11 * All rights reserved.
12 *
13 * Redistribution and use in source and binary forms, with or without modification,
14 * are permitted provided that the following conditions are met:
15 *
16 * 1. Redistributions of source code must retain the above copyright notice,
17 * this list of conditions and the following disclaimer.
18 * 2. Redistributions in binary form must reproduce the above copyright notice,
19 * this list of conditions and the following disclaimer in the documentation
20 * and/or other materials provided with the distribution.
21 * 3. The name of the author may not be used to endorse or promote products
22 * derived from this software without specific prior written permission.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
25 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
26 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
27 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
28 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
29 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
32 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
33 * OF SUCH DAMAGE.
34 *
35 * This file is part of the lwIP TCP/IP stack.
36 *
37 * Author: Simon Goldschmidt <goldsimon@gmx.de>
38 *
39 */
40#ifndef LWIP_HDR_ALTCP_H
41#define LWIP_HDR_ALTCP_H
42
43#include "lwip/opt.h"
44
45#if LWIP_ALTCP /* don't build if not configured for use in lwipopts.h */
46
47#include "lwip/tcpbase.h"
48#include "lwip/err.h"
49#include "lwip/pbuf.h"
50#include "lwip/ip_addr.h"
51
52#ifdef __cplusplus
53extern "C" {
54#endif
55
56struct altcp_pcb;
57struct altcp_functions;
58
59typedef err_t (*altcp_accept_fn)(void *arg, struct altcp_pcb *new_conn, err_t err);
60typedef err_t (*altcp_connected_fn)(void *arg, struct altcp_pcb *conn, err_t err);
61typedef err_t (*altcp_recv_fn)(void *arg, struct altcp_pcb *conn, struct pbuf *p, err_t err);
62typedef err_t (*altcp_sent_fn)(void *arg, struct altcp_pcb *conn, u16_t len);
63typedef err_t (*altcp_poll_fn)(void *arg, struct altcp_pcb *conn);
64typedef void (*altcp_err_fn)(void *arg, err_t err);
65
66typedef struct altcp_pcb* (*altcp_new_fn)(void *arg, u8_t ip_type);
67
68struct altcp_pcb {
69 const struct altcp_functions *fns;
70 struct altcp_pcb *inner_conn;
71 void *arg;
72 void *state;
73 /* application callbacks */
80 u8_t pollinterval;
81};
82
85typedef struct altcp_allocator_s {
87 altcp_new_fn alloc;
89 void *arg;
90} altcp_allocator_t;
91
92struct altcp_pcb *altcp_new(altcp_allocator_t *allocator);
93struct altcp_pcb *altcp_new_ip6(altcp_allocator_t *allocator);
94struct altcp_pcb *altcp_new_ip_type(altcp_allocator_t *allocator, u8_t ip_type);
95
96void altcp_arg(struct altcp_pcb *conn, void *arg);
98void altcp_recv(struct altcp_pcb *conn, altcp_recv_fn recv);
99void altcp_sent(struct altcp_pcb *conn, altcp_sent_fn sent);
101void altcp_err(struct altcp_pcb *conn, altcp_err_fn err);
102
103void altcp_recved(struct altcp_pcb *conn, u16_t len);
104err_t altcp_bind(struct altcp_pcb *conn, const ip_addr_t *ipaddr, u16_t port);
106
107/* return conn for source code compatibility to tcp callback API only */
108struct altcp_pcb *altcp_listen_with_backlog_and_err(struct altcp_pcb *conn, u8_t backlog, err_t *err);
109#define altcp_listen_with_backlog(conn, backlog) altcp_listen_with_backlog_and_err(conn, backlog, NULL)
111#define altcp_listen(conn) altcp_listen_with_backlog_and_err(conn, TCP_DEFAULT_LISTEN_BACKLOG, NULL)
112
113void altcp_abort(struct altcp_pcb *conn);
114err_t altcp_close(struct altcp_pcb *conn);
115err_t altcp_shutdown(struct altcp_pcb *conn, int shut_rx, int shut_tx);
116
117err_t altcp_write(struct altcp_pcb *conn, const void *dataptr, u16_t len, u8_t apiflags);
118err_t altcp_output(struct altcp_pcb *conn);
119
120u16_t altcp_mss(struct altcp_pcb *conn);
121u16_t altcp_sndbuf(struct altcp_pcb *conn);
122u16_t altcp_sndqueuelen(struct altcp_pcb *conn);
123void altcp_nagle_disable(struct altcp_pcb *conn);
124void altcp_nagle_enable(struct altcp_pcb *conn);
125int altcp_nagle_disabled(struct altcp_pcb *conn);
126
127void altcp_setprio(struct altcp_pcb *conn, u8_t prio);
128
130ip_addr_t *altcp_get_ip(struct altcp_pcb *conn, int local);
131u16_t altcp_get_port(struct altcp_pcb *conn, int local);
132
133#if LWIP_TCP_KEEPALIVE
134void altcp_keepalive_disable(struct altcp_pcb *conn);
135void altcp_keepalive_enable(struct altcp_pcb *conn, u32_t idle, u32_t intvl, u32_t count);
136#endif
137
138#ifdef LWIP_DEBUG
139enum tcp_state altcp_dbg_get_tcp_state(struct altcp_pcb *conn);
140#endif
141
142#ifdef __cplusplus
143}
144#endif
145
146#else /* LWIP_ALTCP */
147
148/* ALTCP disabled, define everything to link against tcp callback API (e.g. to get a small non-ssl httpd) */
149
150#include "lwip/tcp.h"
151
152#define altcp_accept_fn tcp_accept_fn
153#define altcp_connected_fn tcp_connected_fn
154#define altcp_recv_fn tcp_recv_fn
155#define altcp_sent_fn tcp_sent_fn
156#define altcp_poll_fn tcp_poll_fn
157#define altcp_err_fn tcp_err_fn
158
159#define altcp_pcb tcp_pcb
160#define altcp_tcp_new_ip_type tcp_new_ip_type
161#define altcp_tcp_new tcp_new
162#define altcp_tcp_new_ip6 tcp_new_ip6
163
164#define altcp_new(allocator) tcp_new()
165#define altcp_new_ip6(allocator) tcp_new_ip6()
166#define altcp_new_ip_type(allocator, ip_type) tcp_new_ip_type(ip_type)
167
168#define altcp_arg tcp_arg
169#define altcp_accept tcp_accept
170#define altcp_recv tcp_recv
171#define altcp_sent tcp_sent
172#define altcp_poll tcp_poll
173#define altcp_err tcp_err
174
175#define altcp_recved tcp_recved
176#define altcp_bind tcp_bind
177#define altcp_connect tcp_connect
178
179#define altcp_listen_with_backlog_and_err tcp_listen_with_backlog_and_err
180#define altcp_listen_with_backlog tcp_listen_with_backlog
181#define altcp_listen tcp_listen
182
183#define altcp_abort tcp_abort
184#define altcp_close tcp_close
185#define altcp_shutdown tcp_shutdown
186
187#define altcp_write tcp_write
188#define altcp_output tcp_output
189
190#define altcp_mss tcp_mss
191#define altcp_sndbuf tcp_sndbuf
192#define altcp_sndqueuelen tcp_sndqueuelen
193#define altcp_nagle_disable tcp_nagle_disable
194#define altcp_nagle_enable tcp_nagle_enable
195#define altcp_nagle_disabled tcp_nagle_disabled
196#define altcp_setprio tcp_setprio
197
198#define altcp_get_tcp_addrinfo tcp_get_tcp_addrinfo
199#define altcp_get_ip(pcb, local) ((local) ? (&(pcb)->local_ip) : (&(pcb)->remote_ip))
200
201#ifdef LWIP_DEBUG
202#define altcp_dbg_get_tcp_state tcp_dbg_get_tcp_state
203#endif
204
205#endif /* LWIP_ALTCP */
206
207#endif /* LWIP_HDR_ALTCP_H */
@ sent
Definition: SystemMenu.c:27
#define altcp_accept
Definition: altcp.h:169
#define altcp_new_ip_type(allocator, ip_type)
Definition: altcp.h:166
#define altcp_write
Definition: altcp.h:187
#define altcp_output
Definition: altcp.h:188
#define altcp_poll_fn
Definition: altcp.h:156
#define altcp_get_ip(pcb, local)
Definition: altcp.h:199
#define altcp_sndqueuelen
Definition: altcp.h:192
#define altcp_mss
Definition: altcp.h:190
#define altcp_recv_fn
Definition: altcp.h:154
#define altcp_arg
Definition: altcp.h:168
#define altcp_accept_fn
Definition: altcp.h:152
#define altcp_connect
Definition: altcp.h:177
#define altcp_sndbuf
Definition: altcp.h:191
#define altcp_shutdown
Definition: altcp.h:185
#define altcp_poll
Definition: altcp.h:172
#define altcp_err_fn
Definition: altcp.h:157
#define altcp_sent
Definition: altcp.h:171
#define altcp_nagle_enable
Definition: altcp.h:194
#define altcp_listen_with_backlog_and_err
Definition: altcp.h:179
#define altcp_nagle_disabled
Definition: altcp.h:195
#define altcp_setprio
Definition: altcp.h:196
#define altcp_nagle_disable
Definition: altcp.h:193
#define altcp_get_tcp_addrinfo
Definition: altcp.h:198
#define altcp_err
Definition: altcp.h:173
#define altcp_recv
Definition: altcp.h:170
#define altcp_pcb
Definition: altcp.h:159
#define altcp_sent_fn
Definition: altcp.h:155
#define altcp_close
Definition: altcp.h:184
#define altcp_abort
Definition: altcp.h:183
#define altcp_connected_fn
Definition: altcp.h:153
#define altcp_new(allocator)
Definition: altcp.h:164
#define altcp_recved
Definition: altcp.h:175
#define altcp_new_ip6(allocator)
Definition: altcp.h:165
#define altcp_bind
Definition: altcp.h:176
static int state
Definition: maze.c:121
void idle(int argc, const char *argv[])
Definition: cmds.c:1581
USHORT port
Definition: uri.c:228
INT WSAAPI recv(IN SOCKET s, OUT CHAR FAR *buf, IN INT len, IN INT flags)
Definition: recv.c:23
#define local
Definition: zutil.h:30
int connected
Definition: main.c:61
GLuint GLuint GLsizei count
Definition: gl.h:1545
GLenum const GLvoid * addr
Definition: glext.h:9621
GLfloat GLfloat p
Definition: glext.h:8902
GLenum GLsizei len
Definition: glext.h:6722
uint32_t u32_t
Definition: arch.h:129
uint8_t u8_t
Definition: arch.h:125
uint16_t u16_t
Definition: arch.h:127
s8_t err_t
Definition: err.h:96
ip6_addr_t ip_addr_t
Definition: ip_addr.h:344
int const JOCTET * dataptr
Definition: jpeglib.h:1031
#define err(...)
#define alloc
Definition: rosglue.h:13
SOCKET WSAAPI accept(IN SOCKET s, OUT LPSOCKADDR addr, OUT INT FAR *addrlen)
Definition: socklife.c:23
Definition: pbuf.h:186
void * arg
Definition: msvc.h:10
#define poll
Definition: wintirpc.h:59