Disable UDP + DHCP + DNS to reduce the amount of memory usage

Dependents:   EthernetInterface

Fork of Socket by mbed official

Committer:
aos
Date:
Sun Feb 02 10:45:47 2014 +0000
Revision:
20:92677e486349
Parent:
17:c5089d058eab
Disabled DHCP + DNS + UDP

Who changed what in which revision?

UserRevisionLine numberNew contents of line
emilmont 16:2d471deff212 1 /* Copyright (C) 2012 mbed.org, MIT License
emilmont 16:2d471deff212 2 *
emilmont 16:2d471deff212 3 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
emilmont 16:2d471deff212 4 * and associated documentation files (the "Software"), to deal in the Software without restriction,
emilmont 16:2d471deff212 5 * including without limitation the rights to use, copy, modify, merge, publish, distribute,
emilmont 16:2d471deff212 6 * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
emilmont 16:2d471deff212 7 * furnished to do so, subject to the following conditions:
emilmont 16:2d471deff212 8 *
emilmont 16:2d471deff212 9 * The above copyright notice and this permission notice shall be included in all copies or
emilmont 16:2d471deff212 10 * substantial portions of the Software.
emilmont 16:2d471deff212 11 *
emilmont 16:2d471deff212 12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
emilmont 16:2d471deff212 13 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
emilmont 16:2d471deff212 14 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
emilmont 16:2d471deff212 15 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
emilmont 16:2d471deff212 16 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
emilmont 16:2d471deff212 17 */
emilmont 16:2d471deff212 18 #ifndef SOCKET_H_
emilmont 16:2d471deff212 19 #define SOCKET_H_
emilmont 16:2d471deff212 20
emilmont 16:2d471deff212 21 #include "lwip/sockets.h"
emilmont 16:2d471deff212 22 #include "lwip/netdb.h"
emilmont 16:2d471deff212 23
aos 20:92677e486349 24 #if LWIP_DNS
emilmont 16:2d471deff212 25 //DNS
emilmont 16:2d471deff212 26 inline struct hostent *gethostbyname(const char *name) {
emilmont 16:2d471deff212 27 return lwip_gethostbyname(name);
emilmont 16:2d471deff212 28 }
emilmont 16:2d471deff212 29
emilmont 16:2d471deff212 30 inline int gethostbyname_r(const char *name, struct hostent *ret, char *buf, size_t buflen, struct hostent **result, int *h_errnop) {
emilmont 16:2d471deff212 31 return lwip_gethostbyname_r(name, ret, buf, buflen, result, h_errnop);
emilmont 16:2d471deff212 32 }
aos 20:92677e486349 33 #endif
emilmont 16:2d471deff212 34
emilmont 16:2d471deff212 35 class TimeInterval;
emilmont 16:2d471deff212 36
emilmont 16:2d471deff212 37 /** Socket file descriptor and select wrapper
emilmont 16:2d471deff212 38 */
emilmont 16:2d471deff212 39 class Socket {
emilmont 16:2d471deff212 40 public:
emilmont 16:2d471deff212 41 /** Socket
emilmont 16:2d471deff212 42 */
emilmont 16:2d471deff212 43 Socket();
emilmont 16:2d471deff212 44
emilmont 16:2d471deff212 45 /** Set blocking or non-blocking mode of the socket and a timeout on
emilmont 16:2d471deff212 46 blocking socket operations
emilmont 16:2d471deff212 47 \param blocking true for blocking mode, false for non-blocking mode.
emilmont 16:2d471deff212 48 \param timeout timeout in ms [Default: (1500)ms].
emilmont 16:2d471deff212 49 */
emilmont 16:2d471deff212 50 void set_blocking(bool blocking, unsigned int timeout=1500);
emilmont 16:2d471deff212 51
emilmont 16:2d471deff212 52 /** Set socket options
emilmont 16:2d471deff212 53 \param level stack level (see: lwip/sockets.h)
emilmont 16:2d471deff212 54 \param optname option ID
emilmont 16:2d471deff212 55 \param optval option value
emilmont 16:2d471deff212 56 \param socklen_t length of the option value
emilmont 16:2d471deff212 57 \return 0 on success, -1 on failure
emilmont 16:2d471deff212 58 */
emilmont 16:2d471deff212 59 int set_option(int level, int optname, const void *optval, socklen_t optlen);
emilmont 16:2d471deff212 60
emilmont 16:2d471deff212 61 /** Get socket options
emilmont 16:2d471deff212 62 \param level stack level (see: lwip/sockets.h)
emilmont 16:2d471deff212 63 \param optname option ID
emilmont 16:2d471deff212 64 \param optval buffer pointer where to write the option value
emilmont 16:2d471deff212 65 \param socklen_t length of the option value
emilmont 16:2d471deff212 66 \return 0 on success, -1 on failure
emilmont 16:2d471deff212 67 */
emilmont 16:2d471deff212 68 int get_option(int level, int optname, void *optval, socklen_t *optlen);
emilmont 16:2d471deff212 69
emilmont 17:c5089d058eab 70 /** Close the socket
emilmont 17:c5089d058eab 71 \param shutdown free the left-over data in message queues
emilmont 16:2d471deff212 72 */
emilmont 17:c5089d058eab 73 int close(bool shutdown=true);
emilmont 16:2d471deff212 74
emilmont 16:2d471deff212 75 ~Socket();
emilmont 16:2d471deff212 76
emilmont 16:2d471deff212 77 protected:
emilmont 16:2d471deff212 78 int _sock_fd;
emilmont 16:2d471deff212 79 int init_socket(int type);
emilmont 16:2d471deff212 80
emilmont 16:2d471deff212 81 int wait_readable(TimeInterval& timeout);
emilmont 16:2d471deff212 82 int wait_writable(TimeInterval& timeout);
emilmont 16:2d471deff212 83
emilmont 16:2d471deff212 84 bool _blocking;
emilmont 16:2d471deff212 85 unsigned int _timeout;
emilmont 16:2d471deff212 86
emilmont 16:2d471deff212 87 private:
emilmont 16:2d471deff212 88 int select(struct timeval *timeout, bool read, bool write);
emilmont 16:2d471deff212 89 };
emilmont 16:2d471deff212 90
emilmont 16:2d471deff212 91 /** Time interval class used to specify timeouts
emilmont 16:2d471deff212 92 */
emilmont 16:2d471deff212 93 class TimeInterval {
emilmont 16:2d471deff212 94 friend class Socket;
emilmont 16:2d471deff212 95
emilmont 16:2d471deff212 96 public:
emilmont 16:2d471deff212 97 /** Time Interval
emilmont 16:2d471deff212 98 \param ms time interval expressed in milliseconds
emilmont 16:2d471deff212 99 */
emilmont 16:2d471deff212 100 TimeInterval(unsigned int ms);
emilmont 16:2d471deff212 101
emilmont 16:2d471deff212 102 private:
emilmont 16:2d471deff212 103 struct timeval _time;
emilmont 16:2d471deff212 104 };
emilmont 16:2d471deff212 105
emilmont 16:2d471deff212 106 #endif /* SOCKET_H_ */