Modified version of NetServices. Fixes an issue where connections failed should the HTTP response status line be received in a packet on its own prior to any further headers. Changes are made to the HTTPClient.cpp file's readHeaders method.

Committer:
andrewbonney
Date:
Fri Apr 08 14:39:41 2011 +0000
Revision:
0:ec559500a63f

        

Who changed what in which revision?

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