本文整理汇总了C++中RawData::alloc方法的典型用法代码示例。如果您正苦于以下问题:C++ RawData::alloc方法的具体用法?C++ RawData::alloc怎么用?C++ RawData::alloc使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RawData
的用法示例。
在下文中一共展示了RawData::alloc方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: process
void Net::process()
{
sockaddr sa;
sa.sa_family = AF_UNSPEC;
NetAddress srcAddress;
RawData tmpBuffer;
tmpBuffer.alloc(MaxPacketDataSize);
for(;;)
{
socklen_t addrLen = sizeof(sa);
S32 bytesRead = -1;
if(udpSocket != InvalidSocket)
bytesRead = recvfrom(udpSocket, (char *) tmpBuffer.data, MaxPacketDataSize, 0, &sa, &addrLen);
if(bytesRead == -1)
break;
if(sa.sa_family == AF_INET)
IPSocketToNetAddress((sockaddr_in *) &sa, &srcAddress);
else
continue;
if(bytesRead <= 0)
continue;
if(srcAddress.type == NetAddress::IPAddress &&
srcAddress.netNum[0] == 127 &&
srcAddress.netNum[1] == 0 &&
srcAddress.netNum[2] == 0 &&
srcAddress.netNum[3] == 1 &&
srcAddress.port == netPort)
continue;
tmpBuffer.size = bytesRead;
Net::smPacketReceive.trigger(srcAddress, tmpBuffer);
}
// process the polled sockets. This blob of code performs functions
// similar to WinsockProc in winNet.cc
if (gPolledSockets.size() == 0)
return;
S32 optval;
socklen_t optlen = sizeof(S32);
S32 bytesRead;
Net::Error err;
bool removeSock = false;
Socket *currentSock = NULL;
sockaddr_in ipAddr;
NetSocket incoming = InvalidSocket;
char out_h_addr[1024];
int out_h_length = 0;
RawData readBuff;
for (S32 i = 0; i < gPolledSockets.size();
/* no increment, this is done at end of loop body */)
{
removeSock = false;
currentSock = gPolledSockets[i];
switch (currentSock->state)
{
case ::InvalidState:
Con::errorf("Error, InvalidState socket in polled sockets list");
break;
case ::ConnectionPending:
// see if it is now connected
#ifdef TORQUE_OS_XENON
// WSASetLastError has no return value, however part of the SO_ERROR behavior
// is to clear the last error, so this needs to be done here.
if( ( optval = _getLastErrorAndClear() ) == -1 )
#else
if (getsockopt(currentSock->fd, SOL_SOCKET, SO_ERROR,
(char*)&optval, &optlen) == -1)
#endif
{
Con::errorf("Error getting socket options: %s", strerror(errno));
Net::smConnectionNotify.trigger(currentSock->fd, Net::ConnectFailed);
removeSock = true;
}
else
{
if (optval == EINPROGRESS)
// still connecting...
break;
if (optval == 0)
{
// poll for writable status to be sure we're connected.
bool ready = netSocketWaitForWritable(currentSock->fd,0);
if(!ready)
break;
currentSock->state = ::Connected;
Net::smConnectionNotify.trigger(currentSock->fd, Net::Connected);
}
//.........这里部分代码省略.........