Version of http://mbed.org/cookbook/NetServicesTribute with setting set the same for LPC2368

Dependents:   UDPSocketExample 24LCxx_I2CApp WeatherPlatform_pachube HvZServerLib ... more

Committer:
simon
Date:
Tue Nov 23 14:15:36 2010 +0000
Revision:
0:350011bf8be7
Experimental version for testing UDP

Who changed what in which revision?

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