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_MEM_H__
hlipka 0:8b387bed54c2 33 #define __LWIP_MEM_H__
hlipka 0:8b387bed54c2 34
hlipka 0:8b387bed54c2 35 #include "lwip/opt.h"
hlipka 0:8b387bed54c2 36
hlipka 0:8b387bed54c2 37 #ifdef __cplusplus
hlipka 0:8b387bed54c2 38 extern "C" {
hlipka 0:8b387bed54c2 39 #endif
hlipka 0:8b387bed54c2 40
hlipka 0:8b387bed54c2 41 #if MEM_LIBC_MALLOC
hlipka 0:8b387bed54c2 42
hlipka 0:8b387bed54c2 43 #include <stddef.h> /* for size_t */
hlipka 0:8b387bed54c2 44
hlipka 0:8b387bed54c2 45 typedef size_t mem_size_t;
hlipka 0:8b387bed54c2 46
hlipka 0:8b387bed54c2 47 /* aliases for C library malloc() */
hlipka 0:8b387bed54c2 48 #define mem_init()
hlipka 0:8b387bed54c2 49 /* in case C library malloc() needs extra protection,
hlipka 0:8b387bed54c2 50 * allow these defines to be overridden.
hlipka 0:8b387bed54c2 51 */
hlipka 0:8b387bed54c2 52 #ifndef mem_free
hlipka 0:8b387bed54c2 53 #define mem_free free
hlipka 0:8b387bed54c2 54 #endif
hlipka 0:8b387bed54c2 55 #ifndef mem_malloc
hlipka 0:8b387bed54c2 56 #define mem_malloc malloc
hlipka 0:8b387bed54c2 57 #endif
hlipka 0:8b387bed54c2 58 #ifndef mem_calloc
hlipka 0:8b387bed54c2 59 #define mem_calloc calloc
hlipka 0:8b387bed54c2 60 #endif
hlipka 0:8b387bed54c2 61 /* Since there is no C library allocation function to shrink memory without
hlipka 0:8b387bed54c2 62 moving it, define this to nothing. */
hlipka 0:8b387bed54c2 63 #ifndef mem_trim
hlipka 0:8b387bed54c2 64 #define mem_trim(mem, size) (mem)
hlipka 0:8b387bed54c2 65 #endif
hlipka 0:8b387bed54c2 66 #else /* MEM_LIBC_MALLOC */
hlipka 0:8b387bed54c2 67
hlipka 0:8b387bed54c2 68 /* MEM_SIZE would have to be aligned, but using 64000 here instead of
hlipka 0:8b387bed54c2 69 * 65535 leaves some room for alignment...
hlipka 0:8b387bed54c2 70 */
hlipka 0:8b387bed54c2 71 #if MEM_SIZE > 64000l
hlipka 0:8b387bed54c2 72 typedef u32_t mem_size_t;
hlipka 0:8b387bed54c2 73 #define MEM_SIZE_F U32_F
hlipka 0:8b387bed54c2 74 #else
hlipka 0:8b387bed54c2 75 typedef u16_t mem_size_t;
hlipka 0:8b387bed54c2 76 #define MEM_SIZE_F U16_F
hlipka 0:8b387bed54c2 77 #endif /* MEM_SIZE > 64000 */
hlipka 0:8b387bed54c2 78
hlipka 0:8b387bed54c2 79 #if MEM_USE_POOLS
hlipka 0:8b387bed54c2 80 /** mem_init is not used when using pools instead of a heap */
hlipka 0:8b387bed54c2 81 #define mem_init()
hlipka 0:8b387bed54c2 82 /** mem_trim is not used when using pools instead of a heap:
hlipka 0:8b387bed54c2 83 we can't free part of a pool element and don't want to copy the rest */
hlipka 0:8b387bed54c2 84 #define mem_trim(mem, size) (mem)
hlipka 0:8b387bed54c2 85 #else /* MEM_USE_POOLS */
hlipka 0:8b387bed54c2 86 /* lwIP alternative malloc */
hlipka 0:8b387bed54c2 87 void mem_init(void);
hlipka 0:8b387bed54c2 88 void *mem_trim(void *mem, mem_size_t size);
hlipka 0:8b387bed54c2 89 #endif /* MEM_USE_POOLS */
hlipka 0:8b387bed54c2 90 void *mem_malloc(mem_size_t size);
hlipka 0:8b387bed54c2 91 void *mem_calloc(mem_size_t count, mem_size_t size);
hlipka 0:8b387bed54c2 92 void mem_free(void *mem);
hlipka 0:8b387bed54c2 93 #endif /* MEM_LIBC_MALLOC */
hlipka 0:8b387bed54c2 94
hlipka 0:8b387bed54c2 95 /** Calculate memory size for an aligned buffer - returns the next highest
hlipka 0:8b387bed54c2 96 * multiple of MEM_ALIGNMENT (e.g. LWIP_MEM_ALIGN_SIZE(3) and
hlipka 0:8b387bed54c2 97 * LWIP_MEM_ALIGN_SIZE(4) will both yield 4 for MEM_ALIGNMENT == 4).
hlipka 0:8b387bed54c2 98 */
hlipka 0:8b387bed54c2 99 #ifndef LWIP_MEM_ALIGN_SIZE
hlipka 0:8b387bed54c2 100 #define LWIP_MEM_ALIGN_SIZE(size) (((size) + MEM_ALIGNMENT - 1) & ~(MEM_ALIGNMENT-1))
hlipka 0:8b387bed54c2 101 #endif
hlipka 0:8b387bed54c2 102
hlipka 0:8b387bed54c2 103 /** Calculate safe memory size for an aligned buffer when using an unaligned
hlipka 0:8b387bed54c2 104 * type as storage. This includes a safety-margin on (MEM_ALIGNMENT - 1) at the
hlipka 0:8b387bed54c2 105 * start (e.g. if buffer is u8_t[] and actual data will be u32_t*)
hlipka 0:8b387bed54c2 106 */
hlipka 0:8b387bed54c2 107 #ifndef LWIP_MEM_ALIGN_BUFFER
hlipka 0:8b387bed54c2 108 #define LWIP_MEM_ALIGN_BUFFER(size) (((size) + MEM_ALIGNMENT - 1))
hlipka 0:8b387bed54c2 109 #endif
hlipka 0:8b387bed54c2 110
hlipka 0:8b387bed54c2 111 /** Align a memory pointer to the alignment defined by MEM_ALIGNMENT
hlipka 0:8b387bed54c2 112 * so that ADDR % MEM_ALIGNMENT == 0
hlipka 0:8b387bed54c2 113 */
hlipka 0:8b387bed54c2 114 #ifndef LWIP_MEM_ALIGN
hlipka 0:8b387bed54c2 115 #define LWIP_MEM_ALIGN(addr) ((void *)(((mem_ptr_t)(addr) + MEM_ALIGNMENT - 1) & ~(mem_ptr_t)(MEM_ALIGNMENT-1)))
hlipka 0:8b387bed54c2 116 #endif
hlipka 0:8b387bed54c2 117
hlipka 0:8b387bed54c2 118 #ifdef __cplusplus
hlipka 0:8b387bed54c2 119 }
hlipka 0:8b387bed54c2 120 #endif
hlipka 0:8b387bed54c2 121
hlipka 0:8b387bed54c2 122 #endif /* __LWIP_MEM_H__ */