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 /*
tax 0:66300c77c6e9 3 Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com)
tax 0:66300c77c6e9 4
tax 0:66300c77c6e9 5 Permission is hereby granted, free of charge, to any person obtaining a copy
tax 0:66300c77c6e9 6 of this software and associated documentation files (the "Software"), to deal
tax 0:66300c77c6e9 7 in the Software without restriction, including without limitation the rights
tax 0:66300c77c6e9 8 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
tax 0:66300c77c6e9 9 copies of the Software, and to permit persons to whom the Software is
tax 0:66300c77c6e9 10 furnished to do so, subject to the following conditions:
tax 0:66300c77c6e9 11
tax 0:66300c77c6e9 12 The above copyright notice and this permission notice shall be included in
tax 0:66300c77c6e9 13 all copies or substantial portions of the Software.
tax 0:66300c77c6e9 14
tax 0:66300c77c6e9 15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
tax 0:66300c77c6e9 16 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
tax 0:66300c77c6e9 17 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
tax 0:66300c77c6e9 18 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
tax 0:66300c77c6e9 19 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
tax 0:66300c77c6e9 20 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
tax 0:66300c77c6e9 21 THE SOFTWARE.
tax 0:66300c77c6e9 22 */
tax 0:66300c77c6e9 23
tax 0:66300c77c6e9 24 #include "lwipNetDnsRequest.h"
tax 0:66300c77c6e9 25 #include "lwip/err.h" //err_t, ERR_xxx
tax 0:66300c77c6e9 26 #include "lwip/dns.h"
tax 0:66300c77c6e9 27
tax 0:66300c77c6e9 28 #include "netCfg.h"
tax 0:66300c77c6e9 29 #if NET_LWIP_STACK
tax 0:66300c77c6e9 30
tax 0:66300c77c6e9 31 //#define __DEBUG
tax 0:66300c77c6e9 32 #include "dbg/dbg.h"
tax 0:66300c77c6e9 33
tax 0:66300c77c6e9 34 LwipNetDnsRequest::LwipNetDnsRequest(const char* hostname) : NetDnsRequest(hostname), m_state(LWIPNETDNS_START), m_cbFired(false), m_closing(false)
tax 0:66300c77c6e9 35 {
tax 0:66300c77c6e9 36 DBG("New LwipNetDnsRequest %p\n", this);
tax 0:66300c77c6e9 37 }
tax 0:66300c77c6e9 38
tax 0:66300c77c6e9 39 LwipNetDnsRequest::LwipNetDnsRequest(Host* pHost) : NetDnsRequest(pHost), m_state(LWIPNETDNS_START), m_cbFired(false), m_closing(false)
tax 0:66300c77c6e9 40 {
tax 0:66300c77c6e9 41 DBG("New LwipNetDnsRequest %p\n", this);
tax 0:66300c77c6e9 42 }
tax 0:66300c77c6e9 43
tax 0:66300c77c6e9 44 LwipNetDnsRequest::~LwipNetDnsRequest()
tax 0:66300c77c6e9 45 {
tax 0:66300c77c6e9 46 DBG("LwipNetDnsRequest %p destroyed\n", this);
tax 0:66300c77c6e9 47 }
tax 0:66300c77c6e9 48
tax 0:66300c77c6e9 49 /*
tax 0:66300c77c6e9 50 Main useful function here (see lwip/dns.h):
tax 0:66300c77c6e9 51 err_t dns_gethostbyname(const char *hostname, ip_addr_t *addr,
tax 0:66300c77c6e9 52 dns_found_callback found, void *callback_arg);
tax 0:66300c77c6e9 53 */
tax 0:66300c77c6e9 54
tax 0:66300c77c6e9 55 //Execute request & return OK if found, NOTFOUND or ERROR on error, or PROCESSING if the request has not completed yet
tax 0:66300c77c6e9 56 void LwipNetDnsRequest::poll()
tax 0:66300c77c6e9 57 {
tax 0:66300c77c6e9 58 err_t err;
tax 0:66300c77c6e9 59 switch(m_state)
tax 0:66300c77c6e9 60 {
tax 0:66300c77c6e9 61 case LWIPNETDNS_START: //First req, let's call dns_gethostbyname
tax 0:66300c77c6e9 62 ip_addr_t ipStruct;
tax 0:66300c77c6e9 63 err = dns_gethostbyname(m_hostname, &ipStruct, LwipNetDnsRequest::sFoundCb, (void*) this );
tax 0:66300c77c6e9 64 if( err == ERR_OK )
tax 0:66300c77c6e9 65 {
tax 0:66300c77c6e9 66 m_ip = IpAddr(&ipStruct);
tax 0:66300c77c6e9 67 m_state = LWIPNETDNS_OK;
tax 0:66300c77c6e9 68 DBG("DNS: Ip found in cache.\n");
tax 0:66300c77c6e9 69 }
tax 0:66300c77c6e9 70 else if( err == ERR_INPROGRESS)
tax 0:66300c77c6e9 71 {
tax 0:66300c77c6e9 72 DBG("DNS: Processing.\n");
tax 0:66300c77c6e9 73 m_state = LWIPNETDNS_PROCESSING;
tax 0:66300c77c6e9 74 }
tax 0:66300c77c6e9 75 else //Likely ERR_VAL
tax 0:66300c77c6e9 76 {
tax 0:66300c77c6e9 77 DBG("DNS: Error on init.\n");
tax 0:66300c77c6e9 78 m_state = LWIPNETDNS_ERROR;
tax 0:66300c77c6e9 79 }
tax 0:66300c77c6e9 80 break;
tax 0:66300c77c6e9 81 case LWIPNETDNS_PROCESSING:
tax 0:66300c77c6e9 82 break; //Nothing to do, DNS is polled on interrupt
tax 0:66300c77c6e9 83 case LWIPNETDNS_OK:
tax 0:66300c77c6e9 84 if(!m_cbFired)
tax 0:66300c77c6e9 85 {
tax 0:66300c77c6e9 86 DBG("DNS: Ip found.\n");
tax 0:66300c77c6e9 87 m_cbFired = true;
tax 0:66300c77c6e9 88 onReply(NETDNS_FOUND); //Raise callback
tax 0:66300c77c6e9 89 }
tax 0:66300c77c6e9 90 break;
tax 0:66300c77c6e9 91 case LWIPNETDNS_NOTFOUND:
tax 0:66300c77c6e9 92 if(!m_cbFired)
tax 0:66300c77c6e9 93 {
tax 0:66300c77c6e9 94 DBG("DNS: could not be resolved.\n");
tax 0:66300c77c6e9 95 m_cbFired = true;
tax 0:66300c77c6e9 96 onReply(NETDNS_NOTFOUND); //Raise callback
tax 0:66300c77c6e9 97 }
tax 0:66300c77c6e9 98 break;
tax 0:66300c77c6e9 99 case LWIPNETDNS_ERROR:
tax 0:66300c77c6e9 100 default:
tax 0:66300c77c6e9 101 if(!m_cbFired)
tax 0:66300c77c6e9 102 {
tax 0:66300c77c6e9 103 DBG("DNS: Error.\n");
tax 0:66300c77c6e9 104 m_cbFired = true;
tax 0:66300c77c6e9 105 onReply(NETDNS_ERROR); //Raise callback
tax 0:66300c77c6e9 106 }
tax 0:66300c77c6e9 107 break;
tax 0:66300c77c6e9 108 }
tax 0:66300c77c6e9 109 if(m_closing && (m_state!=LWIPNETDNS_PROCESSING)) //Check wether the closure has been reqd
tax 0:66300c77c6e9 110 {
tax 0:66300c77c6e9 111 DBG("LwipNetDnsRequest: Closing in poll()\n");
tax 0:66300c77c6e9 112 NetDnsRequest::close();
tax 0:66300c77c6e9 113 }
tax 0:66300c77c6e9 114 }
tax 0:66300c77c6e9 115
tax 0:66300c77c6e9 116 void LwipNetDnsRequest::close()
tax 0:66300c77c6e9 117 {
tax 0:66300c77c6e9 118 DBG("LwipNetDnsRequest: Close req\n");
tax 0:66300c77c6e9 119 if(m_state!=LWIPNETDNS_PROCESSING)
tax 0:66300c77c6e9 120 {
tax 0:66300c77c6e9 121 DBG("LwipNetDnsRequest: Closing in close()\n");
tax 0:66300c77c6e9 122 NetDnsRequest::close();
tax 0:66300c77c6e9 123 }
tax 0:66300c77c6e9 124 else //Cannot close rightaway, waiting for callback from underlying layer
tax 0:66300c77c6e9 125 {
tax 0:66300c77c6e9 126 m_closing = true;
tax 0:66300c77c6e9 127 }
tax 0:66300c77c6e9 128 }
tax 0:66300c77c6e9 129
tax 0:66300c77c6e9 130 void LwipNetDnsRequest::foundCb(const char *name, ip_addr_t *ipaddr)
tax 0:66300c77c6e9 131 {
tax 0:66300c77c6e9 132 if( ipaddr == NULL )
tax 0:66300c77c6e9 133 {
tax 0:66300c77c6e9 134 DBG("LwipNetDnsRequest: Callback: Name not found\n");
tax 0:66300c77c6e9 135 m_state = LWIPNETDNS_NOTFOUND;
tax 0:66300c77c6e9 136 return;
tax 0:66300c77c6e9 137 }
tax 0:66300c77c6e9 138 DBG("LwipNetDnsRequest: Callback: Resolved\n");
tax 0:66300c77c6e9 139 m_ip = IpAddr(ipaddr);
tax 0:66300c77c6e9 140 m_state = LWIPNETDNS_OK;
tax 0:66300c77c6e9 141 }
tax 0:66300c77c6e9 142
tax 0:66300c77c6e9 143
tax 0:66300c77c6e9 144 void LwipNetDnsRequest::sFoundCb(const char *name, ip_addr_t *ipaddr, void *arg)
tax 0:66300c77c6e9 145 {
tax 0:66300c77c6e9 146 DBG("LwipNetDnsRequest: Static callback\n");
tax 0:66300c77c6e9 147 LwipNetDnsRequest* pMe = (LwipNetDnsRequest*) arg;
tax 0:66300c77c6e9 148 return pMe->foundCb( name, ipaddr );
tax 0:66300c77c6e9 149 }
tax 0:66300c77c6e9 150
tax 0:66300c77c6e9 151 #endif
tax 0:66300c77c6e9 152