]>
git.gir.st - tmk_keyboard.git/blob - tool/mbed/mbed-sdk/libraries/net/lwip/Socket/Socket.h
1 /* Copyright (C) 2012 mbed.org, MIT License
3 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
4 * and associated documentation files (the "Software"), to deal in the Software without restriction,
5 * including without limitation the rights to use, copy, modify, merge, publish, distribute,
6 * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
7 * furnished to do so, subject to the following conditions:
9 * The above copyright notice and this permission notice shall be included in all copies or
10 * substantial portions of the Software.
12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
13 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
14 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
15 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
16 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 #include "lwip/sockets.h"
22 #include "lwip/netdb.h"
25 inline struct hostent
*gethostbyname(const char *name
) {
26 return lwip_gethostbyname(name
);
29 inline int gethostbyname_r(const char *name
, struct hostent
*ret
, char *buf
, size_t buflen
, struct hostent
**result
, int *h_errnop
) {
30 return lwip_gethostbyname_r(name
, ret
, buf
, buflen
, result
, h_errnop
);
35 /** Socket file descriptor and select wrapper
43 /** Set blocking or non-blocking mode of the socket and a timeout on
44 blocking socket operations
45 \param blocking true for blocking mode, false for non-blocking mode.
46 \param timeout timeout in ms [Default: (1500)ms].
48 void set_blocking(bool blocking
, unsigned int timeout
=1500);
50 /** Set socket options
51 \param level stack level (see: lwip/sockets.h)
52 \param optname option ID
53 \param optval option value
54 \param socklen_t length of the option value
55 \return 0 on success, -1 on failure
57 int set_option(int level
, int optname
, const void *optval
, socklen_t optlen
);
59 /** Get socket options
60 \param level stack level (see: lwip/sockets.h)
61 \param optname option ID
62 \param optval buffer pointer where to write the option value
63 \param socklen_t length of the option value
64 \return 0 on success, -1 on failure
66 int get_option(int level
, int optname
, void *optval
, socklen_t
*optlen
);
69 \param shutdown free the left-over data in message queues
71 int close(bool shutdown
=true);
77 int init_socket(int type
);
79 int wait_readable(TimeInterval
& timeout
);
80 int wait_writable(TimeInterval
& timeout
);
83 unsigned int _timeout
;
86 int select(struct timeval
*timeout
, bool read
, bool write
);
89 /** Time interval class used to specify timeouts
96 \param ms time interval expressed in milliseconds
98 TimeInterval(unsigned int ms
);
101 struct timeval _time
;
104 #endif /* SOCKET_H_ */