本文整理汇总了C++中SocketAddress::GetSize方法的典型用法代码示例。如果您正苦于以下问题:C++ SocketAddress::GetSize方法的具体用法?C++ SocketAddress::GetSize怎么用?C++ SocketAddress::GetSize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SocketAddress
的用法示例。
在下文中一共展示了SocketAddress::GetSize方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: assert
bool
SocketDescriptor::Connect(SocketAddress address)
{
assert(address.IsDefined());
return ::connect(Get(), address.GetAddress(), address.GetSize()) >= 0;
}
示例2: ReceiveFrom
int UDPSocket::ReceiveFrom( void* inToReceive, int inMaxLength, SocketAddress& outFromAddress )
{
socklen_t fromLength = outFromAddress.GetSize();
int readByteCount = recvfrom( mSocket,
static_cast< char* >( inToReceive ),
inMaxLength,
0, &outFromAddress.mSockAddr, &fromLength );
if( readByteCount >= 0 )
{
return readByteCount;
}
else
{
int error = SocketUtil::GetLastError();
if( error == WSAEWOULDBLOCK )
{
return 0;
}
else if( error == WSAECONNRESET )
{
//this can happen if a client closed and we haven't DC'd yet.
//this is the ICMP message being sent back saying the port on that computer is closed
LOG( "Connection reset from %s", outFromAddress.ToString().c_str() );
return -WSAECONNRESET;
}
else
{
SocketUtil::ReportError( "UDPSocket::ReceiveFrom" );
return -error;
}
}
}
示例3: Bind
int UDPSocket::Bind( const SocketAddress& inBindAddress )
{
int error = bind( mSocket, &inBindAddress.mSockAddr, inBindAddress.GetSize() );
if( error != 0 )
{
SocketUtil::ReportError( "UDPSocket::Bind" );
return SocketUtil::GetLastError();
}
return NO_ERROR;
}
示例4: Bind
int UDPSocket::Bind(const SocketAddress& address)
{
int error = bind(m_socket, &address.m_sockAddr, (int)address.GetSize());
if(error != 0)
{
#ifdef _DEBUG
ReportError("UDPSocket::Bind");
#endif
return LastError();
}
return NO_ERROR;
}
示例5: ReceiveFrom
int UDPSocket::ReceiveFrom(void* buffer, int len, SocketAddress& from)
{
socklen_t fromLen = (socklen_t)from.GetSize();
int byteCount = recvfrom(m_socket, static_cast<char*>(buffer), len, 0, &from.m_sockAddr, &fromLen);
if(byteCount < 0)
{
#ifdef _DEBUG
ReportError("UDPSocket::ReceiveFrom");
#endif
return -LastError();
}
return byteCount;
}
示例6:
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());
}
示例7: SendTo
int UDPSocket::SendTo( const void* inToSend, int inLength, const SocketAddress& inToAddress )
{
int byteSentCount = sendto( mSocket,
static_cast< const char* >( inToSend ),
inLength,
0, &inToAddress.mSockAddr, inToAddress.GetSize() );
if( byteSentCount <= 0 )
{
//we'll return error as negative number to indicate less than requested amount of bytes sent...
SocketUtil::ReportError( "UDPSocket::SendTo" );
return -SocketUtil::GetLastError();
}
else
{
return byteSentCount;
}
}
示例8: SendTo
int UDPSocket::SendTo(const void* data, int len, const SocketAddress& to)
{
int byteCount = sendto(m_socket, static_cast<const char*>(data), len, 0, &to.m_sockAddr, (int)to.GetSize());
if(byteCount < 0)
{
#ifdef _DEBUG
ReportError("UDPSocket::SendTo");
#endif
return -LastError();
}
return byteCount;
}
示例9: bind
bool
SocketDescriptor::Bind(SocketAddress address)
{
return bind(Get(), address.GetAddress(), address.GetSize()) == 0;
}