Exemple #1
0
void SOCK_Connector::connect(SOCK_Stream& server, INET_Address& addr)
{
	int ret = 0;
	const sockaddr* ad = addr.addr();
	SOCKET s = ::socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
	if (s == INVALID_SOCKET)
	{
		ret = WSAGetLastError();
		throw std::runtime_error("Socket() failed.");
	}

	ret = ::connect(s, ad, addr.size());
	if (ret != 0)
	{
		ret = WSAGetLastError();
		throw std::runtime_error("Connect() failed.");
	}
	else
	{
		server.set_handle(s);
	}
}
Exemple #2
0
void SOCK_Acceptor::accept(SOCK_Stream& s)
{
	s.set_handle(_WINSOCKAPI_::accept(handle_, 0, 0));
}