Example program with HTTPServer and sensor data streaming over TCPSockets, using Donatien Garnier's Net APIs and services code on top of LWIP. Files StreamServer.h and .cpp encapsulate streaming over TCPSockets. Broadcast is done by sendToAll(), and all incoming data is echoed back to the client. Echo code can be replaced with some remote control of the streaming interface. See main() that shows how to periodically send some data to all subscribed clients. To subscribe, a client should open a socket at <mbed_ip> port 123. I used few lines in TCL code to set up a quick sink for the data. HTTP files are served on port 80 concurrently to the streaming.

Dependencies:   mbed

Committer:
iva2k
Date:
Sat Jun 12 06:01:50 2010 +0000
Revision:
0:e614f7875b60

        

Who changed what in which revision?

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