diff --git a/posix/socket.cpp b/posix/socket.cpp index 2a486db2..d8637db6 100644 --- a/posix/socket.cpp +++ b/posix/socket.cpp @@ -170,3 +170,46 @@ socket::connect (util::view host, int port) throw std::runtime_error ("unable to reconnect"); } + + + +/////////////////////////////////////////////////////////////////////////////// +template +ssize_t +socket::sendto (util::view buffer, int flags, ::sockaddr_in const &dst) +{ + return util::posix::error::try_value ( + ::sendto ( + native (), + buffer.data (), + buffer.size (), + flags, + reinterpret_cast (&dst), + sizeof (dst) + ) + ); +} + + +template ssize_t socket::sendto (util::view, int, sockaddr_in const&); +template ssize_t socket::sendto (util::view, int, sockaddr_in const&); +template ssize_t socket::sendto (util::view, int, sockaddr_in const&); + + + +//----------------------------------------------------------------------------- +template +util::view +socket::recvfrom (util::view buffer, int flags) +{ + auto res = util::posix::error::try_value ( + ::recvfrom (native (), buffer.data (), buffer.size (), flags, nullptr, nullptr) + ); + + return { buffer.begin (), res }; +} + + +template util::view socket::recvfrom (util::view buffer, int flags); +template util::view socket::recvfrom (util::view buffer, int flags); +template util::view socket::recvfrom (util::view buffer, int flags); diff --git a/posix/socket.hpp b/posix/socket.hpp index b5e87534..52f54d62 100644 --- a/posix/socket.hpp +++ b/posix/socket.hpp @@ -54,6 +54,12 @@ namespace util::posix { void connect (util::view host, int port); void shutdown (); + template + ssize_t sendto (util::view data, int flags, ::sockaddr_in const &dst); + + template + util::view recvfrom (util::view buffer, int flags); + template void setoption (int _level, int _name, const ValueT &_value) {