I have a problem getting this to work. Server only recieves half of the data being sent. Whats wrong

Dependencies:   mbed

Committer:
tax
Date:
Tue Mar 29 13:20:15 2011 +0000
Revision:
0:66300c77c6e9

        

Who changed what in which revision?

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