Socket: Add recvfrom method to receive UDP with source address. (#6103)

This commit is contained in:
Clyde Stubbs 2024-01-17 10:12:31 +11:00 committed by GitHub
parent 21337ffc67
commit 3854203037
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 10 additions and 0 deletions

View file

@ -86,6 +86,13 @@ class BSDSocketImpl : public Socket {
} }
int listen(int backlog) override { return ::listen(fd_, backlog); } int listen(int backlog) override { return ::listen(fd_, backlog); }
ssize_t read(void *buf, size_t len) override { return ::read(fd_, buf, len); } ssize_t read(void *buf, size_t len) override { return ::read(fd_, buf, len); }
ssize_t recvfrom(void *buf, size_t len, sockaddr *addr, socklen_t *addr_len) override {
#if defined(USE_ESP32)
return ::recvfrom(this->fd_, buf, len, 0, addr, addr_len);
#else
return ::lwip_recvfrom(this->fd_, buf, len, 0, addr, addr_len);
#endif
}
ssize_t readv(const struct iovec *iov, int iovcnt) override { ssize_t readv(const struct iovec *iov, int iovcnt) override {
#if defined(USE_ESP32) #if defined(USE_ESP32)
return ::lwip_readv(fd_, iov, iovcnt); return ::lwip_readv(fd_, iov, iovcnt);

View file

@ -31,6 +31,9 @@ class Socket {
virtual int setsockopt(int level, int optname, const void *optval, socklen_t optlen) = 0; virtual int setsockopt(int level, int optname, const void *optval, socklen_t optlen) = 0;
virtual int listen(int backlog) = 0; virtual int listen(int backlog) = 0;
virtual ssize_t read(void *buf, size_t len) = 0; virtual ssize_t read(void *buf, size_t len) = 0;
#ifdef USE_SOCKET_IMPL_BSD_SOCKETS
virtual ssize_t recvfrom(void *buf, size_t len, sockaddr *addr, socklen_t *addr_len) = 0;
#endif
virtual ssize_t readv(const struct iovec *iov, int iovcnt) = 0; virtual ssize_t readv(const struct iovec *iov, int iovcnt) = 0;
virtual ssize_t write(const void *buf, size_t len) = 0; virtual ssize_t write(const void *buf, size_t len) = 0;
virtual ssize_t writev(const struct iovec *iov, int iovcnt) = 0; virtual ssize_t writev(const struct iovec *iov, int iovcnt) = 0;