My fork of the HTTPServer (working)

Dependents:   DGWWebServer LAN2

Committer:
screamer
Date:
Tue Nov 20 12:18:53 2012 +0000
Revision:
1:284f2df30cf9
Parent:
0:7a64fbb4069d
local changes

Who changed what in which revision?

UserRevisionLine numberNew contents of line
screamer 0:7a64fbb4069d 1 /*
screamer 0:7a64fbb4069d 2 * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
screamer 0:7a64fbb4069d 3 * All rights reserved.
screamer 0:7a64fbb4069d 4 *
screamer 0:7a64fbb4069d 5 * Redistribution and use in source and binary forms, with or without modification,
screamer 0:7a64fbb4069d 6 * are permitted provided that the following conditions are met:
screamer 0:7a64fbb4069d 7 *
screamer 0:7a64fbb4069d 8 * 1. Redistributions of source code must retain the above copyright notice,
screamer 0:7a64fbb4069d 9 * this list of conditions and the following disclaimer.
screamer 0:7a64fbb4069d 10 * 2. Redistributions in binary form must reproduce the above copyright notice,
screamer 0:7a64fbb4069d 11 * this list of conditions and the following disclaimer in the documentation
screamer 0:7a64fbb4069d 12 * and/or other materials provided with the distribution.
screamer 0:7a64fbb4069d 13 * 3. The name of the author may not be used to endorse or promote products
screamer 0:7a64fbb4069d 14 * derived from this software without specific prior written permission.
screamer 0:7a64fbb4069d 15 *
screamer 0:7a64fbb4069d 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
screamer 0:7a64fbb4069d 17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
screamer 0:7a64fbb4069d 18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
screamer 0:7a64fbb4069d 19 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
screamer 0:7a64fbb4069d 20 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
screamer 0:7a64fbb4069d 21 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
screamer 0:7a64fbb4069d 22 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
screamer 0:7a64fbb4069d 23 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
screamer 0:7a64fbb4069d 24 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
screamer 0:7a64fbb4069d 25 * OF SUCH DAMAGE.
screamer 0:7a64fbb4069d 26 *
screamer 0:7a64fbb4069d 27 * This file is part of the lwIP TCP/IP stack.
screamer 0:7a64fbb4069d 28 *
screamer 0:7a64fbb4069d 29 * Author: Adam Dunkels <adam@sics.se>
screamer 0:7a64fbb4069d 30 *
screamer 0:7a64fbb4069d 31 */
screamer 0:7a64fbb4069d 32 #ifndef __LWIP_API_H__
screamer 0:7a64fbb4069d 33 #define __LWIP_API_H__
screamer 0:7a64fbb4069d 34
screamer 0:7a64fbb4069d 35 #include "lwip/opt.h"
screamer 0:7a64fbb4069d 36
screamer 0:7a64fbb4069d 37 #if LWIP_NETCONN /* don't build if not configured for use in lwipopts.h */
screamer 0:7a64fbb4069d 38
screamer 0:7a64fbb4069d 39 #include "lwip/netbuf.h"
screamer 0:7a64fbb4069d 40 #include "lwip/sys.h"
screamer 0:7a64fbb4069d 41 #include "lwip/ip_addr.h"
screamer 0:7a64fbb4069d 42 #include "lwip/err.h"
screamer 0:7a64fbb4069d 43
screamer 0:7a64fbb4069d 44 #ifdef __cplusplus
screamer 0:7a64fbb4069d 45 extern "C" {
screamer 0:7a64fbb4069d 46 #endif
screamer 0:7a64fbb4069d 47
screamer 0:7a64fbb4069d 48 /* Throughout this file, IP addresses and port numbers are expected to be in
screamer 0:7a64fbb4069d 49 * the same byte order as in the corresponding pcb.
screamer 0:7a64fbb4069d 50 */
screamer 0:7a64fbb4069d 51
screamer 0:7a64fbb4069d 52 /* Flags for netconn_write */
screamer 0:7a64fbb4069d 53 #define NETCONN_NOFLAG 0x00
screamer 0:7a64fbb4069d 54 #define NETCONN_NOCOPY 0x00 /* Only for source code compatibility */
screamer 0:7a64fbb4069d 55 #define NETCONN_COPY 0x01
screamer 0:7a64fbb4069d 56 #define NETCONN_MORE 0x02
screamer 0:7a64fbb4069d 57
screamer 0:7a64fbb4069d 58 /* Helpers to process several netconn_types by the same code */
screamer 0:7a64fbb4069d 59 #define NETCONNTYPE_GROUP(t) (t&0xF0)
screamer 0:7a64fbb4069d 60 #define NETCONNTYPE_DATAGRAM(t) (t&0xE0)
screamer 0:7a64fbb4069d 61
screamer 0:7a64fbb4069d 62 enum netconn_type {
screamer 0:7a64fbb4069d 63 NETCONN_INVALID = 0,
screamer 0:7a64fbb4069d 64 /* NETCONN_TCP Group */
screamer 0:7a64fbb4069d 65 NETCONN_TCP = 0x10,
screamer 0:7a64fbb4069d 66 /* NETCONN_UDP Group */
screamer 0:7a64fbb4069d 67 NETCONN_UDP = 0x20,
screamer 0:7a64fbb4069d 68 NETCONN_UDPLITE = 0x21,
screamer 0:7a64fbb4069d 69 NETCONN_UDPNOCHKSUM= 0x22,
screamer 0:7a64fbb4069d 70 /* NETCONN_RAW Group */
screamer 0:7a64fbb4069d 71 NETCONN_RAW = 0x40
screamer 0:7a64fbb4069d 72 };
screamer 0:7a64fbb4069d 73
screamer 0:7a64fbb4069d 74 enum netconn_state {
screamer 0:7a64fbb4069d 75 NETCONN_NONE,
screamer 0:7a64fbb4069d 76 NETCONN_WRITE,
screamer 0:7a64fbb4069d 77 NETCONN_LISTEN,
screamer 0:7a64fbb4069d 78 NETCONN_CONNECT,
screamer 0:7a64fbb4069d 79 NETCONN_CLOSE
screamer 0:7a64fbb4069d 80 };
screamer 0:7a64fbb4069d 81
screamer 0:7a64fbb4069d 82 enum netconn_evt {
screamer 0:7a64fbb4069d 83 NETCONN_EVT_RCVPLUS,
screamer 0:7a64fbb4069d 84 NETCONN_EVT_RCVMINUS,
screamer 0:7a64fbb4069d 85 NETCONN_EVT_SENDPLUS,
screamer 0:7a64fbb4069d 86 NETCONN_EVT_SENDMINUS
screamer 0:7a64fbb4069d 87 };
screamer 0:7a64fbb4069d 88
screamer 0:7a64fbb4069d 89 #if LWIP_IGMP
screamer 0:7a64fbb4069d 90 enum netconn_igmp {
screamer 0:7a64fbb4069d 91 NETCONN_JOIN,
screamer 0:7a64fbb4069d 92 NETCONN_LEAVE
screamer 0:7a64fbb4069d 93 };
screamer 0:7a64fbb4069d 94 #endif /* LWIP_IGMP */
screamer 0:7a64fbb4069d 95
screamer 0:7a64fbb4069d 96 /* forward-declare some structs to avoid to include their headers */
screamer 0:7a64fbb4069d 97 struct ip_pcb;
screamer 0:7a64fbb4069d 98 struct tcp_pcb;
screamer 0:7a64fbb4069d 99 struct udp_pcb;
screamer 0:7a64fbb4069d 100 struct raw_pcb;
screamer 0:7a64fbb4069d 101 struct netconn;
screamer 0:7a64fbb4069d 102
screamer 0:7a64fbb4069d 103 /** A callback prototype to inform about events for a netconn */
screamer 0:7a64fbb4069d 104 typedef void (* netconn_callback)(struct netconn *, enum netconn_evt, u16_t len);
screamer 0:7a64fbb4069d 105
screamer 0:7a64fbb4069d 106 /** A netconn descriptor */
screamer 0:7a64fbb4069d 107 struct netconn {
screamer 0:7a64fbb4069d 108 /** type of the netconn (TCP, UDP or RAW) */
screamer 0:7a64fbb4069d 109 enum netconn_type type;
screamer 0:7a64fbb4069d 110 /** current state of the netconn */
screamer 0:7a64fbb4069d 111 enum netconn_state state;
screamer 0:7a64fbb4069d 112 /** the lwIP internal protocol control block */
screamer 0:7a64fbb4069d 113 union {
screamer 0:7a64fbb4069d 114 struct ip_pcb *ip;
screamer 0:7a64fbb4069d 115 struct tcp_pcb *tcp;
screamer 0:7a64fbb4069d 116 struct udp_pcb *udp;
screamer 0:7a64fbb4069d 117 struct raw_pcb *raw;
screamer 0:7a64fbb4069d 118 } pcb;
screamer 0:7a64fbb4069d 119 /** the last error this netconn had */
screamer 0:7a64fbb4069d 120 err_t err;
screamer 0:7a64fbb4069d 121 /** sem that is used to synchroneously execute functions in the core context */
screamer 0:7a64fbb4069d 122 sys_sem_t op_completed;
screamer 0:7a64fbb4069d 123 /** mbox where received packets are stored until they are fetched
screamer 0:7a64fbb4069d 124 by the netconn application thread (can grow quite big) */
screamer 0:7a64fbb4069d 125 sys_mbox_t recvmbox;
screamer 0:7a64fbb4069d 126 /** mbox where new connections are stored until processed
screamer 0:7a64fbb4069d 127 by the application thread */
screamer 0:7a64fbb4069d 128 sys_mbox_t acceptmbox;
screamer 0:7a64fbb4069d 129 /** only used for socket layer */
screamer 0:7a64fbb4069d 130 int socket;
screamer 0:7a64fbb4069d 131 #if LWIP_SO_RCVTIMEO
screamer 0:7a64fbb4069d 132 /** timeout to wait for new data to be received
screamer 0:7a64fbb4069d 133 (or connections to arrive for listening netconns) */
screamer 0:7a64fbb4069d 134 int recv_timeout;
screamer 0:7a64fbb4069d 135 #endif /* LWIP_SO_RCVTIMEO */
screamer 0:7a64fbb4069d 136 #if LWIP_SO_RCVBUF
screamer 0:7a64fbb4069d 137 /** maximum amount of bytes queued in recvmbox */
screamer 0:7a64fbb4069d 138 int recv_bufsize;
screamer 0:7a64fbb4069d 139 #endif /* LWIP_SO_RCVBUF */
screamer 0:7a64fbb4069d 140 u16_t recv_avail;
screamer 0:7a64fbb4069d 141 /** TCP: when data passed to netconn_write doesn't fit into the send buffer,
screamer 0:7a64fbb4069d 142 this temporarily stores the message. */
screamer 0:7a64fbb4069d 143 struct api_msg_msg *write_msg;
screamer 0:7a64fbb4069d 144 #if LWIP_TCP
screamer 0:7a64fbb4069d 145 /** TCP: when data passed to netconn_write doesn't fit into the send buffer,
screamer 0:7a64fbb4069d 146 this temporarily stores how much is already sent. */
screamer 0:7a64fbb4069d 147 size_t write_offset;
screamer 0:7a64fbb4069d 148 #endif /* LWIP_TCP */
screamer 0:7a64fbb4069d 149 #if LWIP_TCPIP_CORE_LOCKING
screamer 0:7a64fbb4069d 150 /** TCP: when data passed to netconn_write doesn't fit into the send buffer,
screamer 0:7a64fbb4069d 151 this temporarily stores whether to wake up the original application task
screamer 0:7a64fbb4069d 152 if data couldn't be sent in the first try. */
screamer 0:7a64fbb4069d 153 u8_t write_delayed;
screamer 0:7a64fbb4069d 154 #endif /* LWIP_TCPIP_CORE_LOCKING */
screamer 0:7a64fbb4069d 155 /** A callback function that is informed about events for this netconn */
screamer 0:7a64fbb4069d 156 netconn_callback callback;
screamer 0:7a64fbb4069d 157 };
screamer 0:7a64fbb4069d 158
screamer 0:7a64fbb4069d 159 /* Register an Network connection event */
screamer 0:7a64fbb4069d 160 #define API_EVENT(c,e,l) if (c->callback) { \
screamer 0:7a64fbb4069d 161 (*c->callback)(c, e, l); \
screamer 0:7a64fbb4069d 162 }
screamer 0:7a64fbb4069d 163
screamer 0:7a64fbb4069d 164 /* Network connection functions: */
screamer 0:7a64fbb4069d 165 #define netconn_new(t) netconn_new_with_proto_and_callback(t, 0, NULL)
screamer 0:7a64fbb4069d 166 #define netconn_new_with_callback(t, c) netconn_new_with_proto_and_callback(t, 0, c)
screamer 0:7a64fbb4069d 167 struct
screamer 0:7a64fbb4069d 168 netconn *netconn_new_with_proto_and_callback(enum netconn_type t, u8_t proto,
screamer 0:7a64fbb4069d 169 netconn_callback callback);
screamer 0:7a64fbb4069d 170 err_t netconn_delete (struct netconn *conn);
screamer 0:7a64fbb4069d 171 /** Get the type of a netconn (as enum netconn_type). */
screamer 0:7a64fbb4069d 172 #define netconn_type(conn) (conn->type)
screamer 0:7a64fbb4069d 173
screamer 0:7a64fbb4069d 174 err_t netconn_getaddr (struct netconn *conn,
screamer 0:7a64fbb4069d 175 struct ip_addr *addr,
screamer 0:7a64fbb4069d 176 u16_t *port,
screamer 0:7a64fbb4069d 177 u8_t local);
screamer 0:7a64fbb4069d 178 #define netconn_peer(c,i,p) netconn_getaddr(c,i,p,0)
screamer 0:7a64fbb4069d 179 #define netconn_addr(c,i,p) netconn_getaddr(c,i,p,1)
screamer 0:7a64fbb4069d 180
screamer 0:7a64fbb4069d 181 err_t netconn_bind (struct netconn *conn,
screamer 0:7a64fbb4069d 182 struct ip_addr *addr,
screamer 0:7a64fbb4069d 183 u16_t port);
screamer 0:7a64fbb4069d 184 err_t netconn_connect (struct netconn *conn,
screamer 0:7a64fbb4069d 185 struct ip_addr *addr,
screamer 0:7a64fbb4069d 186 u16_t port);
screamer 0:7a64fbb4069d 187 err_t netconn_disconnect (struct netconn *conn);
screamer 0:7a64fbb4069d 188 err_t netconn_listen_with_backlog(struct netconn *conn, u8_t backlog);
screamer 0:7a64fbb4069d 189 #define netconn_listen(conn) netconn_listen_with_backlog(conn, TCP_DEFAULT_LISTEN_BACKLOG)
screamer 0:7a64fbb4069d 190 struct netconn * netconn_accept (struct netconn *conn);
screamer 0:7a64fbb4069d 191 struct netbuf * netconn_recv (struct netconn *conn);
screamer 0:7a64fbb4069d 192 err_t netconn_sendto (struct netconn *conn,
screamer 0:7a64fbb4069d 193 struct netbuf *buf, struct ip_addr *addr, u16_t port);
screamer 0:7a64fbb4069d 194 err_t netconn_send (struct netconn *conn,
screamer 0:7a64fbb4069d 195 struct netbuf *buf);
screamer 0:7a64fbb4069d 196 err_t netconn_write (struct netconn *conn,
screamer 0:7a64fbb4069d 197 const void *dataptr, size_t size,
screamer 0:7a64fbb4069d 198 u8_t apiflags);
screamer 0:7a64fbb4069d 199 err_t netconn_close (struct netconn *conn);
screamer 0:7a64fbb4069d 200
screamer 0:7a64fbb4069d 201 #if LWIP_IGMP
screamer 0:7a64fbb4069d 202 err_t netconn_join_leave_group (struct netconn *conn,
screamer 0:7a64fbb4069d 203 struct ip_addr *multiaddr,
screamer 0:7a64fbb4069d 204 struct ip_addr *interface,
screamer 0:7a64fbb4069d 205 enum netconn_igmp join_or_leave);
screamer 0:7a64fbb4069d 206 #endif /* LWIP_IGMP */
screamer 0:7a64fbb4069d 207 #if LWIP_DNS
screamer 0:7a64fbb4069d 208 err_t netconn_gethostbyname(const char *name, struct ip_addr *addr);
screamer 0:7a64fbb4069d 209 #endif /* LWIP_DNS */
screamer 0:7a64fbb4069d 210
screamer 0:7a64fbb4069d 211 #define netconn_err(conn) ((conn)->err)
screamer 0:7a64fbb4069d 212 #define netconn_recv_bufsize(conn) ((conn)->recv_bufsize)
screamer 0:7a64fbb4069d 213
screamer 0:7a64fbb4069d 214 #ifdef __cplusplus
screamer 0:7a64fbb4069d 215 }
screamer 0:7a64fbb4069d 216 #endif
screamer 0:7a64fbb4069d 217
screamer 0:7a64fbb4069d 218 #endif /* LWIP_NETCONN */
screamer 0:7a64fbb4069d 219
screamer 0:7a64fbb4069d 220 #endif /* __LWIP_API_H__ */