本文整理汇总了C++中SocketName::to_sockaddr方法的典型用法代码示例。如果您正苦于以下问题:C++ SocketName::to_sockaddr方法的具体用法?C++ SocketName::to_sockaddr怎么用?C++ SocketName::to_sockaddr使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SocketName
的用法示例。
在下文中一共展示了SocketName::to_sockaddr方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: send
void UDPSocketImpl::send(const void *data, int size, const SocketName &endpoint)
{
sockaddr_in addr;
endpoint.to_sockaddr(AF_INET, (sockaddr *)&addr, sizeof(sockaddr_in));
sendto(handle, static_cast<const char*>(data), size, 0, (const sockaddr *)&addr, sizeof(sockaddr_in));
}
示例2: Exception
TCPConnectionImpl::TCPConnectionImpl(const SocketName &endpoint)
{
int receive_buffer_size = 600 * 1024;
int send_buffer_size = 600 * 1024;
//int result = setsockopt(handle, SOL_SOCKET, SO_RCVBUF, (const char *) &receive_buffer_size, sizeof(int));
int result = setsockopt(handle, SOL_SOCKET, SO_SNDBUF, (const char *)&send_buffer_size, sizeof(int));
sockaddr_in addr;
endpoint.to_sockaddr(AF_INET, (sockaddr *)&addr, sizeof(sockaddr_in));
result = ::connect(handle, (const sockaddr *)&addr, sizeof(sockaddr_in));
if (result == SOCKET_ERROR)
throw Exception("Connect to server failed");
int value = 1;
result = setsockopt(handle, IPPROTO_TCP, TCP_NODELAY, (const char *)&value, sizeof(int));
result = WSAEventSelect(handle, wait_handle, FD_READ | FD_WRITE | FD_CLOSE);
if (result == SOCKET_ERROR)
throw Exception("WSAEventSelect failed");
//int receive_buffer_size = 0;
//int send_buffer_size = 0;
//int len = sizeof(int);
//getsockopt(handle, SOL_SOCKET, SO_RCVBUF, (char *) &receive_buffer_size, &len);
//getsockopt(handle, SOL_SOCKET, SO_SNDBUF, (char *) &send_buffer_size, &len);
}
示例3: bind
void UDPSocketImpl::bind(const SocketName &endpoint)
{
sockaddr_in addr;
endpoint.to_sockaddr(AF_INET, (sockaddr *)&addr, sizeof(sockaddr_in));
int result = ::bind(handle, (const sockaddr *)&addr, sizeof(sockaddr_in));
if (result == SOCKET_ERROR)
throw Exception("Could not bind socket to end point");
}
示例4: Exception
void Win32Socket::connect(const SocketName &socketname)
{
sockaddr_in addr;
socketname.to_sockaddr(AF_INET, (sockaddr *) &addr, sizeof(sockaddr_in));
int result = ::connect(handle, (const sockaddr *) &addr, sizeof(sockaddr_in));
if (result == SOCKET_ERROR)
{
int errorcode = WSAGetLastError();
if ( ! ( (errorcode == WSAEWOULDBLOCK) || (errorcode == WSAEINPROGRESS) ) )
throw Exception(error_to_string(errorcode));
}
}
示例5: setsockopt
void Win32Socket::bind(const SocketName &socketname, bool reuse_address)
{
if (reuse_address)
{
int value = 1;
int result = setsockopt(handle, SOL_SOCKET, SO_REUSEADDR, (const char *) &value, sizeof(int));
throw_if_failed(result);
}
sockaddr_in addr;
socketname.to_sockaddr(AF_INET, (sockaddr *) &addr, sizeof(sockaddr_in));
int result = ::bind(handle, (const sockaddr *) &addr, sizeof(sockaddr_in));
throw_if_failed(result);
}
示例6: Exception
TCPListen::TCPListen(const SocketName &endpoint, int backlog, bool reuse_address)
: impl(new TCPSocket())
{
if (reuse_address)
{
int value = 1;
int result = setsockopt(impl->handle, SOL_SOCKET, SO_REUSEADDR, (const char *)&value, sizeof(int));
if (result == SOCKET_ERROR)
throw Exception("Could not set reuse address socket option");
}
int receive_buffer_size = 600 * 1024;
int send_buffer_size = 600 * 1024;
//int result = setsockopt(impl->handle, SOL_SOCKET, SO_RCVBUF, (const char *) &receive_buffer_size, sizeof(int));
//if (result == SOCKET_ERROR)
// throw Exception("Could not set socket receive buffer size");
int result = setsockopt(impl->handle, SOL_SOCKET, SO_SNDBUF, (const char *)&send_buffer_size, sizeof(int));
if (result == SOCKET_ERROR)
throw Exception("Could not set socket send buffer size");
int value = 1;
result = setsockopt(impl->handle, IPPROTO_TCP, TCP_NODELAY, (const char *)&value, sizeof(int));
sockaddr_in addr;
endpoint.to_sockaddr(AF_INET, (sockaddr *)&addr, sizeof(sockaddr_in));
result = ::bind(impl->handle, (const sockaddr *)&addr, sizeof(sockaddr_in));
if (result == SOCKET_ERROR)
throw Exception("Could not bind socket to end point");
result = ::listen(impl->handle, backlog);
if (result == SOCKET_ERROR)
throw Exception("Unable to set socket into listen state");
result = WSAEventSelect(impl->handle, impl->wait_handle, FD_ACCEPT);
if (result == SOCKET_ERROR)
throw Exception("WSAEventSelect failed");
}