Stripped down version of Segundos NetService library (http://mbed.org/users/segundo/libraries/NetServices ). I have removed all NetServices, and all functions which had been disabled. Use this version when you need only pure TCP or UDP functions - this library compiles faster.

Dependencies:   lwip lwip-sys

Dependents:   christmasLights device_server pop3demo device_server_udp ... more

Committer:
hlipka
Date:
Mon Jan 10 21:03:11 2011 +0000
Revision:
0:8b387bed54c2
initial version

Who changed what in which revision?

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