Example self-announcing webserver which controls a servo through a smallHTML userinterface.

Dependencies:   mbed

Committer:
dirkx
Date:
Sat Aug 14 15:56:01 2010 +0000
Revision:
0:a259777c45a3

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
dirkx 0:a259777c45a3 1 /*
dirkx 0:a259777c45a3 2 * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
dirkx 0:a259777c45a3 3 * All rights reserved.
dirkx 0:a259777c45a3 4 *
dirkx 0:a259777c45a3 5 * Redistribution and use in source and binary forms, with or without modification,
dirkx 0:a259777c45a3 6 * are permitted provided that the following conditions are met:
dirkx 0:a259777c45a3 7 *
dirkx 0:a259777c45a3 8 * 1. Redistributions of source code must retain the above copyright notice,
dirkx 0:a259777c45a3 9 * this list of conditions and the following disclaimer.
dirkx 0:a259777c45a3 10 * 2. Redistributions in binary form must reproduce the above copyright notice,
dirkx 0:a259777c45a3 11 * this list of conditions and the following disclaimer in the documentation
dirkx 0:a259777c45a3 12 * and/or other materials provided with the distribution.
dirkx 0:a259777c45a3 13 * 3. The name of the author may not be used to endorse or promote products
dirkx 0:a259777c45a3 14 * derived from this software without specific prior written permission.
dirkx 0:a259777c45a3 15 *
dirkx 0:a259777c45a3 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
dirkx 0:a259777c45a3 17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
dirkx 0:a259777c45a3 18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
dirkx 0:a259777c45a3 19 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
dirkx 0:a259777c45a3 20 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
dirkx 0:a259777c45a3 21 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
dirkx 0:a259777c45a3 22 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
dirkx 0:a259777c45a3 23 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
dirkx 0:a259777c45a3 24 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
dirkx 0:a259777c45a3 25 * OF SUCH DAMAGE.
dirkx 0:a259777c45a3 26 *
dirkx 0:a259777c45a3 27 * This file is part of the lwIP TCP/IP stack.
dirkx 0:a259777c45a3 28 *
dirkx 0:a259777c45a3 29 * Author: Adam Dunkels <adam@sics.se>
dirkx 0:a259777c45a3 30 *
dirkx 0:a259777c45a3 31 */
dirkx 0:a259777c45a3 32 #ifndef __LWIP_TCP_H__
dirkx 0:a259777c45a3 33 #define __LWIP_TCP_H__
dirkx 0:a259777c45a3 34
dirkx 0:a259777c45a3 35 #include "lwip/opt.h"
dirkx 0:a259777c45a3 36
dirkx 0:a259777c45a3 37 #if LWIP_TCP /* don't build if not configured for use in lwipopts.h */
dirkx 0:a259777c45a3 38
dirkx 0:a259777c45a3 39 #include "lwip/sys.h"
dirkx 0:a259777c45a3 40 #include "lwip/mem.h"
dirkx 0:a259777c45a3 41 #include "lwip/pbuf.h"
dirkx 0:a259777c45a3 42 #include "lwip/ip.h"
dirkx 0:a259777c45a3 43 #include "lwip/icmp.h"
dirkx 0:a259777c45a3 44 #include "lwip/err.h"
dirkx 0:a259777c45a3 45
dirkx 0:a259777c45a3 46 #ifdef __cplusplus
dirkx 0:a259777c45a3 47 extern "C" {
dirkx 0:a259777c45a3 48 #endif
dirkx 0:a259777c45a3 49
dirkx 0:a259777c45a3 50 struct tcp_pcb;
dirkx 0:a259777c45a3 51
dirkx 0:a259777c45a3 52 /** Function prototype for tcp accept callback functions. Called when a new
dirkx 0:a259777c45a3 53 * connection can be accepted on a listening pcb.
dirkx 0:a259777c45a3 54 *
dirkx 0:a259777c45a3 55 * @param arg Additional argument to pass to the callback function (@see tcp_arg())
dirkx 0:a259777c45a3 56 * @param newpcb The new connection pcb
dirkx 0:a259777c45a3 57 * @param err An error code if there has been an error accepting.
dirkx 0:a259777c45a3 58 * Only return ERR_ABRT if you have called tcp_abort from within the
dirkx 0:a259777c45a3 59 * callback function!
dirkx 0:a259777c45a3 60 */
dirkx 0:a259777c45a3 61 typedef err_t (*tcp_accept_fn)(void *arg, struct tcp_pcb *newpcb, err_t err);
dirkx 0:a259777c45a3 62
dirkx 0:a259777c45a3 63 /** Function prototype for tcp receive callback functions. Called when data has
dirkx 0:a259777c45a3 64 * been received.
dirkx 0:a259777c45a3 65 *
dirkx 0:a259777c45a3 66 * @param arg Additional argument to pass to the callback function (@see tcp_arg())
dirkx 0:a259777c45a3 67 * @param tpcb The connection pcb which received data
dirkx 0:a259777c45a3 68 * @param p The received data (or NULL when the connection has been closed!)
dirkx 0:a259777c45a3 69 * @param err An error code if there has been an error receiving
dirkx 0:a259777c45a3 70 * Only return ERR_ABRT if you have called tcp_abort from within the
dirkx 0:a259777c45a3 71 * callback function!
dirkx 0:a259777c45a3 72 */
dirkx 0:a259777c45a3 73 typedef err_t (*tcp_recv_fn)(void *arg, struct tcp_pcb *tpcb,
dirkx 0:a259777c45a3 74 struct pbuf *p, err_t err);
dirkx 0:a259777c45a3 75
dirkx 0:a259777c45a3 76 /** Function prototype for tcp sent callback functions. Called when sent data has
dirkx 0:a259777c45a3 77 * been acknowledged by the remote side. Use it to free corresponding resources.
dirkx 0:a259777c45a3 78 * This also means that the pcb has now space available to send new data.
dirkx 0:a259777c45a3 79 *
dirkx 0:a259777c45a3 80 * @param arg Additional argument to pass to the callback function (@see tcp_arg())
dirkx 0:a259777c45a3 81 * @param tpcb The connection pcb for which data has been acknowledged
dirkx 0:a259777c45a3 82 * @param len The amount of bytes acknowledged
dirkx 0:a259777c45a3 83 * @return ERR_OK: try to send some data by calling tcp_output
dirkx 0:a259777c45a3 84 * Only return ERR_ABRT if you have called tcp_abort from within the
dirkx 0:a259777c45a3 85 * callback function!
dirkx 0:a259777c45a3 86 */
dirkx 0:a259777c45a3 87 typedef err_t (*tcp_sent_fn)(void *arg, struct tcp_pcb *tpcb,
dirkx 0:a259777c45a3 88 u16_t len);
dirkx 0:a259777c45a3 89
dirkx 0:a259777c45a3 90 /** Function prototype for tcp poll callback functions. Called periodically as
dirkx 0:a259777c45a3 91 * specified by @see tcp_poll.
dirkx 0:a259777c45a3 92 *
dirkx 0:a259777c45a3 93 * @param arg Additional argument to pass to the callback function (@see tcp_arg())
dirkx 0:a259777c45a3 94 * @param tpcb tcp pcb
dirkx 0:a259777c45a3 95 * @return ERR_OK: try to send some data by calling tcp_output
dirkx 0:a259777c45a3 96 * Only return ERR_ABRT if you have called tcp_abort from within the
dirkx 0:a259777c45a3 97 * callback function!
dirkx 0:a259777c45a3 98 */
dirkx 0:a259777c45a3 99 typedef err_t (*tcp_poll_fn)(void *arg, struct tcp_pcb *tpcb);
dirkx 0:a259777c45a3 100
dirkx 0:a259777c45a3 101 /** Function prototype for tcp error callback functions. Called when the pcb
dirkx 0:a259777c45a3 102 * receives a RST or is unexpectedly closed for any other reason.
dirkx 0:a259777c45a3 103 *
dirkx 0:a259777c45a3 104 * @note The corresponding pcb is already freed when this callback is called!
dirkx 0:a259777c45a3 105 *
dirkx 0:a259777c45a3 106 * @param arg Additional argument to pass to the callback function (@see tcp_arg())
dirkx 0:a259777c45a3 107 * @param err Error code to indicate why the pcb has been closed
dirkx 0:a259777c45a3 108 * ERR_ABRT: aborted through tcp_abort or by a TCP timer
dirkx 0:a259777c45a3 109 * ERR_RST: the connection was reset by the remote host
dirkx 0:a259777c45a3 110 */
dirkx 0:a259777c45a3 111 typedef void (*tcp_err_fn)(void *arg, err_t err);
dirkx 0:a259777c45a3 112
dirkx 0:a259777c45a3 113 /** Function prototype for tcp connected callback functions. Called when a pcb
dirkx 0:a259777c45a3 114 * is connected to the remote side after initiating a connection attempt by
dirkx 0:a259777c45a3 115 * calling tcp_connect().
dirkx 0:a259777c45a3 116 *
dirkx 0:a259777c45a3 117 * @param arg Additional argument to pass to the callback function (@see tcp_arg())
dirkx 0:a259777c45a3 118 * @param tpcb The connection pcb which is connected
dirkx 0:a259777c45a3 119 * @param err An unused error code, always ERR_OK currently ;-) TODO!
dirkx 0:a259777c45a3 120 * Only return ERR_ABRT if you have called tcp_abort from within the
dirkx 0:a259777c45a3 121 * callback function!
dirkx 0:a259777c45a3 122 *
dirkx 0:a259777c45a3 123 * @note When a connection attempt fails, the error callback is currently called!
dirkx 0:a259777c45a3 124 */
dirkx 0:a259777c45a3 125 typedef err_t (*tcp_connected_fn)(void *arg, struct tcp_pcb *tpcb, err_t err);
dirkx 0:a259777c45a3 126
dirkx 0:a259777c45a3 127 enum tcp_state {
dirkx 0:a259777c45a3 128 CLOSED = 0,
dirkx 0:a259777c45a3 129 LISTEN = 1,
dirkx 0:a259777c45a3 130 SYN_SENT = 2,
dirkx 0:a259777c45a3 131 SYN_RCVD = 3,
dirkx 0:a259777c45a3 132 ESTABLISHED = 4,
dirkx 0:a259777c45a3 133 FIN_WAIT_1 = 5,
dirkx 0:a259777c45a3 134 FIN_WAIT_2 = 6,
dirkx 0:a259777c45a3 135 CLOSE_WAIT = 7,
dirkx 0:a259777c45a3 136 CLOSING = 8,
dirkx 0:a259777c45a3 137 LAST_ACK = 9,
dirkx 0:a259777c45a3 138 TIME_WAIT = 10
dirkx 0:a259777c45a3 139 };
dirkx 0:a259777c45a3 140
dirkx 0:a259777c45a3 141 #if LWIP_CALLBACK_API
dirkx 0:a259777c45a3 142 /* Function to call when a listener has been connected.
dirkx 0:a259777c45a3 143 * @param arg user-supplied argument (tcp_pcb.callback_arg)
dirkx 0:a259777c45a3 144 * @param pcb a new tcp_pcb that now is connected
dirkx 0:a259777c45a3 145 * @param err an error argument (TODO: that is current always ERR_OK?)
dirkx 0:a259777c45a3 146 * @return ERR_OK: accept the new connection,
dirkx 0:a259777c45a3 147 * any other err_t abortsthe new connection
dirkx 0:a259777c45a3 148 */
dirkx 0:a259777c45a3 149 #define DEF_ACCEPT_CALLBACK tcp_accept_fn accept;
dirkx 0:a259777c45a3 150 #else /* LWIP_CALLBACK_API */
dirkx 0:a259777c45a3 151 #define DEF_ACCEPT_CALLBACK
dirkx 0:a259777c45a3 152 #endif /* LWIP_CALLBACK_API */
dirkx 0:a259777c45a3 153
dirkx 0:a259777c45a3 154 /**
dirkx 0:a259777c45a3 155 * members common to struct tcp_pcb and struct tcp_listen_pcb
dirkx 0:a259777c45a3 156 */
dirkx 0:a259777c45a3 157 #define TCP_PCB_COMMON(type) \
dirkx 0:a259777c45a3 158 type *next; /* for the linked list */ \
dirkx 0:a259777c45a3 159 enum tcp_state state; /* TCP state */ \
dirkx 0:a259777c45a3 160 u8_t prio; \
dirkx 0:a259777c45a3 161 void *callback_arg; \
dirkx 0:a259777c45a3 162 /* the accept callback for listen- and normal pcbs, if LWIP_CALLBACK_API */ \
dirkx 0:a259777c45a3 163 DEF_ACCEPT_CALLBACK \
dirkx 0:a259777c45a3 164 /* ports are in host byte order */ \
dirkx 0:a259777c45a3 165 u16_t local_port
dirkx 0:a259777c45a3 166
dirkx 0:a259777c45a3 167
dirkx 0:a259777c45a3 168 /* the TCP protocol control block */
dirkx 0:a259777c45a3 169 struct tcp_pcb {
dirkx 0:a259777c45a3 170 /** common PCB members */
dirkx 0:a259777c45a3 171 IP_PCB;
dirkx 0:a259777c45a3 172 /** protocol specific PCB members */
dirkx 0:a259777c45a3 173 TCP_PCB_COMMON(struct tcp_pcb);
dirkx 0:a259777c45a3 174
dirkx 0:a259777c45a3 175 /* ports are in host byte order */
dirkx 0:a259777c45a3 176 u16_t remote_port;
dirkx 0:a259777c45a3 177
dirkx 0:a259777c45a3 178 u8_t flags;
dirkx 0:a259777c45a3 179 #define TF_ACK_DELAY ((u8_t)0x01U) /* Delayed ACK. */
dirkx 0:a259777c45a3 180 #define TF_ACK_NOW ((u8_t)0x02U) /* Immediate ACK. */
dirkx 0:a259777c45a3 181 #define TF_INFR ((u8_t)0x04U) /* In fast recovery. */
dirkx 0:a259777c45a3 182 #define TF_TIMESTAMP ((u8_t)0x08U) /* Timestamp option enabled */
dirkx 0:a259777c45a3 183 #define TF_RXCLOSED ((u8_t)0x10U) /* rx closed by tcp_shutdown */
dirkx 0:a259777c45a3 184 #define TF_FIN ((u8_t)0x20U) /* Connection was closed locally (FIN segment enqueued). */
dirkx 0:a259777c45a3 185 #define TF_NODELAY ((u8_t)0x40U) /* Disable Nagle algorithm */
dirkx 0:a259777c45a3 186 #define TF_NAGLEMEMERR ((u8_t)0x80U) /* nagle enabled, memerr, try to output to prevent delayed ACK to happen */
dirkx 0:a259777c45a3 187
dirkx 0:a259777c45a3 188 /* the rest of the fields are in host byte order
dirkx 0:a259777c45a3 189 as we have to do some math with them */
dirkx 0:a259777c45a3 190 /* receiver variables */
dirkx 0:a259777c45a3 191 u32_t rcv_nxt; /* next seqno expected */
dirkx 0:a259777c45a3 192 u16_t rcv_wnd; /* receiver window available */
dirkx 0:a259777c45a3 193 u16_t rcv_ann_wnd; /* receiver window to announce */
dirkx 0:a259777c45a3 194 u32_t rcv_ann_right_edge; /* announced right edge of window */
dirkx 0:a259777c45a3 195
dirkx 0:a259777c45a3 196 /* Timers */
dirkx 0:a259777c45a3 197 u32_t tmr;
dirkx 0:a259777c45a3 198 u8_t polltmr, pollinterval;
dirkx 0:a259777c45a3 199
dirkx 0:a259777c45a3 200 /* Retransmission timer. */
dirkx 0:a259777c45a3 201 s16_t rtime;
dirkx 0:a259777c45a3 202
dirkx 0:a259777c45a3 203 u16_t mss; /* maximum segment size */
dirkx 0:a259777c45a3 204
dirkx 0:a259777c45a3 205 /* RTT (round trip time) estimation variables */
dirkx 0:a259777c45a3 206 u32_t rttest; /* RTT estimate in 500ms ticks */
dirkx 0:a259777c45a3 207 u32_t rtseq; /* sequence number being timed */
dirkx 0:a259777c45a3 208 s16_t sa, sv; /* @todo document this */
dirkx 0:a259777c45a3 209
dirkx 0:a259777c45a3 210 s16_t rto; /* retransmission time-out */
dirkx 0:a259777c45a3 211 u8_t nrtx; /* number of retransmissions */
dirkx 0:a259777c45a3 212
dirkx 0:a259777c45a3 213 /* fast retransmit/recovery */
dirkx 0:a259777c45a3 214 u32_t lastack; /* Highest acknowledged seqno. */
dirkx 0:a259777c45a3 215 u8_t dupacks;
dirkx 0:a259777c45a3 216
dirkx 0:a259777c45a3 217 /* congestion avoidance/control variables */
dirkx 0:a259777c45a3 218 u16_t cwnd;
dirkx 0:a259777c45a3 219 u16_t ssthresh;
dirkx 0:a259777c45a3 220
dirkx 0:a259777c45a3 221 /* sender variables */
dirkx 0:a259777c45a3 222 u32_t snd_nxt; /* next new seqno to be sent */
dirkx 0:a259777c45a3 223 u16_t snd_wnd; /* sender window */
dirkx 0:a259777c45a3 224 u32_t snd_wl1, snd_wl2; /* Sequence and acknowledgement numbers of last
dirkx 0:a259777c45a3 225 window update. */
dirkx 0:a259777c45a3 226 u32_t snd_lbb; /* Sequence number of next byte to be buffered. */
dirkx 0:a259777c45a3 227
dirkx 0:a259777c45a3 228 u16_t acked;
dirkx 0:a259777c45a3 229
dirkx 0:a259777c45a3 230 u16_t snd_buf; /* Available buffer space for sending (in bytes). */
dirkx 0:a259777c45a3 231 #define TCP_SNDQUEUELEN_OVERFLOW (0xffff-3)
dirkx 0:a259777c45a3 232 u16_t snd_queuelen; /* Available buffer space for sending (in tcp_segs). */
dirkx 0:a259777c45a3 233
dirkx 0:a259777c45a3 234 #if TCP_OVERSIZE
dirkx 0:a259777c45a3 235 /* Extra bytes available at the end of the last pbuf in unsent. */
dirkx 0:a259777c45a3 236 u16_t unsent_oversize;
dirkx 0:a259777c45a3 237 #endif /* TCP_OVERSIZE */
dirkx 0:a259777c45a3 238
dirkx 0:a259777c45a3 239 /* These are ordered by sequence number: */
dirkx 0:a259777c45a3 240 struct tcp_seg *unsent; /* Unsent (queued) segments. */
dirkx 0:a259777c45a3 241 struct tcp_seg *unacked; /* Sent but unacknowledged segments. */
dirkx 0:a259777c45a3 242 #if TCP_QUEUE_OOSEQ
dirkx 0:a259777c45a3 243 struct tcp_seg *ooseq; /* Received out of sequence segments. */
dirkx 0:a259777c45a3 244 #endif /* TCP_QUEUE_OOSEQ */
dirkx 0:a259777c45a3 245
dirkx 0:a259777c45a3 246 struct pbuf *refused_data; /* Data previously received but not yet taken by upper layer */
dirkx 0:a259777c45a3 247
dirkx 0:a259777c45a3 248 #if LWIP_CALLBACK_API
dirkx 0:a259777c45a3 249 /* Function to be called when more send buffer space is available. */
dirkx 0:a259777c45a3 250 tcp_sent_fn sent;
dirkx 0:a259777c45a3 251 /* Function to be called when (in-sequence) data has arrived. */
dirkx 0:a259777c45a3 252 tcp_recv_fn recv;
dirkx 0:a259777c45a3 253 /* Function to be called when a connection has been set up. */
dirkx 0:a259777c45a3 254 tcp_connected_fn connected;
dirkx 0:a259777c45a3 255 /* Function which is called periodically. */
dirkx 0:a259777c45a3 256 tcp_poll_fn poll;
dirkx 0:a259777c45a3 257 /* Function to be called whenever a fatal error occurs. */
dirkx 0:a259777c45a3 258 tcp_err_fn errf;
dirkx 0:a259777c45a3 259 #endif /* LWIP_CALLBACK_API */
dirkx 0:a259777c45a3 260
dirkx 0:a259777c45a3 261 #if LWIP_TCP_TIMESTAMPS
dirkx 0:a259777c45a3 262 u32_t ts_lastacksent;
dirkx 0:a259777c45a3 263 u32_t ts_recent;
dirkx 0:a259777c45a3 264 #endif /* LWIP_TCP_TIMESTAMPS */
dirkx 0:a259777c45a3 265
dirkx 0:a259777c45a3 266 /* idle time before KEEPALIVE is sent */
dirkx 0:a259777c45a3 267 u32_t keep_idle;
dirkx 0:a259777c45a3 268 #if LWIP_TCP_KEEPALIVE
dirkx 0:a259777c45a3 269 u32_t keep_intvl;
dirkx 0:a259777c45a3 270 u32_t keep_cnt;
dirkx 0:a259777c45a3 271 #endif /* LWIP_TCP_KEEPALIVE */
dirkx 0:a259777c45a3 272
dirkx 0:a259777c45a3 273 /* Persist timer counter */
dirkx 0:a259777c45a3 274 u32_t persist_cnt;
dirkx 0:a259777c45a3 275 /* Persist timer back-off */
dirkx 0:a259777c45a3 276 u8_t persist_backoff;
dirkx 0:a259777c45a3 277
dirkx 0:a259777c45a3 278 /* KEEPALIVE counter */
dirkx 0:a259777c45a3 279 u8_t keep_cnt_sent;
dirkx 0:a259777c45a3 280 };
dirkx 0:a259777c45a3 281
dirkx 0:a259777c45a3 282 struct tcp_pcb_listen {
dirkx 0:a259777c45a3 283 /* Common members of all PCB types */
dirkx 0:a259777c45a3 284 IP_PCB;
dirkx 0:a259777c45a3 285 /* Protocol specific PCB members */
dirkx 0:a259777c45a3 286 TCP_PCB_COMMON(struct tcp_pcb_listen);
dirkx 0:a259777c45a3 287
dirkx 0:a259777c45a3 288 #if TCP_LISTEN_BACKLOG
dirkx 0:a259777c45a3 289 u8_t backlog;
dirkx 0:a259777c45a3 290 u8_t accepts_pending;
dirkx 0:a259777c45a3 291 #endif /* TCP_LISTEN_BACKLOG */
dirkx 0:a259777c45a3 292 };
dirkx 0:a259777c45a3 293
dirkx 0:a259777c45a3 294 #if LWIP_EVENT_API
dirkx 0:a259777c45a3 295
dirkx 0:a259777c45a3 296 enum lwip_event {
dirkx 0:a259777c45a3 297 LWIP_EVENT_ACCEPT,
dirkx 0:a259777c45a3 298 LWIP_EVENT_SENT,
dirkx 0:a259777c45a3 299 LWIP_EVENT_RECV,
dirkx 0:a259777c45a3 300 LWIP_EVENT_CONNECTED,
dirkx 0:a259777c45a3 301 LWIP_EVENT_POLL,
dirkx 0:a259777c45a3 302 LWIP_EVENT_ERR
dirkx 0:a259777c45a3 303 };
dirkx 0:a259777c45a3 304
dirkx 0:a259777c45a3 305 err_t lwip_tcp_event(void *arg, struct tcp_pcb *pcb,
dirkx 0:a259777c45a3 306 enum lwip_event,
dirkx 0:a259777c45a3 307 struct pbuf *p,
dirkx 0:a259777c45a3 308 u16_t size,
dirkx 0:a259777c45a3 309 err_t err);
dirkx 0:a259777c45a3 310
dirkx 0:a259777c45a3 311 #endif /* LWIP_EVENT_API */
dirkx 0:a259777c45a3 312
dirkx 0:a259777c45a3 313 /* Application program's interface: */
dirkx 0:a259777c45a3 314 struct tcp_pcb * tcp_new (void);
dirkx 0:a259777c45a3 315
dirkx 0:a259777c45a3 316 void tcp_arg (struct tcp_pcb *pcb, void *arg);
dirkx 0:a259777c45a3 317 void tcp_accept (struct tcp_pcb *pcb, tcp_accept_fn accept);
dirkx 0:a259777c45a3 318 void tcp_recv (struct tcp_pcb *pcb, tcp_recv_fn recv);
dirkx 0:a259777c45a3 319 void tcp_sent (struct tcp_pcb *pcb, tcp_sent_fn sent);
dirkx 0:a259777c45a3 320 void tcp_poll (struct tcp_pcb *pcb, tcp_poll_fn poll, u8_t interval);
dirkx 0:a259777c45a3 321 void tcp_err (struct tcp_pcb *pcb, tcp_err_fn err);
dirkx 0:a259777c45a3 322
dirkx 0:a259777c45a3 323 #define tcp_mss(pcb) (((pcb)->flags & TF_TIMESTAMP) ? ((pcb)->mss - 12) : (pcb)->mss)
dirkx 0:a259777c45a3 324 #define tcp_sndbuf(pcb) ((pcb)->snd_buf)
dirkx 0:a259777c45a3 325 #define tcp_sndqueuelen(pcb) ((pcb)->snd_queuelen)
dirkx 0:a259777c45a3 326 #define tcp_nagle_disable(pcb) ((pcb)->flags |= TF_NODELAY)
dirkx 0:a259777c45a3 327 #define tcp_nagle_enable(pcb) ((pcb)->flags &= ~TF_NODELAY)
dirkx 0:a259777c45a3 328 #define tcp_nagle_disabled(pcb) (((pcb)->flags & TF_NODELAY) != 0)
dirkx 0:a259777c45a3 329
dirkx 0:a259777c45a3 330 #if TCP_LISTEN_BACKLOG
dirkx 0:a259777c45a3 331 #define tcp_accepted(pcb) do { \
dirkx 0:a259777c45a3 332 LWIP_ASSERT("pcb->state == LISTEN (called for wrong pcb?)", pcb->state == LISTEN); \
dirkx 0:a259777c45a3 333 (((struct tcp_pcb_listen *)(pcb))->accepts_pending--); } while(0)
dirkx 0:a259777c45a3 334 #else /* TCP_LISTEN_BACKLOG */
dirkx 0:a259777c45a3 335 #define tcp_accepted(pcb) LWIP_ASSERT("pcb->state == LISTEN (called for wrong pcb?)", \
dirkx 0:a259777c45a3 336 pcb->state == LISTEN)
dirkx 0:a259777c45a3 337 #endif /* TCP_LISTEN_BACKLOG */
dirkx 0:a259777c45a3 338
dirkx 0:a259777c45a3 339 void tcp_recved (struct tcp_pcb *pcb, u16_t len);
dirkx 0:a259777c45a3 340 err_t tcp_bind (struct tcp_pcb *pcb, ip_addr_t *ipaddr,
dirkx 0:a259777c45a3 341 u16_t port);
dirkx 0:a259777c45a3 342 err_t tcp_connect (struct tcp_pcb *pcb, ip_addr_t *ipaddr,
dirkx 0:a259777c45a3 343 u16_t port, tcp_connected_fn connected);
dirkx 0:a259777c45a3 344
dirkx 0:a259777c45a3 345 struct tcp_pcb * tcp_listen_with_backlog(struct tcp_pcb *pcb, u8_t backlog);
dirkx 0:a259777c45a3 346 #define tcp_listen(pcb) tcp_listen_with_backlog(pcb, TCP_DEFAULT_LISTEN_BACKLOG)
dirkx 0:a259777c45a3 347
dirkx 0:a259777c45a3 348 void tcp_abort (struct tcp_pcb *pcb);
dirkx 0:a259777c45a3 349 err_t tcp_close (struct tcp_pcb *pcb);
dirkx 0:a259777c45a3 350 err_t tcp_shutdown(struct tcp_pcb *pcb, int shut_rx, int shut_tx);
dirkx 0:a259777c45a3 351
dirkx 0:a259777c45a3 352 /* Flags for "apiflags" parameter in tcp_write */
dirkx 0:a259777c45a3 353 #define TCP_WRITE_FLAG_COPY 0x01
dirkx 0:a259777c45a3 354 #define TCP_WRITE_FLAG_MORE 0x02
dirkx 0:a259777c45a3 355
dirkx 0:a259777c45a3 356 err_t tcp_write (struct tcp_pcb *pcb, const void *dataptr, u16_t len,
dirkx 0:a259777c45a3 357 u8_t apiflags);
dirkx 0:a259777c45a3 358
dirkx 0:a259777c45a3 359 void tcp_setprio (struct tcp_pcb *pcb, u8_t prio);
dirkx 0:a259777c45a3 360
dirkx 0:a259777c45a3 361 #define TCP_PRIO_MIN 1
dirkx 0:a259777c45a3 362 #define TCP_PRIO_NORMAL 64
dirkx 0:a259777c45a3 363 #define TCP_PRIO_MAX 127
dirkx 0:a259777c45a3 364
dirkx 0:a259777c45a3 365 err_t tcp_output (struct tcp_pcb *pcb);
dirkx 0:a259777c45a3 366
dirkx 0:a259777c45a3 367
dirkx 0:a259777c45a3 368 const char* tcp_debug_state_str(enum tcp_state s);
dirkx 0:a259777c45a3 369
dirkx 0:a259777c45a3 370
dirkx 0:a259777c45a3 371 #ifdef __cplusplus
dirkx 0:a259777c45a3 372 }
dirkx 0:a259777c45a3 373 #endif
dirkx 0:a259777c45a3 374
dirkx 0:a259777c45a3 375 #endif /* LWIP_TCP */
dirkx 0:a259777c45a3 376
dirkx 0:a259777c45a3 377 #endif /* __LWIP_TCP_H__ */