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 std::unique_ptr<Socket> accept(
struct sockaddr *addr,
socklen_t *addrlen)
override {
43 int fd = lwip_accept(fd_, addr, addrlen);
46 return make_unique<LwIPSocketImpl>(fd);
48 int bind(
const struct sockaddr *addr,
socklen_t addrlen)
override {
return lwip_bind(fd_, addr, addrlen); }
49 int close()
override {
50 int ret = lwip_close(fd_);
54 int shutdown(
int how)
override {
return lwip_shutdown(fd_, how); }
56 int getpeername(
struct sockaddr *addr,
socklen_t *addrlen)
override {
return lwip_getpeername(fd_, addr, addrlen); }
57 std::string getpeername()
override {
60 int err = this->getpeername((
struct sockaddr *) &storage, &len);
65 int getsockname(
struct sockaddr *addr,
socklen_t *addrlen)
override {
return lwip_getsockname(fd_, addr, addrlen); }
66 std::string getsockname()
override {
69 int err = this->getsockname((
struct sockaddr *) &storage, &len);
74 int getsockopt(
int level,
int optname,
void *optval,
socklen_t *optlen)
override {
75 return lwip_getsockopt(fd_, level, optname, optval, optlen);
77 int setsockopt(
int level,
int optname,
const void *optval,
socklen_t optlen)
override {
78 return lwip_setsockopt(fd_, level, optname, optval, optlen);
80 int listen(
int backlog)
override {
return lwip_listen(fd_, backlog); }
81 ssize_t read(
void *buf,
size_t len)
override {
return lwip_read(fd_, buf, len); }
82 ssize_t readv(
const struct iovec *iov,
int iovcnt)
override {
return lwip_readv(fd_, iov, iovcnt); }
83 ssize_t write(
const void *buf,
size_t len)
override {
return lwip_write(fd_, buf, len); }
84 ssize_t send(
void *buf,
size_t len,
int flags) {
return lwip_send(fd_, buf, len, flags); }
85 ssize_t writev(
const struct iovec *iov,
int iovcnt)
override {
return lwip_writev(fd_, iov, iovcnt); }
86 ssize_t sendto(
const void *buf,
size_t len,
int flags,
const struct sockaddr *to,
socklen_t tolen)
override {
87 return lwip_sendto(fd_, buf, len, flags, to, tolen);
89 int setblocking(
bool blocking)
override {
90 int fl = lwip_fcntl(fd_, F_GETFL, 0);
96 lwip_fcntl(fd_, F_SETFL, fl);
102 bool closed_ =
false;
105 std::unique_ptr<Socket>
socket(
int domain,
int type,
int protocol) {
106 int ret = lwip_socket(domain, type, protocol);
109 return std::unique_ptr<Socket>{
new LwIPSocketImpl(ret)};
115 #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.