An example HTTP Server using new Ethernet Interface and localfilesystem.

Dependencies:   EthernetInterface HttpServer mbed-rpc mbed-rtos mbed

Fork of giken9_HTMLServer_Sample by Yasushi TAUCHI

Committer:
yueee_yt
Date:
Wed Mar 12 04:19:54 2014 +0000
Revision:
0:7766f6712673
???????????????

Who changed what in which revision?

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