void testmassiveclassification::defineClasses(int ClassCount) { string strRand ; char * className; int i; mLogger.out()<<endl<<"Defining "<<COUNT_CLASS<< " classes."<<std::flush; long const lBef = getTimeInMs(); for(i=0;i<ClassCount;i++) { MVTRand::getString( strRand, 20, 0 ) ; char lB[64]; sprintf(lB, "%d.massive.class.%s", i,strRand.c_str()); className=lB; IStmt *lClassQ=mSession->createStmt() ; unsigned char lVar = lClassQ->addVariable() ; Value ops[1] ; ops[0].setVarRef(0, mProp[i] ) ; IExprNode *lE=mSession->expr(OP_EXISTS, 1, ops ) ; lClassQ->addCondition( lVar, lE ) ; TVERIFYRC(defineClass(mSession, lB, lClassQ )); lClassQ->destroy(); lE->destroy(); if(!(i%100)) std::cout<<"."<<std::flush; } mDefineTime = getTimeInMs()-lBef ; mLogger.out()<<endl<<"Defining "<<COUNT_CLASS<< " classes done!"; }
void testmassiveclassification::createPins(int PinCount) { int i,j; //Value tValue[mLargeClass+1]; Value* tValue = NULL; tValue = (Value*) mSession->malloc(sizeof(Value)*(mLargeClass+1)); std::cout<<endl<<"Creating "<<PinCount<< " pins."<<std::flush; long lBef = getTimeInMs(); for(i=0;i<PinCount;i++) { for(j=0;j<mLargeClass;j++) { tValue[j].set(j); tValue[j].property=mProp[j]; } tValue[j].set(j); tValue[j].property=mProp[j+(i%COUNT_PROP-mLargeClass)]; TVERIFYRC(mSession->createPIN(tValue,j+1,NULL,MODE_COPY_VALUES|MODE_PERSISTENT)); if(!(i%100)) std::cout<<"."<<std::flush; if(!((i+1)%1000)) mPinTime[(i+1)/1000] = getTimeInMs()-lBef ; //Calculating time taken for each 1000 pins } mPinTimeTotal = getTimeInMs()-lBef; std::cout<<endl<<"Creating "<<PinCount<< " pins : done!"; mSession->free(tValue); }
void TestUndelete::test(IStmt *pQuery) { uint64_t lActualCount = 0, lDeleteCount = 0, lAftDeleteCount = 0, lAftUndeleteCount = 0; std::vector<PID> lDeletedPINs; pQuery->count(lActualCount); ICursor *lR = NULL; TVERIFYRC(pQuery->execute(&lR)); if(lR) { PID lPID = {STORE_INVALID_PID, STORE_OWNER}; while(RC_OK == lR->next(lPID)) { if(MVTRand::getBool()) { TVERIFYRC(mSession->deletePINs(&lPID, 1)); lDeletedPINs.push_back(lPID); } } lR->destroy(); lR = NULL; } uint64_t lNumDeletePINs = lDeletedPINs.size(); long const lCountStartTime = getTimeInMs(); pQuery->count(lDeleteCount, NULL, 0, ~0, MODE_DELETED); long const lCountEndTime = getTimeInMs(); mLogger.out() << "Num of Deleted PINs :: " << lDeleteCount << ", Time taken to IStmt::count() on deleted PINs :: " << (lCountEndTime - lCountStartTime) << " ms" << std::endl; TVERIFY(lNumDeletePINs == lDeleteCount && "More/Less PINs returned after delete"); pQuery->count(lAftDeleteCount); TVERIFY((lActualCount-lNumDeletePINs) == lAftDeleteCount && "Deleted PINs not returned in query"); long const lResultStartTime = getTimeInMs(); TVERIFYRC(pQuery->execute(&lR, 0, 0, ~0, 0, MODE_DELETED)); unsigned long lIResultCount = 0; if(lR) { PID lPID = {STORE_INVALID_PID, STORE_OWNER}; while(RC_OK == lR->next(lPID)) lIResultCount++; lR->destroy(); } else TVERIFY(false && "Failed to return ICursor"); long const lResultEndTime = getTimeInMs(); mLogger.out() << "Num of Deleted PINs :: " << lIResultCount << ", Time taken to Iterate thro ICursor::next(&PID) on deleted PINs :: " << (lResultEndTime - lResultStartTime) << " ms" << std::endl; TVERIFY(lIResultCount == lNumDeletePINs && "ICursor->next() did not return any/all pins"); undeletePINs(2, &lDeletedPINs[0], int(lNumDeletePINs)); pQuery->count(lDeleteCount, NULL, 0, ~0, MODE_DELETED); TVERIFY(lDeleteCount == 0 && "Not all PINs were undeleted"); pQuery->count(lAftUndeleteCount); TVERIFY(lActualCount == lAftUndeleteCount && "Not all PINs were undeleted"); lDeletedPINs.clear(); undeletePINs(2, &mPIDs[0], sNumPINs); }
int CInConnection::_receiveSimplePacket(std::vector<char>& packet) { _socketTimeOut.tv_sec=10; // 1 second max between successive receive for the same packet _socketTimeOut.tv_usec=0; FD_ZERO(&_socketTheSet); FD_SET(_socketClient,&_socketTheSet); #ifdef _WIN32 int selectResult=select(0,&_socketTheSet,NULL,NULL,&_socketTimeOut); #endif /* _WIN32 */ #if defined (__linux) || defined (__APPLE__) int selectResult=select(_socketClient+1, &_socketTheSet,NULL,NULL,&_socketTimeOut); #endif /* __linux || __APPLE__ */ if (selectResult==1) { //1. Read the header and packet size: char headerAndSize[HEADER_LENGTH]; int totalReceived=0; DWORD startT=getTimeInMs(); while(totalReceived!=HEADER_LENGTH) { int nb=recv(_socketClient,headerAndSize+totalReceived,HEADER_LENGTH-totalReceived,0); if (nb<1) break; totalReceived+=nb; if (getTimeDiffInMs(startT)>SOCKET_TIMEOUT_READ) break; } // 2. Check if the header is consistent: if (totalReceived!=HEADER_LENGTH) return(-2); // Error reading _otherSideIsBigEndian=(((WORD*)headerAndSize)[0]!=1); WORD dataLength=littleEndianShortConversion(((WORD*)headerAndSize)[1],_otherSideIsBigEndian); // 3. Read the data with correct length: packet.clear(); packet.resize(dataLength,0); totalReceived=0; startT=getTimeInMs(); while(totalReceived!=dataLength) { int nb=recv(_socketClient,&packet[0]+totalReceived,dataLength-totalReceived,0); if (nb<1) break; totalReceived+=nb; if (getTimeDiffInMs(startT)>SOCKET_TIMEOUT_READ) break; } if (totalReceived!=dataLength) return(-2); // wrong size or nothing received return(int(littleEndianShortConversion(((WORD*)headerAndSize)[2],_otherSideIsBigEndian))); } if (selectResult==0) return(-1); return(-2); }
void TestUndelete::testClass() { IStmt *lQ = getQuery(2); long const lStartTime = getTimeInMs(); test(lQ); long const lEndTime = getTimeInMs(); mLogger.out() << "Time taken for testClass() :: " << (lEndTime - lStartTime) << " ms" << std::endl; lQ->destroy(); }
int CSimpleInConnection::_receiveSimplePacket(std::vector<char>& packet) { // Returns the number of packets left to read if >=0, -2=error, -1=select time out _socketTimeOut.tv_sec=10; // 1 second max between successive receive for the same packet _socketTimeOut.tv_usec=0; FD_ZERO(&_socketTheSet); FD_SET(_socketClient,&_socketTheSet); #ifdef _WIN32 int selectResult=select(0,&_socketTheSet,NULL,NULL,&_socketTimeOut); #endif /* _WIN32 */ #if defined (__linux) || defined (__APPLE__) int selectResult=select(_socketClient+1, &_socketTheSet,NULL,NULL,&_socketTimeOut); #endif /* __linux || __APPLE__ */ if (selectResult==1) { //1. Read the header and packet size: char headerAndSize[HEADER_LENGTH]; int totalReceived=0; DWORD startT=getTimeInMs(); while(totalReceived!=HEADER_LENGTH) { int nb=recv(_socketClient,headerAndSize+totalReceived,HEADER_LENGTH-totalReceived,0); if (nb<1) break; totalReceived+=nb; if (getTimeDiffInMs(startT)>3000) break; } // 2. Check if the header is consistent: if (totalReceived!=HEADER_LENGTH) return(-2); // Error reading if ( (headerAndSize[0]!=_headerByte1)||(headerAndSize[1]!=_headerByte2) ) return(-2); // Error, wrong header WORD dataLength=((WORD*)(headerAndSize+2))[0]; // 3. Read the data with correct length: packet.clear(); packet.resize(dataLength,0); totalReceived=0; startT=getTimeInMs(); while(totalReceived!=dataLength) { int nb=recv(_socketClient,&packet[0]+totalReceived,dataLength-totalReceived,0); if (nb<1) break; totalReceived+=nb; if (getTimeDiffInMs(startT)>3000) break; } if (totalReceived!=dataLength) return(-2); // wrong size or nothing received return(int(((WORD*)(headerAndSize+2))[1])); } if (selectResult==0) return(-1); return(-2); }
void TestUndelete::testFullScan() { Value lV[1]; lV[0].set(mQueryStr.c_str()); IStmt *lQ = getQuery(1, mPropIDs[2], lV); long const lStartTime = getTimeInMs(); test(lQ); long const lEndTime = getTimeInMs(); mLogger.out() << "Time taken for testFullScan() :: " << (lEndTime - lStartTime) << " ms" << std::endl; lQ->destroy(); }
DWORD getTimeDiffInMs(DWORD lastTime) { DWORD currentTime=getTimeInMs(); if (currentTime<lastTime) return(currentTime+0x03ffffff-lastTime); return(currentTime-lastTime); }
void* CSimxSocket::_run() { _commThreadLaunched=true; connection=NULL; while (_commThreadLaunched) { connection=new CInConnection(_portNb,_maxPacketSize,useAlternateSocketRoutines); if (_debug) { // We do this in a funny way since we should not access V-REP from a thread not created in V-REP! _lock(); _textToPrintToConsole.push_back("connecting to client...\n"); _unlock(); } //printf("Trying to connect...\n"); if (connection->connectToClient()) { //printf("Connected!\n"); clientIsConnected=true; _lock(); _receivedCommands->clearAll(); _dataToSend->clearAll(); _unlock(); int _lastLastReceivedMessage_time=0; if (_debug) { // We do this in a funny way since we should not access V-REP from a thread not created in V-REP! _lock(); // we are not locked here! _textToPrintToConsole.push_back("connected to client.\n"); _unlock(); } while (_commThreadLaunched) { int dataSize; //printf("Trying to read...\n"); char* data=connection->receiveMessage(dataSize); if (dataSize>0) { // we received some data. The server ALWAYS replies! //printf("Read successful!\n"); _lastReceivedMessage_time=getTimeInMs(); _successiveReception_time=_lastReceivedMessage_time-_lastLastReceivedMessage_time; _lastLastReceivedMessage_time=_lastReceivedMessage_time; otherSideIsBigEndian=connection->isOtherSideBigEndian(); // a) check the CRC: WORD crc=littleEndianWordConversion(((WORD*)(data+simx_headeroffset_crc))[0],otherSideIsBigEndian); _lock(); _lastReceivedMessage_cmdCnt=0; bool killConnectionCommand=false; // CRC calculation represents a bottleneck for large transmissions, and is anyway not needed with tcp or shared memory transmissions // if (getCRC(data+2,dataSize-2)==crc) if (true) { _lastReceivedMessage_clientVersion=data[simx_headeroffset_version]; _receivedCommands->setOtherSideIsBigEndian(otherSideIsBigEndian); _dataToSend->setOtherSideIsBigEndian(otherSideIsBigEndian); int messageID=littleEndianIntConversion(((int*)(data+simx_headeroffset_message_id))[0],otherSideIsBigEndian); int timeStamp=littleEndianIntConversion(((int*)(data+simx_headeroffset_client_time))[0],otherSideIsBigEndian); _receivedCommands->setMessageID(messageID); _receivedCommands->setDataTimeStamp(timeStamp); if (_debug) { // We do this in a funny way since we should not access V-REP from a thread not created in V-REP! // resources are already locked here, no need to lock a second time! std::stringstream strStream; strStream << "data received: " << dataSize << " bytes (message ID = " << messageID << ")\n"; _textToPrintToConsole.push_back(strStream.str()); } int off=SIMX_HEADER_SIZE; while (off<dataSize) { int cmdSize=littleEndianIntConversion(((int*)(data+off+simx_cmdheaderoffset_mem_size))[0],otherSideIsBigEndian); int fullCmdSize=littleEndianIntConversion(((int*)(data+off+simx_cmdheaderoffset_full_mem_size))[0],otherSideIsBigEndian); if (cmdSize!=fullCmdSize) { char* fullCommand=_receivedCommands->addPartialCommand(data+off,otherSideIsBigEndian); if (fullCommand!=NULL) { int localCmdSize=littleEndianIntConversion(((int*)(fullCommand+simx_cmdheaderoffset_mem_size))[0],otherSideIsBigEndian); int cmd=littleEndianIntConversion(((int*)(fullCommand+simx_cmdheaderoffset_cmd))[0],otherSideIsBigEndian); killConnectionCommand=(cmd==simx_cmd_kill_connection); BYTE options=fullCommand[simx_cmdheaderoffset_status]; // bit0 set: do not overwrite this command! WORD delayOrSplit=littleEndianWordConversion(((WORD*)(fullCommand+simx_cmdheaderoffset_delay_or_split))[0],otherSideIsBigEndian); CSimxCmd* newCmd=new CSimxCmd(cmd,delayOrSplit,localCmdSize-SIMX_SUBHEADER_SIZE,fullCommand+SIMX_SUBHEADER_SIZE); _receivedCommands->addCommand(newCmd,options&1); delete[] fullCommand; } } else { int cmd=littleEndianIntConversion(((int*)(data+off+simx_cmdheaderoffset_cmd))[0],otherSideIsBigEndian); killConnectionCommand=(cmd==simx_cmd_kill_connection); BYTE options=data[off+simx_cmdheaderoffset_status]; // bit0 set: do not overwrite this command! WORD delayOrSplit=littleEndianWordConversion(((WORD*)(data+off+simx_cmdheaderoffset_delay_or_split))[0],otherSideIsBigEndian); CSimxCmd* newCmd=new CSimxCmd(cmd,delayOrSplit,cmdSize-SIMX_SUBHEADER_SIZE,data+off+SIMX_SUBHEADER_SIZE); _receivedCommands->addCommand(newCmd,options&1); } off+=cmdSize; _lastReceivedMessage_cmdCnt++; } } else { if (_debug) { // We do this in a funny way since we should not access V-REP from a thread not created in V-REP! // resources are already locked here, no need to lock a second time! _textToPrintToConsole.push_back("data received: error (crc failed)\n"); } } delete[] data; // Prepare the reply: std::vector<char> replyData; _lastSentMessage_cmdCnt=_dataToSend->getDataString(replyData,otherSideIsBigEndian); _lastSentMessage_cmdCnt+=_receivedCommands->getDataStringOfSplitOrGradualCommands(replyData,otherSideIsBigEndian); int messageIdToSend=_dataToSend->getMessageID(); _dataToSend->clearAll(); _unlock(); // send the reply, but first add the CRC: // CRC calculation represents a bottleneck for large transmissions, and is anyway not needed with tcp or shared memory transmissions // crc=getCRC(&replyData[2],int(replyData.size()-2)); crc=0; ((WORD*)&replyData[simx_headeroffset_crc])[0]=littleEndianWordConversion(crc,otherSideIsBigEndian); //printf("Trying to write...\n"); if (!connection->replyToReceivedMessage(&replyData[0],(int)replyData.size())) { //printf("Write NOT successful!\n"); if (_debug) { // We do this in a funny way since we should not access V-REP from a thread not created in V-REP! _lock(); // important to lock resources! _textToPrintToConsole.push_back("failed sending reply.\n"); _unlock(); } break; } else { //printf("Write successful!\n"); _lastSentMessage_time=getTimeInMs(); if (_debug) { // We do this in a funny way since we should not access V-REP from a thread not created in V-REP! _lock(); // important to lock resources! std::stringstream strStream; strStream << "reply sent: " << replyData.size() << " bytes (message ID = " << messageIdToSend << ")\n"; _textToPrintToConsole.push_back(strStream.str()); _unlock(); } } if (killConnectionCommand) break; // since 13/12/2013 } else { //printf("Read NOT successful!\n"); // commented on 13/12/2013 // if (dataSize==-1) { if (_debug) { // We do this in a funny way since we should not access V-REP from a thread not created in V-REP! _lock(); // important to lock resources! _textToPrintToConsole.push_back("error while receiving data.\n"); _unlock(); } break; } } } if (_debug) { // We do this in a funny way since we should not access V-REP from a thread not created in V-REP! _lock(); // important to lock resources! _textToPrintToConsole.push_back("disconnected from client.\n"); _unlock(); } _lock(); _receivedCommands->clearAll(); _unlock(); clientIsConnected=false; _waitForTrigger=true; _waitForTriggerFunctionEnabled=false; } else { //printf("Failed connecting!\n"); Sleep(2000); // 13/12/2013 if (_debug) { // We do this in a funny way since we should not access V-REP from a thread not created in V-REP! _lock(); // important to lock resources! _textToPrintToConsole.push_back("failed connecting to client.\n"); _unlock(); } } delete connection; connection=NULL; Sleep(500); // important, otherwise it reconnects directly. 600 is already too much on some systems somehow. To fix. } _commThreadLaunched=false; _commThreadEnded=true; // confirmation that is needed return(NULL); }
void CSimxSocket::_stop() { // Terminate the communication thread if needed: if (_commThreadLaunched) { connection->stopWaitingForConnection(); _commThreadLaunched=false; // signal the thread we wanna end // First try if we can bring the communication thread to an end: DWORD startT=getTimeInMs(); while (getTimeDiffInMs(startT)<20) { Sleep(1); if (_commThreadEnded) break; // this usually happens when a client was connected and the communication was running } if (!_commThreadEnded) { // no, the communication thread is probably waiting for a connection (blocked while accepting) // Make a fake connection to this socket, to unblock it (the thread might be trapped in the "accept" function) if (_portNb>=0) { // sockets struct hostent *hp; unsigned int addr; struct sockaddr_in _socketServer; #ifdef _WIN32 WSADATA _socketWsaData; if (WSAStartup(0x101,&_socketWsaData)==0) #endif // _WIN32 { _SOCKET _socketConn=socket(AF_INET,SOCK_STREAM,IPPROTO_TCP); if(_socketConn!=INVALID_SOCKET) { addr=inet_addr("127.0.0.1"); hp=gethostbyaddr((char*)&addr,sizeof(addr),AF_INET); if(hp!=NULL) { _socketServer.sin_addr.s_addr=*((unsigned long*)hp->h_addr); _socketServer.sin_family=AF_INET; _socketServer.sin_port=htons(_portNb); connect(_socketConn,(struct sockaddr*)&_socketServer,sizeof(_socketServer)); } #ifdef _WIN32 closesocket(_socketConn); #elif defined (__linux) || defined (__APPLE__) close(_socketConn); #endif // _WIN32 } #ifdef _WIN32 WSACleanup(); #endif // _WIN32 } } // Now wait until the thread signals that it ended (or we reached a timeout: that probably happens when a firewall forbids self-connections) startT=getTimeInMs(); while (getTimeDiffInMs(startT)<1000) { Sleep(1); if (_commThreadEnded) break; // ok, the thread ended } } } // Do some other clean-up: _receivedCommands->clearAll(); _dataToSend->clearAll(); }