43#include <netplus/exception.h>
44#include <netplus/socket.h>
53inline int boundPort(netplus::socket &sock) {
55 socklen_t blen =
sizeof(bound);
56 ::getsockname(sock.fd(),
reinterpret_cast<sockaddr *
>(&bound), &blen);
57 return ntohs(bound.sin_port);
61inline void connectLocal(netplus::tcp &sock,
int port) {
62 sock.connect(
"127.0.0.1", port);
70inline void sendAllOrThrow(netplus::socket &sock,
const char *data,
size_t len) {
73 netplus::buffer buf(data + sent, len - sent);
76 n = sock.sendData(buf);
77 }
catch (netplus::NetException &e) {
78 throw std::runtime_error(std::string(
"rawtcp::sendAllOrThrow: ") + e.what());
80 if (n == 0)
throw std::runtime_error(
"rawtcp::sendAllOrThrow: send failed");
84inline void sendAllOrThrow(netplus::socket &sock,
const std::string &s) {
85 sendAllOrThrow(sock, s.data(), s.size());