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
andrewbonney 0:ec559500a63f 33
andrewbonney 0:ec559500a63f 34 #ifndef __LWIP_SOCKETS_H__
andrewbonney 0:ec559500a63f 35 #define __LWIP_SOCKETS_H__
andrewbonney 0:ec559500a63f 36
andrewbonney 0:ec559500a63f 37 #include "lwip/opt.h"
andrewbonney 0:ec559500a63f 38
andrewbonney 0:ec559500a63f 39 #if LWIP_SOCKET /* don't build if not configured for use in lwipopts.h */
andrewbonney 0:ec559500a63f 40
andrewbonney 0:ec559500a63f 41 #include <stddef.h> /* for size_t */
andrewbonney 0:ec559500a63f 42
andrewbonney 0:ec559500a63f 43 #include "lwip/ip_addr.h"
andrewbonney 0:ec559500a63f 44 #include "lwip/inet.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 /* members are in network byte order */
andrewbonney 0:ec559500a63f 51 struct sockaddr_in {
andrewbonney 0:ec559500a63f 52 u8_t sin_len;
andrewbonney 0:ec559500a63f 53 u8_t sin_family;
andrewbonney 0:ec559500a63f 54 u16_t sin_port;
andrewbonney 0:ec559500a63f 55 struct in_addr sin_addr;
andrewbonney 0:ec559500a63f 56 char sin_zero[8];
andrewbonney 0:ec559500a63f 57 };
andrewbonney 0:ec559500a63f 58
andrewbonney 0:ec559500a63f 59 struct sockaddr {
andrewbonney 0:ec559500a63f 60 u8_t sa_len;
andrewbonney 0:ec559500a63f 61 u8_t sa_family;
andrewbonney 0:ec559500a63f 62 u16_t sa_data[14];
andrewbonney 0:ec559500a63f 63 };
andrewbonney 0:ec559500a63f 64
andrewbonney 0:ec559500a63f 65 #ifndef socklen_t
andrewbonney 0:ec559500a63f 66 # define socklen_t u32_t
andrewbonney 0:ec559500a63f 67 #endif
andrewbonney 0:ec559500a63f 68
andrewbonney 0:ec559500a63f 69 /* Socket protocol types (TCP/UDP/RAW) */
andrewbonney 0:ec559500a63f 70 #define SOCK_STREAM 1
andrewbonney 0:ec559500a63f 71 #define SOCK_DGRAM 2
andrewbonney 0:ec559500a63f 72 #define SOCK_RAW 3
andrewbonney 0:ec559500a63f 73
andrewbonney 0:ec559500a63f 74 /*
andrewbonney 0:ec559500a63f 75 * Option flags per-socket. These must match the SOF_ flags in ip.h (checked in init.c)
andrewbonney 0:ec559500a63f 76 */
andrewbonney 0:ec559500a63f 77 #define SO_DEBUG 0x0001 /* Unimplemented: turn on debugging info recording */
andrewbonney 0:ec559500a63f 78 #define SO_ACCEPTCONN 0x0002 /* socket has had listen() */
andrewbonney 0:ec559500a63f 79 #define SO_REUSEADDR 0x0004 /* Allow local address reuse */
andrewbonney 0:ec559500a63f 80 #define SO_KEEPALIVE 0x0008 /* keep connections alive */
andrewbonney 0:ec559500a63f 81 #define SO_DONTROUTE 0x0010 /* Unimplemented: just use interface addresses */
andrewbonney 0:ec559500a63f 82 #define SO_BROADCAST 0x0020 /* permit to send and to receive broadcast messages (see IP_SOF_BROADCAST option) */
andrewbonney 0:ec559500a63f 83 #define SO_USELOOPBACK 0x0040 /* Unimplemented: bypass hardware when possible */
andrewbonney 0:ec559500a63f 84 #define SO_LINGER 0x0080 /* linger on close if data present */
andrewbonney 0:ec559500a63f 85 #define SO_OOBINLINE 0x0100 /* Unimplemented: leave received OOB data in line */
andrewbonney 0:ec559500a63f 86 #define SO_REUSEPORT 0x0200 /* Unimplemented: allow local address & port reuse */
andrewbonney 0:ec559500a63f 87
andrewbonney 0:ec559500a63f 88 #define SO_DONTLINGER ((int)(~SO_LINGER))
andrewbonney 0:ec559500a63f 89
andrewbonney 0:ec559500a63f 90 /*
andrewbonney 0:ec559500a63f 91 * Additional options, not kept in so_options.
andrewbonney 0:ec559500a63f 92 */
andrewbonney 0:ec559500a63f 93 #define SO_SNDBUF 0x1001 /* Unimplemented: send buffer size */
andrewbonney 0:ec559500a63f 94 #define SO_RCVBUF 0x1002 /* receive buffer size */
andrewbonney 0:ec559500a63f 95 #define SO_SNDLOWAT 0x1003 /* Unimplemented: send low-water mark */
andrewbonney 0:ec559500a63f 96 #define SO_RCVLOWAT 0x1004 /* Unimplemented: receive low-water mark */
andrewbonney 0:ec559500a63f 97 #define SO_SNDTIMEO 0x1005 /* Unimplemented: send timeout */
andrewbonney 0:ec559500a63f 98 #define SO_RCVTIMEO 0x1006 /* receive timeout */
andrewbonney 0:ec559500a63f 99 #define SO_ERROR 0x1007 /* get error status and clear */
andrewbonney 0:ec559500a63f 100 #define SO_TYPE 0x1008 /* get socket type */
andrewbonney 0:ec559500a63f 101 #define SO_CONTIMEO 0x1009 /* Unimplemented: connect timeout */
andrewbonney 0:ec559500a63f 102 #define SO_NO_CHECK 0x100a /* don't create UDP checksum */
andrewbonney 0:ec559500a63f 103
andrewbonney 0:ec559500a63f 104
andrewbonney 0:ec559500a63f 105 /*
andrewbonney 0:ec559500a63f 106 * Structure used for manipulating linger option.
andrewbonney 0:ec559500a63f 107 */
andrewbonney 0:ec559500a63f 108 struct linger {
andrewbonney 0:ec559500a63f 109 int l_onoff; /* option on/off */
andrewbonney 0:ec559500a63f 110 int l_linger; /* linger time */
andrewbonney 0:ec559500a63f 111 };
andrewbonney 0:ec559500a63f 112
andrewbonney 0:ec559500a63f 113 /*
andrewbonney 0:ec559500a63f 114 * Level number for (get/set)sockopt() to apply to socket itself.
andrewbonney 0:ec559500a63f 115 */
andrewbonney 0:ec559500a63f 116 #define SOL_SOCKET 0xfff /* options for socket level */
andrewbonney 0:ec559500a63f 117
andrewbonney 0:ec559500a63f 118
andrewbonney 0:ec559500a63f 119 #define AF_UNSPEC 0
andrewbonney 0:ec559500a63f 120 #define AF_INET 2
andrewbonney 0:ec559500a63f 121 #define PF_INET AF_INET
andrewbonney 0:ec559500a63f 122 #define PF_UNSPEC AF_UNSPEC
andrewbonney 0:ec559500a63f 123
andrewbonney 0:ec559500a63f 124 #define IPPROTO_IP 0
andrewbonney 0:ec559500a63f 125 #define IPPROTO_TCP 6
andrewbonney 0:ec559500a63f 126 #define IPPROTO_UDP 17
andrewbonney 0:ec559500a63f 127 #define IPPROTO_UDPLITE 136
andrewbonney 0:ec559500a63f 128
andrewbonney 0:ec559500a63f 129 /* Flags we can use with send and recv. */
andrewbonney 0:ec559500a63f 130 #define MSG_PEEK 0x01 /* Peeks at an incoming message */
andrewbonney 0:ec559500a63f 131 #define MSG_WAITALL 0x02 /* Unimplemented: Requests that the function block until the full amount of data requested can be returned */
andrewbonney 0:ec559500a63f 132 #define MSG_OOB 0x04 /* Unimplemented: Requests out-of-band data. The significance and semantics of out-of-band data are protocol-specific */
andrewbonney 0:ec559500a63f 133 #define MSG_DONTWAIT 0x08 /* Nonblocking i/o for this operation only */
andrewbonney 0:ec559500a63f 134 #define MSG_MORE 0x10 /* Sender will send more */
andrewbonney 0:ec559500a63f 135
andrewbonney 0:ec559500a63f 136
andrewbonney 0:ec559500a63f 137 /*
andrewbonney 0:ec559500a63f 138 * Options for level IPPROTO_IP
andrewbonney 0:ec559500a63f 139 */
andrewbonney 0:ec559500a63f 140 #define IP_TOS 1
andrewbonney 0:ec559500a63f 141 #define IP_TTL 2
andrewbonney 0:ec559500a63f 142
andrewbonney 0:ec559500a63f 143 #if LWIP_TCP
andrewbonney 0:ec559500a63f 144 /*
andrewbonney 0:ec559500a63f 145 * Options for level IPPROTO_TCP
andrewbonney 0:ec559500a63f 146 */
andrewbonney 0:ec559500a63f 147 #define TCP_NODELAY 0x01 /* don't delay send to coalesce packets */
andrewbonney 0:ec559500a63f 148 #define TCP_KEEPALIVE 0x02 /* send KEEPALIVE probes when idle for pcb->keep_idle milliseconds */
andrewbonney 0:ec559500a63f 149 #define TCP_KEEPIDLE 0x03 /* set pcb->keep_idle - Same as TCP_KEEPALIVE, but use seconds for get/setsockopt */
andrewbonney 0:ec559500a63f 150 #define TCP_KEEPINTVL 0x04 /* set pcb->keep_intvl - Use seconds for get/setsockopt */
andrewbonney 0:ec559500a63f 151 #define TCP_KEEPCNT 0x05 /* set pcb->keep_cnt - Use number of probes sent for get/setsockopt */
andrewbonney 0:ec559500a63f 152 #endif /* LWIP_TCP */
andrewbonney 0:ec559500a63f 153
andrewbonney 0:ec559500a63f 154 #if LWIP_UDP && LWIP_UDPLITE
andrewbonney 0:ec559500a63f 155 /*
andrewbonney 0:ec559500a63f 156 * Options for level IPPROTO_UDPLITE
andrewbonney 0:ec559500a63f 157 */
andrewbonney 0:ec559500a63f 158 #define UDPLITE_SEND_CSCOV 0x01 /* sender checksum coverage */
andrewbonney 0:ec559500a63f 159 #define UDPLITE_RECV_CSCOV 0x02 /* minimal receiver checksum coverage */
andrewbonney 0:ec559500a63f 160 #endif /* LWIP_UDP && LWIP_UDPLITE*/
andrewbonney 0:ec559500a63f 161
andrewbonney 0:ec559500a63f 162
andrewbonney 0:ec559500a63f 163 #if LWIP_IGMP
andrewbonney 0:ec559500a63f 164 /*
andrewbonney 0:ec559500a63f 165 * Options and types for UDP multicast traffic handling
andrewbonney 0:ec559500a63f 166 */
andrewbonney 0:ec559500a63f 167 #define IP_ADD_MEMBERSHIP 3
andrewbonney 0:ec559500a63f 168 #define IP_DROP_MEMBERSHIP 4
andrewbonney 0:ec559500a63f 169 #define IP_MULTICAST_TTL 5
andrewbonney 0:ec559500a63f 170 #define IP_MULTICAST_IF 6
andrewbonney 0:ec559500a63f 171 #define IP_MULTICAST_LOOP 7
andrewbonney 0:ec559500a63f 172
andrewbonney 0:ec559500a63f 173 typedef struct ip_mreq {
andrewbonney 0:ec559500a63f 174 struct in_addr imr_multiaddr; /* IP multicast address of group */
andrewbonney 0:ec559500a63f 175 struct in_addr imr_interface; /* local IP address of interface */
andrewbonney 0:ec559500a63f 176 } ip_mreq;
andrewbonney 0:ec559500a63f 177 #endif /* LWIP_IGMP */
andrewbonney 0:ec559500a63f 178
andrewbonney 0:ec559500a63f 179 /*
andrewbonney 0:ec559500a63f 180 * The Type of Service provides an indication of the abstract
andrewbonney 0:ec559500a63f 181 * parameters of the quality of service desired. These parameters are
andrewbonney 0:ec559500a63f 182 * to be used to guide the selection of the actual service parameters
andrewbonney 0:ec559500a63f 183 * when transmitting a datagram through a particular network. Several
andrewbonney 0:ec559500a63f 184 * networks offer service precedence, which somehow treats high
andrewbonney 0:ec559500a63f 185 * precedence traffic as more important than other traffic (generally
andrewbonney 0:ec559500a63f 186 * by accepting only traffic above a certain precedence at time of high
andrewbonney 0:ec559500a63f 187 * load). The major choice is a three way tradeoff between low-delay,
andrewbonney 0:ec559500a63f 188 * high-reliability, and high-throughput.
andrewbonney 0:ec559500a63f 189 * The use of the Delay, Throughput, and Reliability indications may
andrewbonney 0:ec559500a63f 190 * increase the cost (in some sense) of the service. In many networks
andrewbonney 0:ec559500a63f 191 * better performance for one of these parameters is coupled with worse
andrewbonney 0:ec559500a63f 192 * performance on another. Except for very unusual cases at most two
andrewbonney 0:ec559500a63f 193 * of these three indications should be set.
andrewbonney 0:ec559500a63f 194 */
andrewbonney 0:ec559500a63f 195 #define IPTOS_TOS_MASK 0x1E
andrewbonney 0:ec559500a63f 196 #define IPTOS_TOS(tos) ((tos) & IPTOS_TOS_MASK)
andrewbonney 0:ec559500a63f 197 #define IPTOS_LOWDELAY 0x10
andrewbonney 0:ec559500a63f 198 #define IPTOS_THROUGHPUT 0x08
andrewbonney 0:ec559500a63f 199 #define IPTOS_RELIABILITY 0x04
andrewbonney 0:ec559500a63f 200 #define IPTOS_LOWCOST 0x02
andrewbonney 0:ec559500a63f 201 #define IPTOS_MINCOST IPTOS_LOWCOST
andrewbonney 0:ec559500a63f 202
andrewbonney 0:ec559500a63f 203 /*
andrewbonney 0:ec559500a63f 204 * The Network Control precedence designation is intended to be used
andrewbonney 0:ec559500a63f 205 * within a network only. The actual use and control of that
andrewbonney 0:ec559500a63f 206 * designation is up to each network. The Internetwork Control
andrewbonney 0:ec559500a63f 207 * designation is intended for use by gateway control originators only.
andrewbonney 0:ec559500a63f 208 * If the actual use of these precedence designations is of concern to
andrewbonney 0:ec559500a63f 209 * a particular network, it is the responsibility of that network to
andrewbonney 0:ec559500a63f 210 * control the access to, and use of, those precedence designations.
andrewbonney 0:ec559500a63f 211 */
andrewbonney 0:ec559500a63f 212 #define IPTOS_PREC_MASK 0xe0
andrewbonney 0:ec559500a63f 213 #define IPTOS_PREC(tos) ((tos) & IPTOS_PREC_MASK)
andrewbonney 0:ec559500a63f 214 #define IPTOS_PREC_NETCONTROL 0xe0
andrewbonney 0:ec559500a63f 215 #define IPTOS_PREC_INTERNETCONTROL 0xc0
andrewbonney 0:ec559500a63f 216 #define IPTOS_PREC_CRITIC_ECP 0xa0
andrewbonney 0:ec559500a63f 217 #define IPTOS_PREC_FLASHOVERRIDE 0x80
andrewbonney 0:ec559500a63f 218 #define IPTOS_PREC_FLASH 0x60
andrewbonney 0:ec559500a63f 219 #define IPTOS_PREC_IMMEDIATE 0x40
andrewbonney 0:ec559500a63f 220 #define IPTOS_PREC_PRIORITY 0x20
andrewbonney 0:ec559500a63f 221 #define IPTOS_PREC_ROUTINE 0x00
andrewbonney 0:ec559500a63f 222
andrewbonney 0:ec559500a63f 223
andrewbonney 0:ec559500a63f 224 /*
andrewbonney 0:ec559500a63f 225 * Commands for ioctlsocket(), taken from the BSD file fcntl.h.
andrewbonney 0:ec559500a63f 226 * lwip_ioctl only supports FIONREAD and FIONBIO, for now
andrewbonney 0:ec559500a63f 227 *
andrewbonney 0:ec559500a63f 228 * Ioctl's have the command encoded in the lower word,
andrewbonney 0:ec559500a63f 229 * and the size of any in or out parameters in the upper
andrewbonney 0:ec559500a63f 230 * word. The high 2 bits of the upper word are used
andrewbonney 0:ec559500a63f 231 * to encode the in/out status of the parameter; for now
andrewbonney 0:ec559500a63f 232 * we restrict parameters to at most 128 bytes.
andrewbonney 0:ec559500a63f 233 */
andrewbonney 0:ec559500a63f 234 #if !defined(FIONREAD) || !defined(FIONBIO)
andrewbonney 0:ec559500a63f 235 #define IOCPARM_MASK 0x7fU /* parameters must be < 128 bytes */
andrewbonney 0:ec559500a63f 236 #define IOC_VOID 0x20000000UL /* no parameters */
andrewbonney 0:ec559500a63f 237 #define IOC_OUT 0x40000000UL /* copy out parameters */
andrewbonney 0:ec559500a63f 238 #define IOC_IN 0x80000000UL /* copy in parameters */
andrewbonney 0:ec559500a63f 239 #define IOC_INOUT (IOC_IN|IOC_OUT)
andrewbonney 0:ec559500a63f 240 /* 0x20000000 distinguishes new &
andrewbonney 0:ec559500a63f 241 old ioctl's */
andrewbonney 0:ec559500a63f 242 #define _IO(x,y) (IOC_VOID|((x)<<8)|(y))
andrewbonney 0:ec559500a63f 243
andrewbonney 0:ec559500a63f 244 #define _IOR(x,y,t) (IOC_OUT|(((long)sizeof(t)&IOCPARM_MASK)<<16)|((x)<<8)|(y))
andrewbonney 0:ec559500a63f 245
andrewbonney 0:ec559500a63f 246 #define _IOW(x,y,t) (IOC_IN|(((long)sizeof(t)&IOCPARM_MASK)<<16)|((x)<<8)|(y))
andrewbonney 0:ec559500a63f 247 #endif /* !defined(FIONREAD) || !defined(FIONBIO) */
andrewbonney 0:ec559500a63f 248
andrewbonney 0:ec559500a63f 249 #ifndef FIONREAD
andrewbonney 0:ec559500a63f 250 #define FIONREAD _IOR('f', 127, unsigned long) /* get # bytes to read */
andrewbonney 0:ec559500a63f 251 #endif
andrewbonney 0:ec559500a63f 252 #ifndef FIONBIO
andrewbonney 0:ec559500a63f 253 #define FIONBIO _IOW('f', 126, unsigned long) /* set/clear non-blocking i/o */
andrewbonney 0:ec559500a63f 254 #endif
andrewbonney 0:ec559500a63f 255
andrewbonney 0:ec559500a63f 256 /* Socket I/O Controls: unimplemented */
andrewbonney 0:ec559500a63f 257 #ifndef SIOCSHIWAT
andrewbonney 0:ec559500a63f 258 #define SIOCSHIWAT _IOW('s', 0, unsigned long) /* set high watermark */
andrewbonney 0:ec559500a63f 259 #define SIOCGHIWAT _IOR('s', 1, unsigned long) /* get high watermark */
andrewbonney 0:ec559500a63f 260 #define SIOCSLOWAT _IOW('s', 2, unsigned long) /* set low watermark */
andrewbonney 0:ec559500a63f 261 #define SIOCGLOWAT _IOR('s', 3, unsigned long) /* get low watermark */
andrewbonney 0:ec559500a63f 262 #define SIOCATMARK _IOR('s', 7, unsigned long) /* at oob mark? */
andrewbonney 0:ec559500a63f 263 #endif
andrewbonney 0:ec559500a63f 264
andrewbonney 0:ec559500a63f 265 /* commands for fnctl */
andrewbonney 0:ec559500a63f 266 #ifndef F_GETFL
andrewbonney 0:ec559500a63f 267 #define F_GETFL 3
andrewbonney 0:ec559500a63f 268 #endif
andrewbonney 0:ec559500a63f 269 #ifndef F_SETFL
andrewbonney 0:ec559500a63f 270 #define F_SETFL 4
andrewbonney 0:ec559500a63f 271 #endif
andrewbonney 0:ec559500a63f 272
andrewbonney 0:ec559500a63f 273 /* File status flags and file access modes for fnctl,
andrewbonney 0:ec559500a63f 274 these are bits in an int. */
andrewbonney 0:ec559500a63f 275 #ifndef O_NONBLOCK
andrewbonney 0:ec559500a63f 276 #define O_NONBLOCK 1 /* nonblocking I/O */
andrewbonney 0:ec559500a63f 277 #endif
andrewbonney 0:ec559500a63f 278 #ifndef O_NDELAY
andrewbonney 0:ec559500a63f 279 #define O_NDELAY 1 /* same as O_NONBLOCK, for compatibility */
andrewbonney 0:ec559500a63f 280 #endif
andrewbonney 0:ec559500a63f 281
andrewbonney 0:ec559500a63f 282 #ifndef SHUT_RD
andrewbonney 0:ec559500a63f 283 #define SHUT_RD 1
andrewbonney 0:ec559500a63f 284 #define SHUT_WR 2
andrewbonney 0:ec559500a63f 285 #define SHUT_RDWR 3
andrewbonney 0:ec559500a63f 286 #endif
andrewbonney 0:ec559500a63f 287
andrewbonney 0:ec559500a63f 288 /* FD_SET used for lwip_select */
andrewbonney 0:ec559500a63f 289 #ifndef FD_SET
andrewbonney 0:ec559500a63f 290 #undef FD_SETSIZE
andrewbonney 0:ec559500a63f 291 /* Make FD_SETSIZE match NUM_SOCKETS in socket.c */
andrewbonney 0:ec559500a63f 292 #define FD_SETSIZE MEMP_NUM_NETCONN
andrewbonney 0:ec559500a63f 293 #define FD_SET(n, p) ((p)->fd_bits[(n)/8] |= (1 << ((n) & 7)))
andrewbonney 0:ec559500a63f 294 #define FD_CLR(n, p) ((p)->fd_bits[(n)/8] &= ~(1 << ((n) & 7)))
andrewbonney 0:ec559500a63f 295 #define FD_ISSET(n,p) ((p)->fd_bits[(n)/8] & (1 << ((n) & 7)))
andrewbonney 0:ec559500a63f 296 #define FD_ZERO(p) memset((void*)(p),0,sizeof(*(p)))
andrewbonney 0:ec559500a63f 297
andrewbonney 0:ec559500a63f 298 typedef struct fd_set {
andrewbonney 0:ec559500a63f 299 unsigned char fd_bits [(FD_SETSIZE+7)/8];
andrewbonney 0:ec559500a63f 300 } fd_set;
andrewbonney 0:ec559500a63f 301
andrewbonney 0:ec559500a63f 302 #endif /* FD_SET */
andrewbonney 0:ec559500a63f 303
andrewbonney 0:ec559500a63f 304 /** LWIP_TIMEVAL_PRIVATE: if you want to use the struct timeval provided
andrewbonney 0:ec559500a63f 305 * by your system, set this to 0 and include <sys/time.h> in cc.h */
andrewbonney 0:ec559500a63f 306 #ifndef LWIP_TIMEVAL_PRIVATE
andrewbonney 0:ec559500a63f 307 #define LWIP_TIMEVAL_PRIVATE 1
andrewbonney 0:ec559500a63f 308 #endif
andrewbonney 0:ec559500a63f 309
andrewbonney 0:ec559500a63f 310 #if LWIP_TIMEVAL_PRIVATE
andrewbonney 0:ec559500a63f 311 struct timeval {
andrewbonney 0:ec559500a63f 312 long tv_sec; /* seconds */
andrewbonney 0:ec559500a63f 313 long tv_usec; /* and microseconds */
andrewbonney 0:ec559500a63f 314 };
andrewbonney 0:ec559500a63f 315 #endif /* LWIP_TIMEVAL_PRIVATE */
andrewbonney 0:ec559500a63f 316
andrewbonney 0:ec559500a63f 317 void lwip_socket_init(void);
andrewbonney 0:ec559500a63f 318
andrewbonney 0:ec559500a63f 319 int lwip_accept(int s, struct sockaddr *addr, socklen_t *addrlen);
andrewbonney 0:ec559500a63f 320 int lwip_bind(int s, const struct sockaddr *name, socklen_t namelen);
andrewbonney 0:ec559500a63f 321 int lwip_shutdown(int s, int how);
andrewbonney 0:ec559500a63f 322 int lwip_getpeername (int s, struct sockaddr *name, socklen_t *namelen);
andrewbonney 0:ec559500a63f 323 int lwip_getsockname (int s, struct sockaddr *name, socklen_t *namelen);
andrewbonney 0:ec559500a63f 324 int lwip_getsockopt (int s, int level, int optname, void *optval, socklen_t *optlen);
andrewbonney 0:ec559500a63f 325 int lwip_setsockopt (int s, int level, int optname, const void *optval, socklen_t optlen);
andrewbonney 0:ec559500a63f 326 int lwip_close(int s);
andrewbonney 0:ec559500a63f 327 int lwip_connect(int s, const struct sockaddr *name, socklen_t namelen);
andrewbonney 0:ec559500a63f 328 int lwip_listen(int s, int backlog);
andrewbonney 0:ec559500a63f 329 int lwip_recv(int s, void *mem, size_t len, int flags);
andrewbonney 0:ec559500a63f 330 int lwip_read(int s, void *mem, size_t len);
andrewbonney 0:ec559500a63f 331 int lwip_recvfrom(int s, void *mem, size_t len, int flags,
andrewbonney 0:ec559500a63f 332 struct sockaddr *from, socklen_t *fromlen);
andrewbonney 0:ec559500a63f 333 int lwip_send(int s, const void *dataptr, size_t size, int flags);
andrewbonney 0:ec559500a63f 334 int lwip_sendto(int s, const void *dataptr, size_t size, int flags,
andrewbonney 0:ec559500a63f 335 const struct sockaddr *to, socklen_t tolen);
andrewbonney 0:ec559500a63f 336 int lwip_socket(int domain, int type, int protocol);
andrewbonney 0:ec559500a63f 337 int lwip_write(int s, const void *dataptr, size_t size);
andrewbonney 0:ec559500a63f 338 int lwip_select(int maxfdp1, fd_set *readset, fd_set *writeset, fd_set *exceptset,
andrewbonney 0:ec559500a63f 339 struct timeval *timeout);
andrewbonney 0:ec559500a63f 340 int lwip_ioctl(int s, long cmd, void *argp);
andrewbonney 0:ec559500a63f 341 int lwip_fcntl(int s, int cmd, int val);
andrewbonney 0:ec559500a63f 342
andrewbonney 0:ec559500a63f 343 #if LWIP_COMPAT_SOCKETS
andrewbonney 0:ec559500a63f 344 #define accept(a,b,c) lwip_accept(a,b,c)
andrewbonney 0:ec559500a63f 345 #define bind(a,b,c) lwip_bind(a,b,c)
andrewbonney 0:ec559500a63f 346 #define shutdown(a,b) lwip_shutdown(a,b)
andrewbonney 0:ec559500a63f 347 #define closesocket(s) lwip_close(s)
andrewbonney 0:ec559500a63f 348 #define connect(a,b,c) lwip_connect(a,b,c)
andrewbonney 0:ec559500a63f 349 #define getsockname(a,b,c) lwip_getsockname(a,b,c)
andrewbonney 0:ec559500a63f 350 #define getpeername(a,b,c) lwip_getpeername(a,b,c)
andrewbonney 0:ec559500a63f 351 #define setsockopt(a,b,c,d,e) lwip_setsockopt(a,b,c,d,e)
andrewbonney 0:ec559500a63f 352 #define getsockopt(a,b,c,d,e) lwip_getsockopt(a,b,c,d,e)
andrewbonney 0:ec559500a63f 353 #define listen(a,b) lwip_listen(a,b)
andrewbonney 0:ec559500a63f 354 #define recv(a,b,c,d) lwip_recv(a,b,c,d)
andrewbonney 0:ec559500a63f 355 #define recvfrom(a,b,c,d,e,f) lwip_recvfrom(a,b,c,d,e,f)
andrewbonney 0:ec559500a63f 356 #define send(a,b,c,d) lwip_send(a,b,c,d)
andrewbonney 0:ec559500a63f 357 #define sendto(a,b,c,d,e,f) lwip_sendto(a,b,c,d,e,f)
andrewbonney 0:ec559500a63f 358 #define socket(a,b,c) lwip_socket(a,b,c)
andrewbonney 0:ec559500a63f 359 #define select(a,b,c,d,e) lwip_select(a,b,c,d,e)
andrewbonney 0:ec559500a63f 360 #define ioctlsocket(a,b,c) lwip_ioctl(a,b,c)
andrewbonney 0:ec559500a63f 361
andrewbonney 0:ec559500a63f 362 #if LWIP_POSIX_SOCKETS_IO_NAMES
andrewbonney 0:ec559500a63f 363 #define read(a,b,c) lwip_read(a,b,c)
andrewbonney 0:ec559500a63f 364 #define write(a,b,c) lwip_write(a,b,c)
andrewbonney 0:ec559500a63f 365 #define close(s) lwip_close(s)
andrewbonney 0:ec559500a63f 366 #endif /* LWIP_POSIX_SOCKETS_IO_NAMES */
andrewbonney 0:ec559500a63f 367
andrewbonney 0:ec559500a63f 368 #endif /* LWIP_COMPAT_SOCKETS */
andrewbonney 0:ec559500a63f 369
andrewbonney 0:ec559500a63f 370 #ifdef __cplusplus
andrewbonney 0:ec559500a63f 371 }
andrewbonney 0:ec559500a63f 372 #endif
andrewbonney 0:ec559500a63f 373
andrewbonney 0:ec559500a63f 374 #endif /* LWIP_SOCKET */
andrewbonney 0:ec559500a63f 375
andrewbonney 0:ec559500a63f 376 #endif /* __LWIP_SOCKETS_H__ */