本文整理汇总了C++中RakSleep函数的典型用法代码示例。如果您正苦于以下问题:C++ RakSleep函数的具体用法?C++ RakSleep怎么用?C++ RakSleep使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了RakSleep函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: while
void
CProxy::updateThread()
{
// Threaded update loop
while (!m_bQuit)
{
try
{
while (m_pListenInterface->Receive())
;
{
RakNet::Packet* pPacket = NULL;
for (pPacket = m_pLoginSrvInterface->Receive(); pPacket; m_pLoginSrvInterface->DeallocatePacket(pPacket), pPacket = m_pLoginSrvInterface->Receive())
if (!OnLoginSrvReceive(pPacket))
break;
}
}
catch (std::exception ex)
{
ff::fmt(pan::critical, "Caught an exception in updateThread ({0}).", ex.what());
}
RakSleep(10);
}
}
示例2: while
bool CommonFunctions::WaitAndConnect(RakPeerInterface *peer,char* ip,unsigned short int port,int millisecondsToWait)
{
SystemAddress connectToAddress;
connectToAddress.SetBinaryAddress(ip);
connectToAddress.port=port;
TimeMS entryTime=GetTimeMS();
while(!CommonFunctions::ConnectionStateMatchesOptions (peer,connectToAddress,true)&&GetTimeMS()-entryTime<millisecondsToWait)
{
if(!CommonFunctions::ConnectionStateMatchesOptions (peer,connectToAddress,true,true,true,true))
{
peer->Connect(ip,port,0,0);
}
RakSleep(100);
}
if (ConnectionStateMatchesOptions (peer,connectToAddress,true))
{
return 1;
}
return 0;
}
示例3: socket
bool UPNPNAT::tcp_connect(const char * _host,unsigned short int _port)
{
int ret;
tcp_socket_fd=(int) socket(AF_INET,SOCK_STREAM,0);
struct sockaddr_in r_address;
r_address.sin_family = AF_INET;
r_address.sin_port=htons(_port);
r_address.sin_addr.s_addr=inet_addr(_host);
RakNetTime stopWaiting = RakNet::GetTime() + time_out;
while (RakNet::GetTime() < stopWaiting)
{
ret=connect(tcp_socket_fd,(const struct sockaddr *)&r_address,sizeof(struct sockaddr_in) );
RakSleep(50);
if(ret==0)
{
status=NAT_TCP_CONNECTED;
return true;
}
}
status=NAT_ERROR;
char temp[100];
sprintf(temp,"Fail to connect to %s:%i (using TCP)\n",_host,_port);
last_error=temp;
return false;
}
示例4: while
unsigned RNS2_Berkley::RecvFromLoopInt(void)
{
isRecvFromLoopThreadActive.Increment();
while ( endThreads == false )
{
RNS2RecvStruct *recvFromStruct;
recvFromStruct=binding.eventHandler->AllocRNS2RecvStruct(_FILE_AND_LINE_);
if (recvFromStruct != NULL)
{
recvFromStruct->socket=this;
RecvFromBlocking(recvFromStruct);
if (recvFromStruct->bytesRead>0)
{
RakAssert(recvFromStruct->systemAddress.GetPort());
binding.eventHandler->OnRNS2Recv(recvFromStruct);
}
else
{
RakSleep(0);
binding.eventHandler->DeallocRNS2RecvStruct(recvFromStruct, _FILE_AND_LINE_);
}
}
}
isRecvFromLoopThreadActive.Decrement();
return 0;
}
示例5: while
void MasterList::pulse()
{
RakNet::RakString post;
RakNet::Packet* packet;
while (ServerCore::getInstance().isActive())
{
if ((utility::TimeUtility::getMsTime() - m_lastUpdateTime) < 3000)
continue;
if (m_tcp->Connect(ProjectGlobals::getMasterlistUrl().c_str(), 80, true) == RakNet::UNASSIGNED_SYSTEM_ADDRESS)
continue;
RakSleep(100);
if (m_state == masterListState::STATE_ADD)
m_token = utility::StringUtility::random_string(42);
post = RakNet::RakString::FormatForPOST(std::string(ProjectGlobals::getMasterlistUrl()).append("/api/v1/server/update").c_str(),
"application/x-www-form-urlencoded",
RakNet::RakString("token=%s&ip=%s&port=%d&players=%d",
m_token.c_str(),
ServerCore::getInstance().getServerCoreConfiguration().getAddress().c_str(),
ServerCore::getInstance().getServerCoreConfiguration().getPort(),
ServerCore::getInstance().getPlayerManager().getPoolSize()),
"User-Agent: Malefice/1.0");
m_tcp->Send(post.C_String(), post.GetLength(), m_tcp->HasCompletedConnectionAttempt(), false);
RakSleep(1000);
packet = m_tcp->Receive();
if (!packet)
continue;
if (m_state == masterListState::STATE_ADD) {
LOG_INFO(NETWORK) << "Server successfully posted to the MasterList";
m_state = masterListState::STATE_UPDATE;
}
m_lastUpdateTime = utility::TimeUtility::getMsTime();
m_tcp->DeallocatePacket(packet);
RakSleep(100);
}
}
示例6: BindShared
RNS2BindResult RNS2_Windows::Bind( RNS2_BerkleyBindParameters *bindParameters, const char *file, unsigned int line ) {
RNS2BindResult bindResult = BindShared(bindParameters, file, line);
if (bindResult == BR_FAILED_TO_BIND_SOCKET)
{
// Sometimes windows will fail if the socket is recreated too quickly
RakSleep(100);
bindResult = BindShared(bindParameters, file, line);
}
return bindResult;
}
示例7: defined
bool TCPInterface::Start(unsigned short port, unsigned short maxIncomingConnections, unsigned short maxConnections, int _threadPriority)
{
if (isStarted)
return false;
threadPriority=_threadPriority;
if (threadPriority==-99999)
{
#if defined(_XBOX) || defined(X360)
#elif defined(_WIN32)
threadPriority=0;
#elif defined(_PS3) || defined(__PS3__) || defined(SN_TARGET_PS3)
#else
threadPriority=1000;
#endif
}
isStarted=true;
if (maxConnections==0)
maxConnections=maxIncomingConnections;
if (maxConnections==0)
maxConnections=1;
remoteClientsLength=maxConnections;
remoteClients=RakNet::OP_NEW_ARRAY<RemoteClient>(maxConnections,__FILE__,__LINE__);
if (maxIncomingConnections>0)
{
listenSocket = socket(AF_INET, SOCK_STREAM, 0);
if ((int)listenSocket ==-1)
return false;
struct sockaddr_in serverAddress;
serverAddress.sin_family = AF_INET;
serverAddress.sin_addr.s_addr = htonl(INADDR_ANY);
serverAddress.sin_port = htons(port);
if (bind(listenSocket,(struct sockaddr *) &serverAddress,sizeof(serverAddress)) < 0)
return false;
listen(listenSocket, maxIncomingConnections);
}
// Start the update thread
int errorCode = RakNet::RakThread::Create(UpdateTCPInterfaceLoop, this, threadPriority);
if (errorCode!=0)
return false;
while (threadRunning==false)
RakSleep(0);
return true;
}
示例8: serverThread
void serverThread(std::recursive_mutex *mutex_, TestValues *testValues,
BaseClassA *serverAPtr, ClassC *serverCPtr, ClassD *serverDPtr,
RakNet::RPC3 *serverRpc, unsigned int peerCount,
unsigned int callCount) {
RakNet::RPC3 *emptyRpc = 0;
unsigned int count = callCount;
uint64_t startTime = RakNet::GetTimeUS();
while (count) {
for (size_t i = 1; i < peerCount; i++) {
uint64_t callNumber = i * callCount + count;
RakNet::BitStream testBitStream1, testBitStream2;
testBitStream1.Write("CPP TEST STRING");
testBitStream2.Write("CPP Remote call timestamp test string.");
RakNet::BitStream *testBitStream1Ptr = &testBitStream1;
uint64_t callTime = RakNet::GetTimeUS();
serverCPtr->ClassMemberFuncTest(
serverAPtr, *serverAPtr, serverCPtr, serverDPtr,
testBitStream1Ptr, testBitStream2, callNumber, callTime, emptyRpc
);
serverRpc->CallCPP(
"&ClassC::ClassMemberFuncTest", serverCPtr->GetNetworkID(),
serverAPtr, *serverAPtr, serverCPtr, serverDPtr,
testBitStream1Ptr, testBitStream2, callNumber, callTime, emptyRpc
);
RakNet::RakString rs("C Function call test string.");
const char *str = "C Remote call char * test.";
callTime = RakNet::GetTimeUS();
CFuncTest(rs, serverCPtr, str, callNumber, callTime, emptyRpc);
serverRpc->CallC("CFuncTest",
rs, serverCPtr, str, callNumber, callTime, emptyRpc);
callTime = RakNet::GetTimeUS();
serverRpc->Signal("TestSlotTest", callNumber, callTime);
}
count--;
RakSleep(16);
}
mutex_->lock();
testValues->callFunctionsTime = RakNet::GetTimeUS() - startTime;
mutex_->unlock();
delete emptyRpc;
}
示例9: ServerConnectBlocking
RakNet::SystemAddress ServerConnectBlocking(RakNet::RakPeerInterface *rakPeer, const char *hostName)
{
char ipAddr[64];
printf("Enter IP of system %s is running on: ", hostName);
//Gets(ipAddr, sizeof(ipAddr));
if (ipAddr[0] == 0)
{
printf("Failed. Not connected to %s.\n", hostName);
return RakNet::UNASSIGNED_SYSTEM_ADDRESS;
}
char port[64];
printf("Enter port of system %s is running on: ", hostName);
//Gets(port, sizeof(port));
if (port[0] == 0)
{
printf("Failed. Not connected to %s.\n", hostName);
return RakNet::UNASSIGNED_SYSTEM_ADDRESS;
}
if (rakPeer->Connect(ipAddr, atoi(port), 0, 0) != RakNet::CONNECTION_ATTEMPT_STARTED)
{
printf("Failed connect call for %s.\n", hostName);
return RakNet::UNASSIGNED_SYSTEM_ADDRESS;
}
printf("Connecting...\n");
RakNet::Packet *packet;
while (1)
{
for (packet = rakPeer->Receive(); packet; rakPeer->DeallocatePacket(packet), packet = rakPeer->Receive())
{
if (packet->data[0] == ID_CONNECTION_REQUEST_ACCEPTED)
{
return packet->systemAddress;
}
else
{
return RakNet::UNASSIGNED_SYSTEM_ADDRESS;
}
RakSleep(100);
}
}
}
示例10: Send
void RNS2_Berkley::BlockOnStopRecvPollingThread(void)
{
endThreads=true;
// Get recvfrom to unblock
RNS2_SendParameters bsp;
unsigned long zero=0;
bsp.data=(char*) &zero;
bsp.length=4;
bsp.systemAddress=boundAddress;
bsp.ttl=0;
Send(&bsp, _FILE_AND_LINE_);
RakNet::TimeMS timeout = RakNet::GetTimeMS()+1000;
while ( isRecvFromLoopThreadActive.GetValue()>0 && RakNet::GetTimeMS()<timeout )
{
// Get recvfrom to unblock
Send(&bsp, _FILE_AND_LINE_);
RakSleep(30);
}
}
示例11: while
std::vector<RakNet::RakString> NetworkEngine::getLanServers()
{
//En el server browser se utiliza getLanServersList()
std::vector<RakNet::RakString> serverList;
RakNet::Packet *packet;
peer->Ping("255.255.255.255", SERVER_PORT, false);
RakNet::TimeMS timeout = RakNet::GetTimeMS() + 1000;
while(RakNet::GetTimeMS() < timeout) // Bloquea durante 1s el juego
{
packet = peer->Receive();
while(packet != 0) //Ha llegado un paquete
{
if (packet->data[0]==ID_UNCONNECTED_PONG)
{
RakNet::TimeMS time;
RakNet::BitStream bsIn(packet->data,packet->length,false);
bsIn.IgnoreBytes(1);
bsIn.Read(time);
//char playerData;
//bsIn.Read(playerData);
std::cout<<peer->NumberOfConnections()<<std::endl;
//std::cout << "Server: " << packet->systemAddress.ToString() << ", players: "<< playerData << "/4, ping: "<< RakNet::GetTimeMS() - time << "ms\n";
std::cout << "Server: " << packet->systemAddress.ToString() << ", ping: "<< RakNet::GetTimeMS() - time << "ms\n";
serverList.push_back((RakNet::RakString) packet->systemAddress.ToString(false));
timeout -= 500; // Si ha encontrado un servidor termina antes
}
peer->DeallocatePacket(packet);
packet = peer->Receive();
}
RakSleep(30);
}
return serverList;
}
示例12: socket
bool TCPInterface::Start(unsigned short port, unsigned short maxIncomingConnections, unsigned short maxConnections)
{
if (isStarted)
return false;
isStarted=true;
if (maxConnections==0)
maxConnections=maxIncomingConnections;
if (maxConnections==0)
maxConnections=1;
remoteClientsLength=maxConnections;
remoteClients=RakNet::OP_NEW_ARRAY<RemoteClient>(maxConnections,__FILE__,__LINE__);
if (maxIncomingConnections>0)
{
listenSocket = socket(AF_INET, SOCK_STREAM, 0);
if ((int)listenSocket ==-1)
return false;
struct sockaddr_in serverAddress;
serverAddress.sin_family = AF_INET;
serverAddress.sin_addr.s_addr = htonl(INADDR_ANY);
serverAddress.sin_port = htons(port);
if (bind(listenSocket,(struct sockaddr *) &serverAddress,sizeof(serverAddress)) < 0)
return false;
listen(listenSocket, maxIncomingConnections);
}
// Start the update thread
int errorCode = RakNet::RakThread::Create(UpdateTCPInterfaceLoop, this);
if (errorCode!=0)
return false;
while (threadRunning==false)
RakSleep(0);
return true;
}
示例13: now
void FrameTimer::step()
{
double timeToSleep = 1 / _framerate;
timeToSleep -= now() - _frameTime;
if (timeToSleep < 0)
timeToSleep = 0;
// Always sleep, even if 0, to play nice with other programs
RakSleep(static_cast<unsigned int>(toTimestamp(timeToSleep)));
double previous = _frameTime;
_frameTime = now();
_elapsed = _frameTime - previous;
// Framerate computation
if (_totalFrameTiming > FRAMERATE_SECONDS && !_frameTiming.empty()) {
_totalFrameTiming -= _frameTiming.front();
_frameTiming.pop_front();
}
_totalFrameTiming += _elapsed;
_frameTiming.push_back(_elapsed);
}
示例14: puts
void ServerHost::run( int port )
{
RakNet::SocketDescriptor socketDescriptors;
socketDescriptors.port=port;
socketDescriptors.socketFamily=AF_INET; // Test out IPV4
m_server->SetMaximumIncomingConnections(400);
// Try again, but leave out IPV6
bool b = m_server->Startup(400, &socketDescriptors, 1 )==RakNet::RAKNET_STARTED;
if (!b)
{
puts("Server failed to start. Terminating.");
exit(1);
}
m_server->SetTimeoutTime(10000,RakNet::UNASSIGNED_SYSTEM_ADDRESS);
m_server->SetOccasionalPing(true);
//m_server->SetUnreliableTimeout(1000);
prerun(port);
RakNet::TimeMS time0 = RakNet::GetTimeMS();
while(true)
{
doTick();
runtick();
RakSleep(30);
RakNet::TimeMS time1 = RakNet::GetTimeMS();
RakNet::TimeMS difference = time1 - time0;
if(difference >= 1000)
{
time0 = RakNet::GetTimeMS();
tick();
}
}
postrun();
}
示例15: while
void ManyClientsOneServerDeallocateBlockingTest::WaitForConnectionRequestsToComplete(RakPeerInterface **clientList, int clientNum, bool isVerbose)
{
SystemAddress currentSystem;
bool msgWasPrinted=false;
for (int i=0;i<clientNum;i++)
{
currentSystem.SetBinaryAddress("127.0.0.1");
currentSystem.port=60000;
while (clientList[i]->IsConnectionAttemptPending (currentSystem) )
{
if (msgWasPrinted==false)
{
printf("Waiting for connection requests to complete.\n");
msgWasPrinted=true;
}
RakSleep(30);
}
}
}