5 #ifdef USE_SOCKET_IMPL_LWIP_SOCKETS 15 char buf[INET_ADDRSTRLEN];
16 const char *ret = lwip_inet_ntop(AF_INET, &addr->
sin_addr, buf,
sizeof(buf));
19 return std::string{buf};
24 char buf[INET6_ADDRSTRLEN];
25 const char *ret = lwip_inet_ntop(AF_INET6, &addr->
sin6_addr, buf,
sizeof(buf));
28 return std::string{buf};
34 class LwIPSocketImpl :
public Socket {
36 LwIPSocketImpl(
int fd) : fd_(fd) {}
37 ~LwIPSocketImpl()
override {
42 int connect(
const struct sockaddr *addr,
socklen_t addrlen)
override {
return lwip_connect(fd_, addr, addrlen); }
43 std::unique_ptr<Socket> accept(
struct sockaddr *addr,
socklen_t *addrlen)
override {
44 int fd = lwip_accept(fd_, addr, addrlen);
47 return make_unique<LwIPSocketImpl>(fd);
49 int bind(
const struct sockaddr *addr,
socklen_t addrlen)
override {
return lwip_bind(fd_, addr, addrlen); }
50 int close()
override {
51 int ret = lwip_close(fd_);
55 int shutdown(
int how)
override {
return lwip_shutdown(fd_, how); }
57 int getpeername(
struct sockaddr *addr,
socklen_t *addrlen)
override {
return lwip_getpeername(fd_, addr, addrlen); }
58 std::string getpeername()
override {
61 int err = this->getpeername((
struct sockaddr *) &storage, &len);
66 int getsockname(
struct sockaddr *addr,
socklen_t *addrlen)
override {
return lwip_getsockname(fd_, addr, addrlen); }
67 std::string getsockname()
override {
70 int err = this->getsockname((
struct sockaddr *) &storage, &len);
75 int getsockopt(
int level,
int optname,
void *optval,
socklen_t *optlen)
override {
76 return lwip_getsockopt(fd_, level, optname, optval, optlen);
78 int setsockopt(
int level,
int optname,
const void *optval,
socklen_t optlen)
override {
79 return lwip_setsockopt(fd_, level, optname, optval, optlen);
81 int listen(
int backlog)
override {
return lwip_listen(fd_, backlog); }
82 ssize_t read(
void *buf,
size_t len)
override {
return lwip_read(fd_, buf, len); }
83 ssize_t readv(
const struct iovec *iov,
int iovcnt)
override {
return lwip_readv(fd_, iov, iovcnt); }
84 ssize_t write(
const void *buf,
size_t len)
override {
return lwip_write(fd_, buf, len); }
85 ssize_t send(
void *buf,
size_t len,
int flags) {
return lwip_send(fd_, buf, len, flags); }
86 ssize_t writev(
const struct iovec *iov,
int iovcnt)
override {
return lwip_writev(fd_, iov, iovcnt); }
87 ssize_t sendto(
const void *buf,
size_t len,
int flags,
const struct sockaddr *to,
socklen_t tolen)
override {
88 return lwip_sendto(fd_, buf, len, flags, to, tolen);
90 int setblocking(
bool blocking)
override {
91 int fl = lwip_fcntl(fd_, F_GETFL, 0);
97 lwip_fcntl(fd_, F_SETFL, fl);
103 bool closed_ =
false;
106 std::unique_ptr<Socket>
socket(
int domain,
int type,
int protocol) {
107 int ret = lwip_socket(domain, type, protocol);
110 return std::unique_ptr<Socket>{
new LwIPSocketImpl(ret)};
116 #endif // USE_SOCKET_IMPL_LWIP_SOCKETS
Implementation of SPI Controller mode.
std::string format_sockaddr(const struct sockaddr_storage &storage)
struct in6_addr sin6_addr
std::unique_ptr< Socket > socket(int domain, int type, int protocol)
Create a socket of the given domain, type and protocol.