fort Socket

Fork of Socket by mbed official

Committer:
emilmont
Date:
Wed Jul 25 14:59:37 2012 +0000
Revision:
3:e6474399e057
Child:
5:300e7ad2dc1d
Split TCPSocketServer from TCPSocketConnection

Who changed what in which revision?

UserRevisionLine numberNew contents of line
emilmont 3:e6474399e057 1 /* Copyright (C) 2012 mbed.org, MIT License
emilmont 3:e6474399e057 2 *
emilmont 3:e6474399e057 3 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
emilmont 3:e6474399e057 4 * and associated documentation files (the "Software"), to deal in the Software without restriction,
emilmont 3:e6474399e057 5 * including without limitation the rights to use, copy, modify, merge, publish, distribute,
emilmont 3:e6474399e057 6 * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
emilmont 3:e6474399e057 7 * furnished to do so, subject to the following conditions:
emilmont 3:e6474399e057 8 *
emilmont 3:e6474399e057 9 * The above copyright notice and this permission notice shall be included in all copies or
emilmont 3:e6474399e057 10 * substantial portions of the Software.
emilmont 3:e6474399e057 11 *
emilmont 3:e6474399e057 12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
emilmont 3:e6474399e057 13 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
emilmont 3:e6474399e057 14 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
emilmont 3:e6474399e057 15 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
emilmont 3:e6474399e057 16 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
emilmont 3:e6474399e057 17 */
emilmont 3:e6474399e057 18 #ifndef SOCKET_H_
emilmont 3:e6474399e057 19 #define SOCKET_H_
emilmont 3:e6474399e057 20
emilmont 3:e6474399e057 21 #include "lwip/sockets.h"
emilmont 3:e6474399e057 22 #include "lwip/netdb.h"
emilmont 3:e6474399e057 23
emilmont 3:e6474399e057 24 //DNS
emilmont 3:e6474399e057 25 inline struct hostent *gethostbyname(const char *name) {
emilmont 3:e6474399e057 26 return lwip_gethostbyname(name);
emilmont 3:e6474399e057 27 }
emilmont 3:e6474399e057 28
emilmont 3:e6474399e057 29 inline int gethostbyname_r(const char *name, struct hostent *ret, char *buf, size_t buflen, struct hostent **result, int *h_errnop) {
emilmont 3:e6474399e057 30 return lwip_gethostbyname_r(name, ret, buf, buflen, result, h_errnop);
emilmont 3:e6474399e057 31 }
emilmont 3:e6474399e057 32
emilmont 3:e6474399e057 33 class Socket {
emilmont 3:e6474399e057 34 public:
emilmont 3:e6474399e057 35 Socket();
emilmont 3:e6474399e057 36
emilmont 3:e6474399e057 37 int close();
emilmont 3:e6474399e057 38
emilmont 3:e6474399e057 39 protected:
emilmont 3:e6474399e057 40 int _sock_fd;
emilmont 3:e6474399e057 41 int init(int type);
emilmont 3:e6474399e057 42
emilmont 3:e6474399e057 43 void set_timeout(int timeout);
emilmont 3:e6474399e057 44 int wait_readable(void);
emilmont 3:e6474399e057 45 int wait_writable(void);
emilmont 3:e6474399e057 46
emilmont 3:e6474399e057 47 private:
emilmont 3:e6474399e057 48 // At the moment, we assume a simple single threaded access to the socket
emilmont 3:e6474399e057 49 struct timeval _timeout;
emilmont 3:e6474399e057 50 fd_set _fdSet;
emilmont 3:e6474399e057 51 int select(fd_set* readset, fd_set* writeset);
emilmont 3:e6474399e057 52 };
emilmont 3:e6474399e057 53
emilmont 3:e6474399e057 54 #endif /* SOCKET_H_ */