bool SocketDescriptor::Connect(SocketAddress address) { assert(address.IsDefined()); return ::connect(Get(), address.GetAddress(), address.GetSize()) >= 0; }
bool SocketImpl::Connect(const SocketAddress& address, const std::chrono::seconds& timeout /*= std::chrono::seconds(0)*/) { if (INVALID_SOCKET == m_sockfd) Init(AF_INET); if (timeout.count() > 0) SetBlocking(false); bool bResult = false; do { if (SOCKET_ERROR == connect(m_sockfd, address.GetAddress(), address.GetLength())) { if (timeout.count() == 0) break; int err = WSAGetLastError(); if (WSAEINPROGRESS != err && WSAEWOULDBLOCK != err && WSAEISCONN != err) break; if (!Poll(timeout, SELECT_READ | SELECT_WRITE | SELECT_ERROR)) break; if (GetSocketError() != 0) break; } bResult = true; } while (0); if (timeout.count() > 0) SetBlocking(true); return bResult; }
bool SocketImpl::Bind(const SocketAddress& address, bool bReuse /*= false*/) { if (INVALID_SOCKET == m_sockfd) Init(AF_INET); if (bReuse) SetReuseAddress(true); return bind(m_sockfd, address.GetAddress(), address.GetLength()) != SOCKET_ERROR; }
int GenericSocket::Bind(SocketAddress & sa) { sockaddr dir; sa.GetAddress(dir); int err = bind(sock, &dir, sizeof(sockaddr)); if (err == -1) { SocketTools::MostrarError("Error en GenericSocket::Bind"); } return err; }
ssize_t SocketDescriptor::Write(const void *buffer, size_t length, SocketAddress address) { int flags = 0; #ifdef HAVE_POSIX flags |= MSG_DONTWAIT; #endif #ifdef __linux__ flags |= MSG_NOSIGNAL; #endif return ::sendto(Get(), (const char *)buffer, length, flags, address.GetAddress(), address.GetSize()); }
bool SocketDescriptor::Bind(SocketAddress address) { return bind(Get(), address.GetAddress(), address.GetSize()) == 0; }
int SocketImpl::SendTo(const char* buffer, int length, const SocketAddress& address, int flags /*= 0*/) { assert(INVALID_SOCKET != m_sockfd); return sendto(m_sockfd, buffer, length, flags, address.GetAddress(), address.GetLength()); }