A Simple TCP & UDP Socket Library. An update from that of Hiroshi Yamaguchi.

Committer:
macgyveremir
Date:
Wed May 23 16:26:44 2012 +0000
Revision:
0:1e4a74c2c16f
Fixed dropping of null bytes (0x00) from incoming binary TCP frames

Who changed what in which revision?

UserRevisionLine numberNew contents of line
macgyveremir 0:1e4a74c2c16f 1 /*
macgyveremir 0:1e4a74c2c16f 2 Copyright (c) 2011, Senio Networks, Inc.
macgyveremir 0:1e4a74c2c16f 3
macgyveremir 0:1e4a74c2c16f 4 Permission is hereby granted, free of charge, to any person obtaining a copy
macgyveremir 0:1e4a74c2c16f 5 of this software and associated documentation files (the "Software"), to deal
macgyveremir 0:1e4a74c2c16f 6 in the Software without restriction, including without limitation the rights
macgyveremir 0:1e4a74c2c16f 7 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
macgyveremir 0:1e4a74c2c16f 8 copies of the Software, and to permit persons to whom the Software is
macgyveremir 0:1e4a74c2c16f 9 furnished to do so, subject to the following conditions:
macgyveremir 0:1e4a74c2c16f 10
macgyveremir 0:1e4a74c2c16f 11 The above copyright notice and this permission notice shall be included in
macgyveremir 0:1e4a74c2c16f 12 all copies or substantial portions of the Software.
macgyveremir 0:1e4a74c2c16f 13
macgyveremir 0:1e4a74c2c16f 14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
macgyveremir 0:1e4a74c2c16f 15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
macgyveremir 0:1e4a74c2c16f 16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
macgyveremir 0:1e4a74c2c16f 17 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
macgyveremir 0:1e4a74c2c16f 18 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
macgyveremir 0:1e4a74c2c16f 19 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
macgyveremir 0:1e4a74c2c16f 20 THE SOFTWARE.
macgyveremir 0:1e4a74c2c16f 21 */
macgyveremir 0:1e4a74c2c16f 22
macgyveremir 0:1e4a74c2c16f 23 #include "SimpleSocket.h"
macgyveremir 0:1e4a74c2c16f 24
macgyveremir 0:1e4a74c2c16f 25 Resolver::Resolver() {}
macgyveremir 0:1e4a74c2c16f 26
macgyveremir 0:1e4a74c2c16f 27 IpAddr Resolver::resolve(char *name, bool debug) {
macgyveremir 0:1e4a74c2c16f 28 IpAddr ip;
macgyveremir 0:1e4a74c2c16f 29 DNSRequest request;
macgyveremir 0:1e4a74c2c16f 30
macgyveremir 0:1e4a74c2c16f 31 if (request.resolve(name) == DNS_OK) {
macgyveremir 0:1e4a74c2c16f 32 replied = false;
macgyveremir 0:1e4a74c2c16f 33 request.setOnReply(this, &Resolver::onReply);
macgyveremir 0:1e4a74c2c16f 34 while (!replied)
macgyveremir 0:1e4a74c2c16f 35 Net::poll();
macgyveremir 0:1e4a74c2c16f 36 if (reply == DNS_FOUND)
macgyveremir 0:1e4a74c2c16f 37 request.getResult(&ip);
macgyveremir 0:1e4a74c2c16f 38 }
macgyveremir 0:1e4a74c2c16f 39
macgyveremir 0:1e4a74c2c16f 40 DBG("%s -> %d.%d.%d.%d\n", name, ip[0], ip[1], ip[2], ip[3]);
macgyveremir 0:1e4a74c2c16f 41
macgyveremir 0:1e4a74c2c16f 42 return ip;
macgyveremir 0:1e4a74c2c16f 43 }
macgyveremir 0:1e4a74c2c16f 44
macgyveremir 0:1e4a74c2c16f 45
macgyveremir 0:1e4a74c2c16f 46 void Resolver::onReply(DNSReply reply) {
macgyveremir 0:1e4a74c2c16f 47 replied = true;
macgyveremir 0:1e4a74c2c16f 48 this->reply = reply;
macgyveremir 0:1e4a74c2c16f 49 }