48#if LASS_HAVE_SYS_SOCKET_H && !defined(LASS_IO_SOCKET_HAVE_LIBC)
49# define LASS_IO_SOCKET_HAVE_LIBC
52#if defined(LASS_IO_SOCKET_HAVE_WINSOCK)
54#elif defined(LASS_IO_SOCKET_HAVE_LIBC)
57# error "[LASS BUILD MSG] Socket not supported for this platform"
67 pimpl_ =
new impl::SocketImpl;
92 pimpl_->closeSocket();
97void Socket::bind(TPort port)
104void Socket::bind(
const std::string& address, TPort port)
107 pimpl_->bind(address, port);
128 for (TPort port = begin; port < end; ++port)
132 pimpl_->bind(address, port);
135 catch (
const SocketError&)
139 LASS_THROW_EX(SocketError,
"Failed to bind socket to any port in range [" << begin <<
", " << end <<
").");
152void Socket::accept(Socket& connection)
const
155 LASS_ASSERT(connection.pimpl_);
156 pimpl_->accept(connection.pimpl_);
161void Socket::connect(
const std::string& address, TPort port)
164 pimpl_->connect(address, port);
169std::string Socket::address()
const
172 return pimpl_->address();
177Socket::TPort Socket::port()
const
180 return pimpl_->port();
185int Socket::send(
const void* begin,
int length)
const
188 return pimpl_->send(begin, length);
193const void* Socket::send(
const void* begin,
const void* end)
const
196 const char* first =
static_cast<const char*
>(begin);
197 const char* last =
static_cast<const char*
>(end);
198 const int length = num::numCast<int>(last - first);
199 const int sent = pimpl_->send(first, length);
200 LASS_ASSERT(sent >= 0);
206int Socket::receive(
void* begin,
int length)
const
209 return pimpl_->receive(begin, length);
214void* Socket::receive(
void* begin,
void* end)
const
217 char* first =
static_cast<char*
>(begin);
218 char* last =
static_cast<char*
>(end);
219 const int length = num::numCast<int>(last - first);
220 const int sent = pimpl_->receive(first, length);
221 LASS_ASSERT(sent >= 0);
227int Socket::sizeSendBuffer()
const
230 return pimpl_->sizeSendBuffer();
235void Socket::swap(
Socket& other)
237 std::swap(pimpl_, other.pimpl_);
TPort bindInRange(TPort begin, TPort end)
Bind to the first available port in range [begin, end).
streams, binary streams, vrmlstreams, ...
Library for Assembled Shared Sources.