Stripped down version of Segundos NetService library (http://mbed.org/users/segundo/libraries/NetServices ). I have removed all NetServices, and all functions which had been disabled. Use this version when you need only pure TCP or UDP functions - this library compiles faster.

Dependencies:   lwip lwip-sys

Dependents:   christmasLights device_server pop3demo device_server_udp ... more

Committer:
hlipka
Date:
Mon Jan 10 21:03:11 2011 +0000
Revision:
0:8b387bed54c2
initial version

Who changed what in which revision?

UserRevisionLine numberNew contents of line
hlipka 0:8b387bed54c2 1 /*
hlipka 0:8b387bed54c2 2 * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
hlipka 0:8b387bed54c2 3 * All rights reserved.
hlipka 0:8b387bed54c2 4 *
hlipka 0:8b387bed54c2 5 * Redistribution and use in source and binary forms, with or without modification,
hlipka 0:8b387bed54c2 6 * are permitted provided that the following conditions are met:
hlipka 0:8b387bed54c2 7 *
hlipka 0:8b387bed54c2 8 * 1. Redistributions of source code must retain the above copyright notice,
hlipka 0:8b387bed54c2 9 * this list of conditions and the following disclaimer.
hlipka 0:8b387bed54c2 10 * 2. Redistributions in binary form must reproduce the above copyright notice,
hlipka 0:8b387bed54c2 11 * this list of conditions and the following disclaimer in the documentation
hlipka 0:8b387bed54c2 12 * and/or other materials provided with the distribution.
hlipka 0:8b387bed54c2 13 * 3. The name of the author may not be used to endorse or promote products
hlipka 0:8b387bed54c2 14 * derived from this software without specific prior written permission.
hlipka 0:8b387bed54c2 15 *
hlipka 0:8b387bed54c2 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
hlipka 0:8b387bed54c2 17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
hlipka 0:8b387bed54c2 18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
hlipka 0:8b387bed54c2 19 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
hlipka 0:8b387bed54c2 20 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
hlipka 0:8b387bed54c2 21 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
hlipka 0:8b387bed54c2 22 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
hlipka 0:8b387bed54c2 23 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
hlipka 0:8b387bed54c2 24 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
hlipka 0:8b387bed54c2 25 * OF SUCH DAMAGE.
hlipka 0:8b387bed54c2 26 *
hlipka 0:8b387bed54c2 27 * This file is part of the lwIP TCP/IP stack.
hlipka 0:8b387bed54c2 28 *
hlipka 0:8b387bed54c2 29 * Author: Adam Dunkels <adam@sics.se>
hlipka 0:8b387bed54c2 30 *
hlipka 0:8b387bed54c2 31 */
hlipka 0:8b387bed54c2 32 #ifndef __LWIP_API_MSG_H__
hlipka 0:8b387bed54c2 33 #define __LWIP_API_MSG_H__
hlipka 0:8b387bed54c2 34
hlipka 0:8b387bed54c2 35 #include "lwip/opt.h"
hlipka 0:8b387bed54c2 36
hlipka 0:8b387bed54c2 37 #if LWIP_NETCONN /* don't build if not configured for use in lwipopts.h */
hlipka 0:8b387bed54c2 38
hlipka 0:8b387bed54c2 39 #include <stddef.h> /* for size_t */
hlipka 0:8b387bed54c2 40
hlipka 0:8b387bed54c2 41 #include "lwip/ip_addr.h"
hlipka 0:8b387bed54c2 42 #include "lwip/err.h"
hlipka 0:8b387bed54c2 43 #include "lwip/sys.h"
hlipka 0:8b387bed54c2 44 #include "lwip/igmp.h"
hlipka 0:8b387bed54c2 45 #include "lwip/api.h"
hlipka 0:8b387bed54c2 46
hlipka 0:8b387bed54c2 47 #ifdef __cplusplus
hlipka 0:8b387bed54c2 48 extern "C" {
hlipka 0:8b387bed54c2 49 #endif
hlipka 0:8b387bed54c2 50
hlipka 0:8b387bed54c2 51 #define NETCONN_SHUT_RD 1
hlipka 0:8b387bed54c2 52 #define NETCONN_SHUT_WR 2
hlipka 0:8b387bed54c2 53 #define NETCONN_SHUT_RDWR 3
hlipka 0:8b387bed54c2 54
hlipka 0:8b387bed54c2 55 /* IP addresses and port numbers are expected to be in
hlipka 0:8b387bed54c2 56 * the same byte order as in the corresponding pcb.
hlipka 0:8b387bed54c2 57 */
hlipka 0:8b387bed54c2 58 /** This struct includes everything that is necessary to execute a function
hlipka 0:8b387bed54c2 59 for a netconn in another thread context (mainly used to process netconns
hlipka 0:8b387bed54c2 60 in the tcpip_thread context to be thread safe). */
hlipka 0:8b387bed54c2 61 struct api_msg_msg {
hlipka 0:8b387bed54c2 62 /** The netconn which to process - always needed: it includes the semaphore
hlipka 0:8b387bed54c2 63 which is used to block the application thread until the function finished. */
hlipka 0:8b387bed54c2 64 struct netconn *conn;
hlipka 0:8b387bed54c2 65 /** The return value of the function executed in tcpip_thread. */
hlipka 0:8b387bed54c2 66 err_t err;
hlipka 0:8b387bed54c2 67 /** Depending on the executed function, one of these union members is used */
hlipka 0:8b387bed54c2 68 union {
hlipka 0:8b387bed54c2 69 /** used for do_send */
hlipka 0:8b387bed54c2 70 struct netbuf *b;
hlipka 0:8b387bed54c2 71 /** used for do_newconn */
hlipka 0:8b387bed54c2 72 struct {
hlipka 0:8b387bed54c2 73 u8_t proto;
hlipka 0:8b387bed54c2 74 } n;
hlipka 0:8b387bed54c2 75 /** used for do_bind and do_connect */
hlipka 0:8b387bed54c2 76 struct {
hlipka 0:8b387bed54c2 77 ip_addr_t *ipaddr;
hlipka 0:8b387bed54c2 78 u16_t port;
hlipka 0:8b387bed54c2 79 } bc;
hlipka 0:8b387bed54c2 80 /** used for do_getaddr */
hlipka 0:8b387bed54c2 81 struct {
hlipka 0:8b387bed54c2 82 ip_addr_t *ipaddr;
hlipka 0:8b387bed54c2 83 u16_t *port;
hlipka 0:8b387bed54c2 84 u8_t local;
hlipka 0:8b387bed54c2 85 } ad;
hlipka 0:8b387bed54c2 86 /** used for do_write */
hlipka 0:8b387bed54c2 87 struct {
hlipka 0:8b387bed54c2 88 const void *dataptr;
hlipka 0:8b387bed54c2 89 size_t len;
hlipka 0:8b387bed54c2 90 u8_t apiflags;
hlipka 0:8b387bed54c2 91 } w;
hlipka 0:8b387bed54c2 92 /** used for do_recv */
hlipka 0:8b387bed54c2 93 struct {
hlipka 0:8b387bed54c2 94 u32_t len;
hlipka 0:8b387bed54c2 95 } r;
hlipka 0:8b387bed54c2 96 /** used for do_close (/shutdown) */
hlipka 0:8b387bed54c2 97 struct {
hlipka 0:8b387bed54c2 98 u8_t shut;
hlipka 0:8b387bed54c2 99 } sd;
hlipka 0:8b387bed54c2 100 #if LWIP_IGMP
hlipka 0:8b387bed54c2 101 /** used for do_join_leave_group */
hlipka 0:8b387bed54c2 102 struct {
hlipka 0:8b387bed54c2 103 ip_addr_t *multiaddr;
hlipka 0:8b387bed54c2 104 ip_addr_t *netif_addr;
hlipka 0:8b387bed54c2 105 enum netconn_igmp join_or_leave;
hlipka 0:8b387bed54c2 106 } jl;
hlipka 0:8b387bed54c2 107 #endif /* LWIP_IGMP */
hlipka 0:8b387bed54c2 108 #if TCP_LISTEN_BACKLOG
hlipka 0:8b387bed54c2 109 struct {
hlipka 0:8b387bed54c2 110 u8_t backlog;
hlipka 0:8b387bed54c2 111 } lb;
hlipka 0:8b387bed54c2 112 #endif /* TCP_LISTEN_BACKLOG */
hlipka 0:8b387bed54c2 113 } msg;
hlipka 0:8b387bed54c2 114 };
hlipka 0:8b387bed54c2 115
hlipka 0:8b387bed54c2 116 /** This struct contains a function to execute in another thread context and
hlipka 0:8b387bed54c2 117 a struct api_msg_msg that serves as an argument for this function.
hlipka 0:8b387bed54c2 118 This is passed to tcpip_apimsg to execute functions in tcpip_thread context. */
hlipka 0:8b387bed54c2 119 struct api_msg {
hlipka 0:8b387bed54c2 120 /** function to execute in tcpip_thread context */
hlipka 0:8b387bed54c2 121 void (* function)(struct api_msg_msg *msg);
hlipka 0:8b387bed54c2 122 /** arguments for this function */
hlipka 0:8b387bed54c2 123 struct api_msg_msg msg;
hlipka 0:8b387bed54c2 124 };
hlipka 0:8b387bed54c2 125
hlipka 0:8b387bed54c2 126 #if LWIP_DNS
hlipka 0:8b387bed54c2 127 /** As do_gethostbyname requires more arguments but doesn't require a netconn,
hlipka 0:8b387bed54c2 128 it has its own struct (to avoid struct api_msg getting bigger than necessary).
hlipka 0:8b387bed54c2 129 do_gethostbyname must be called using tcpip_callback instead of tcpip_apimsg
hlipka 0:8b387bed54c2 130 (see netconn_gethostbyname). */
hlipka 0:8b387bed54c2 131 struct dns_api_msg {
hlipka 0:8b387bed54c2 132 /** Hostname to query or dotted IP address string */
hlipka 0:8b387bed54c2 133 const char *name;
hlipka 0:8b387bed54c2 134 /** Rhe resolved address is stored here */
hlipka 0:8b387bed54c2 135 ip_addr_t *addr;
hlipka 0:8b387bed54c2 136 /** This semaphore is posted when the name is resolved, the application thread
hlipka 0:8b387bed54c2 137 should wait on it. */
hlipka 0:8b387bed54c2 138 sys_sem_t *sem;
hlipka 0:8b387bed54c2 139 /** Errors are given back here */
hlipka 0:8b387bed54c2 140 err_t *err;
hlipka 0:8b387bed54c2 141 };
hlipka 0:8b387bed54c2 142 #endif /* LWIP_DNS */
hlipka 0:8b387bed54c2 143
hlipka 0:8b387bed54c2 144 void do_newconn ( struct api_msg_msg *msg);
hlipka 0:8b387bed54c2 145 void do_delconn ( struct api_msg_msg *msg);
hlipka 0:8b387bed54c2 146 void do_bind ( struct api_msg_msg *msg);
hlipka 0:8b387bed54c2 147 void do_connect ( struct api_msg_msg *msg);
hlipka 0:8b387bed54c2 148 void do_disconnect ( struct api_msg_msg *msg);
hlipka 0:8b387bed54c2 149 void do_listen ( struct api_msg_msg *msg);
hlipka 0:8b387bed54c2 150 void do_send ( struct api_msg_msg *msg);
hlipka 0:8b387bed54c2 151 void do_recv ( struct api_msg_msg *msg);
hlipka 0:8b387bed54c2 152 void do_write ( struct api_msg_msg *msg);
hlipka 0:8b387bed54c2 153 void do_getaddr ( struct api_msg_msg *msg);
hlipka 0:8b387bed54c2 154 void do_close ( struct api_msg_msg *msg);
hlipka 0:8b387bed54c2 155 void do_shutdown ( struct api_msg_msg *msg);
hlipka 0:8b387bed54c2 156 #if LWIP_IGMP
hlipka 0:8b387bed54c2 157 void do_join_leave_group( struct api_msg_msg *msg);
hlipka 0:8b387bed54c2 158 #endif /* LWIP_IGMP */
hlipka 0:8b387bed54c2 159
hlipka 0:8b387bed54c2 160 #if LWIP_DNS
hlipka 0:8b387bed54c2 161 void do_gethostbyname(void *arg);
hlipka 0:8b387bed54c2 162 #endif /* LWIP_DNS */
hlipka 0:8b387bed54c2 163
hlipka 0:8b387bed54c2 164 struct netconn* netconn_alloc(enum netconn_type t, netconn_callback callback);
hlipka 0:8b387bed54c2 165 void netconn_free(struct netconn *conn);
hlipka 0:8b387bed54c2 166
hlipka 0:8b387bed54c2 167 #ifdef __cplusplus
hlipka 0:8b387bed54c2 168 }
hlipka 0:8b387bed54c2 169 #endif
hlipka 0:8b387bed54c2 170
hlipka 0:8b387bed54c2 171 #endif /* LWIP_NETCONN */
hlipka 0:8b387bed54c2 172
hlipka 0:8b387bed54c2 173 #endif /* __LWIP_API_MSG_H__ */