TwitterExample with newer library (2012Aug)

Dependencies:   EthernetNetIf HTTPClient mbed

Committer:
nxpfan
Date:
Wed Aug 29 03:50:19 2012 +0000
Revision:
0:075157567b0c
simple twitter example with newer library

Who changed what in which revision?

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