Пример #1
0
void ClientData::searchAccount()
 {
	ifstream indatabase("ATM.txt", ios::in | ios::binary);

// exit program if ifstream cannot open file
if (!indatabase )
 {
 cerr << "File could not be opened." << endl;
 exit( 1 );
 } // end if

 cout << left << setw( 10 ) << "Account" << setw( 16 )
<< setw( 11 ) << "User Name" << left
 << setw( 10 ) << right << "Balance" << endl;

 ClientData database; // create record

indatabase.read(reinterpret_cast< char *>(&database),
   sizeof(ClientData));

// read all records from fil e
while (indatabase && !indatabase.eof() )
{
  // display record
 
 if ( database.getAccountNumber() != 0 )
     //outputLine(cout, client);

  indatabase.read(reinterpret_cast < char *>(&database),
        sizeof(ClientData));
  
} // end while
} // end search record
Пример #2
0
/* virtual */ SysStatus
ServerFileVirtFSTmp<T>::open(uval oflag, ProcessID pid, ObjectHandle &oh,
			  uval &ut, TypeID &type)
{
    SysStatus rc;
    FileLinux::Stat stat;

    rc = getStatus(&stat);
    if (_FAILURE(rc)) { return rc; }

    fileLength = 0;

    // FIXME get rights correct
    rc = giveAccessByServer(oh, pid,
			    MetaObj::read|MetaObj::write|
			    MetaObj::controlAccess,
			    MetaObj::none);
    if (_FAILURE(rc)) { return rc; }

    // now get xhandle and initialize
    XHandle xh = oh._xhandle;
    ClientData *cd = VClnt(xh);
    cd->flags = oflag;
    cd->filePosition = 0;
    cd->isSharingOffset = 0;
    cd->useType = FileLinux::FIXED_SHARED;
    cd->token = token;
    // at this point, nothing can fail, so no need to free anything
    type = FileLinux_VIRT_FILE;

    ut = useType = FileLinux::FIXED_SHARED;
    return DREF(obj)->_open(oflag, cd->userData(), cd->token);
}
Пример #3
0
void Application::Admin_select()
{
	y -= 3;
	ClientData data;	// 고객 정보 임시 저장장소
	account temp;	// 계좌 임시 저장소
	switch(y)
	{
	case 1:
		data.GetClientData();		// 고객 정보 입력
		m_ClientList.InsertItem(data); // 고객 추가 함수
		data.PutClientData();	// 고객 정부 화면 출력
		break;
	case 2:
		DeleteClient();	// 고객 리스트 제거 함수
		break;
	case 3:
		if(!SearchList(data))	// 고객 검색
			break;
		data.PutClientData();	// 고객정보 화면에 띄우기
		break;
	case 4:
		OpenAccount();	// 계좌 열기
		break;
	case 5:
		if(!SearchList(data))	// 고객 검색
			break;
		data.CloseAccount();
		break;
	case 6:
		return;
	}
}
Пример #4
0
void Application::Client_select()
{
	ClientData data;
	y -= 3;
	switch(y)
	{
	case 1:
		CW.AddCW();
		break;
	case 2:
		InputMoney();
		break;
	case 3:
		OutputMoney();
		break;
	case 4:
		BorrowMoney();
		break;
	case 5:
		InputMoney();
		break;
	case 6:
		if(!SearchList(data))
			break;
		data.ApartApplication();
		break;
	case 7:
		return;
	}
}
Пример #5
0
// create formatted text file for printing
void createTextFile(fstream &readFromFile)
{
	// create text file
	ofstream outPrintFile("print.txt", ios::out);

	// exit program if ofstream cannot create file
	if (!outPrintFile)
	{
		cerr << "File could not be created" << endl;
		exit(1);
	} // end if

	outPrintFile << left << setw(10) << "Account" << setw(16)
		<< "Last name" << setw(11) << "First Name" << right << setw(10)
		<< "Balance" << endl;

	// ** SET FILE POSITION POINTER TO BEGINNING OF readFromFile
	readFromFile.seekg(0);

	// read first record from record file
	ClientData client;
	readFromFile.read( reinterpret_cast<char *>(&client), sizeof ( ClientData) );

	// copy all records from record file into text file
	while (!readFromFile.eof() ) // While not the end of file
	{
		// Write single record to text file
		if (client.getAccountNumber() != 0) // skip empty records
			outputLine(outPrintFile, client);

		// read next record from record file
		readFromFile.read(reinterpret_cast<char * >(&client), sizeof( ClientData ) );
	} // end while
} // end function createTextFile
Пример #6
0
/* virtual */ SysStatus
MemTrans::_swapHandle(ObjectHandle callerMT, //Caller's MT
		      ObjectHandle callerFR, //Caller's FR
		      uval callerSize,	     //Size of region
		      uval& sizeRemote,
		      ObjectHandle &remoteFR,
		      __XHANDLE xhandle,
		      __CALLER_PID pid)
{
    ClientData *cd = clnt(xhandle);
    tassertMsg(cd,"No clientData defined\n");
    uval addr=0;
    SysStatus rc = 0;

    rc = StubRegionDefault::_CreateFixedLenExt(
	addr, callerSize, 0, callerFR, 0, AccessMode::writeUserWriteSup, 0,
	RegionType::K42Region);

    ObjectHandle frOH;
    if (_SUCCESS(rc)) {
	cd->init(callerFR, callerMT, addr, callerSize);

	rc = localFR._giveAccess(frOH, pid);

    } else {
	return rc;
    }


    remoteFR = frOH;
    sizeRemote = callerSize;


    return rc;
}
Пример #7
0
int main()
{
   ifstream inCredit( "credit.dat", ios::in | ios::binary );

   // exit program if ifstream cannot open file
   if ( !inCredit ) 
   {
      cerr << "File could not be opened." << endl;
      exit( 1 );
   } // end if

   cout << left << setw( 10 ) << "Account" << setw( 16 )
      << "Last Name" << setw( 11 ) << "First Name" << left
      << setw( 10 ) << right << "Balance" << endl;

   ClientData client; // create record

   // read first record from file
   inCredit.read( reinterpret_cast< char * >( &client ), 
      sizeof( ClientData ) );

   // read all records from file
   while ( inCredit && !inCredit.eof() ) 
   {
      // display record
      if ( client.getAccountNumber() != 0 )
         outputLine( cout, client );

      // read next from file
      inCredit.read( reinterpret_cast< char * >( &client ),
         sizeof( ClientData ) );
   } // end while
} // end main
Пример #8
0
// update balance in record
void updateRecord( fstream &updateFile )
{
   // obtain number of account to update
   int accountNumber = getAccount( "Enter account to update" );

   // move file-position pointer to correct record in file
   updateFile.seekg( ( accountNumber - 1 ) * sizeof( ClientData ) );

   // read first record from file
   ClientData client;
   updateFile.read( reinterpret_cast< char * >( &client ), 
      sizeof( ClientData ) );

   // update record
   if ( client.getAccountNumber() != 0 ) 
   {
      outputLine( cout, client ); // display the record

      // request user to specify transaction
      cout << "\nEnter charge (+) or payment (-): ";
      double transaction; // charge or payment
      cin >> transaction;

      // update record balance
      double oldBalance = client.getBalance();
      client.setBalance( oldBalance + transaction );
      outputLine( cout, client ); // display the record

      // move file-position pointer to correct record in file
      updateFile.seekp( ( accountNumber - 1 ) * sizeof( ClientData ) );

      // write updated record over old record in file
      updateFile.write( reinterpret_cast< const char * >( &client ), 
         sizeof( ClientData ) );
   } // end if
Пример #9
0
int callbackPacketInvalid(Packet& p)
{
	ClientData* cd = PolypeerClient::getInstance()->getClientData();
	//cout << "callbackPacketInvalid" << endl;
	cd->getConnectionManager()->sendTo(cd->getAddressServ(), PacketMd5Error(-1, -1));
	return 1;
}
void ReflectStlVectorInterpreter::OnMoveDown( const ButtonClickedArgs& args )
{
    Reflect::ObjectPtr clientData = args.m_Control->GetClientData();
    if ( clientData.ReferencesObject() && clientData->IsClass( Reflect::GetClass<ClientData>() ) )
    {
        ClientData* data = static_cast< ClientData* >( clientData.Ptr() );
        List* list = static_cast< List* >( data->GetControl() );
        std::set< size_t > selectedItemIndices = list->a_SelectedItemIndices.Get();
        if ( !selectedItemIndices.empty() )
        {
            // for each array in the selection set (the objects the array data is connected to)
            std::vector< DataPtr >::const_iterator serItr = m_Datas.begin();
            std::vector< DataPtr >::const_iterator serEnd = m_Datas.end();
            for ( ; serItr != serEnd; ++serItr )
            {
                Reflect::StlVectorData* arrayData = Reflect::AssertCast<Reflect::StlVectorData>(*serItr);

                arrayData->MoveDown( selectedItemIndices );
            }

            list->a_SelectedItemIndices.Set( selectedItemIndices );

            args.m_Control->GetCanvas()->Read();
        }
    }
}
Пример #11
0
///////////////////////////////////////////////////////////////////////////////
// Callback for when the remove button is pressed.  If there are any items 
// selected in the list control, they will be removed from the list.
// 
void ReflectStlSetInterpreter::OnRemove( const ButtonClickedArgs& args )
{
    Reflect::ObjectPtr clientData = args.m_Control->GetClientData();
    if ( clientData.ReferencesObject() && clientData->IsClass( Reflect::GetClass<ClientData>() ) )
    {
        ClientData* data = static_cast< ClientData* >( clientData.Ptr() );
        List* list = static_cast< List* >( data->GetControl() );
        const std::set< size_t >& selectedItemIndices = list->a_SelectedItemIndices.Get();
        if ( !selectedItemIndices.empty() )
        {
            // for each item in the array to remove (by index)
            std::set< size_t >::const_reverse_iterator itr = selectedItemIndices.rbegin();
            std::set< size_t >::const_reverse_iterator end = selectedItemIndices.rend();
            for ( ; itr != end; ++itr )
            {
                // for each array in the selection set (the objects the array data is connected to)
                std::vector< DataPtr >::const_iterator serItr = m_Datas.begin();
                std::vector< DataPtr >::const_iterator serEnd = m_Datas.end();
                for ( ; serItr != serEnd; ++serItr )
                {
                    Reflect::StlSetData* setData = Reflect::AssertCast<Reflect::StlSetData>(*serItr);
                    std::vector< DataPtr > items;
                    setData->GetItems( items );
                    setData->RemoveItem( items[ *itr ] );
                }
            }

            list->a_SelectedItemIndices.Set( std::set< size_t > () );

            args.m_Control->GetCanvas()->Read();
        }
    }
}
Пример #12
0
// display single record
void outputLine( ostream &output, const ClientData &record )
{
   output << left << setw( 10 ) << record.getAccountNumber()
      << setw( 16 ) << record.getLastName()
      << setw( 11 ) << record.getFirstName()
      << setw( 10 ) << setprecision( 2 ) << right << fixed 
      << showpoint << record.getBalance() << endl;
} // end function outputLine
Пример #13
0
void FawnKVServerHandler::remove(const std::string& key, const int64_t continuation, const int32_t cid) {
    // Generating unique server-side continuation
    int64_t ss_continuation = reqNumber++;
    ClientData *cd = get_client(cid);
    cd->addContinuation(continuation, ss_continuation);
    req_client_map[ss_continuation] = cd;
    pthread_mutex_lock(p_mutex);
    frontend->remove(key, ss_continuation);
    pthread_mutex_unlock(p_mutex);
}
Пример #14
0
/*====================================================================================
// Function : show all list data.s
// Pre		: none
// Post		: none
=====================================================================================*/
void Application::ShowList()
{
	ClientData temp;
	m_ClientList.ResetList();
	m_ClientList.GetCurrentItem(temp);
	for(int i=0; i<m_ClientList.LengthIs();i++)
	{
		m_ClientList.GetCurrentItem(temp);
		temp.PutClientData();
	}
}
Пример #15
0
///////////////////////////////////////////////////////////////////////////////
// Callback for when the add button is pressed.  Displays a dialog that lets
// you enter a new key-value pair.  If you enter a key that already exists in
// the list, you will be asked if you want to replace it or not.
// 
void ReflectStlSetInterpreter::OnAdd( const ButtonClickedArgs& args )
{
    Reflect::ObjectPtr clientData = args.m_Control->GetClientData();
    if ( clientData.ReferencesObject() && clientData->IsClass( Reflect::GetClass<ClientData>() ) )
    {
        ClientData* data = static_cast< ClientData* >( clientData.Ptr() );
        List* list = static_cast< List* >( data->GetControl() );
        list->e_AddItem.Raise( AddItemArgs() );
        args.m_Control->GetCanvas()->Read();
    }
}
Пример #16
0
/*====================================================================================
// Function : write all Clients information to file.
// Pre		: file is opened.
// Post		: create or update a file that has all Clients information in file.
=====================================================================================*/
void Application::PutClientListToFile()
{
	ClientData temp;					//출력하고하는 부품 타입
	m_ClientList.ResetList();			//부품 리스트 초기화
	m_ClientList.GetCurrentItem(temp);
	for(int i=1; i<m_ClientList.LengthIs()-1;i++)		
	{
		m_ClientList.GetCurrentItem(temp);		//파일 끝까지 currentPos 이동
		temp.PutRecordToFile(m_ListOutFile);
	}
	m_ListOutFile.close();
}
Пример #17
0
void Application::OpenAccount()
{
	ClientData data;
	ClientData data2;
	account temp;
	account temp2;
	if(!SearchList(data))
		return;
	data2.Copy(data);
	temp.Getaccount(data.GetCredit());
	data.Account.InsertItem(temp);
	m_ClientList.DeleteItem(data2);
	m_ClientList.InsertItem(data);
}
Пример #18
0
ClientData* ClientData::tryAddClient(ClientSession* clientInfo,
                                     const std::string& account,
                                     uint32_t accoundId,
                                     uint32_t age,
                                     uint32_t event_code,
                                     uint32_t pcBang,
                                     const char ip[INET6_ADDRSTRLEN],
                                     ClientData** oldClientPtr) {
	std::pair<std::unordered_map<uint32_t, ClientData*>::iterator, bool> result;
	std::pair<std::unordered_map<std::string, ClientData*>::iterator, bool> resultForName;
	ClientData* newClient;

	if(oldClientPtr)
		*oldClientPtr = nullptr;

	uv_mutex_lock(&mapLock);

	newClient = new ClientData(clientInfo);
	result = connectedClients.insert(std::pair<uint32_t, ClientData*>(accoundId, newClient));
	if(result.second == false) {
		ClientData* oldClient = result.first->second;
		delete newClient;
		newClient = nullptr;

		if(oldClientPtr)
			*oldClientPtr = oldClient;
	} else {
		newClient->account = account;
		newClient->accountId = accoundId;
		newClient->age = age;
		newClient->eventCode = event_code;
		newClient->pcBang = pcBang;
		memcpy(newClient->ip, ip, INET6_ADDRSTRLEN);
		resultForName = connectedClientsByName.insert(std::pair<std::string, ClientData*>(toLower(account), newClient));
		if(resultForName.second == false) {
			newClient->log(LL_Error, "Duplicated account name with different ID: %s\n", account.c_str());
			if(oldClientPtr)
				*oldClientPtr = resultForName.first->second;
			connectedClients.erase(result.first);
			delete newClient;
			newClient = nullptr;
		}
	}

	uv_mutex_unlock(&mapLock);

	return newClient;
}
Пример #19
0
void ClientData::removeServer(GameData* server) {
	std::unordered_map<uint32_t, ClientData*>::const_iterator it, itEnd;

	uv_mutex_lock(&mapLock);
	for(it = connectedClients.begin(), itEnd = connectedClients.end(); it != itEnd;) {
		ClientData* client = it->second;
		if(client->getGameServer() == server) {
			connectedClientsByName.erase(toLower(client->account));
			it = connectedClients.erase(it);
			delete client;
		} else {
			++it;
		}
	}
	uv_mutex_unlock(&mapLock);
}
Пример #20
0
void get_cb(const DBID& p_key, const string& p_value, unsigned int continuation, bool success)
{
    pthread_mutex_lock(p_mutex);
    //cout << "get_cb for " << continuation << endl;
    ClientData *cd = req_client_map[continuation];
    int64_t cli_continuation = cd->getContinuation(continuation);
    cd->removeContinuation(continuation);

    // Send to client
    cd->fc->get_response(p_value, cli_continuation);

    //if (cache)
    //    cache->insert(p_key, p_value);
    //cout << "get_cb done for " << continuation << endl;
    pthread_mutex_unlock(p_mutex);
}
Пример #21
0
void put_cb(unsigned int continuation)
{
    // continuation is the server-side continuation
    // Need to map back to client continuation

    pthread_mutex_lock(p_mutex);
    //cout << "put_cb for " << continuation << endl;
    ClientData *cd = req_client_map[continuation];
    int64_t cli_continuation = cd->getContinuation(continuation);
    cd->removeContinuation(continuation);

    // Send to client
    cd->fc->put_response(cli_continuation);
    //cout << "put_cb done for " << continuation << endl;
    pthread_mutex_unlock(p_mutex);
}
Пример #22
0
void FawnKVServerHandler::put(const std::string& key, const std::string& value, const int64_t continuation, const int32_t cid) {
    pthread_mutex_lock(p_mutex);
    // Generating unique server-side continuation
    int64_t ss_continuation = reqNumber++;
    //cout << "Put from CID: " << cid << " continuation: " << continuation << " reqNumber: " << ss_continuation << endl;
    ClientData *cd = get_client(cid);
    cd->addContinuation(continuation, ss_continuation);
    req_client_map[ss_continuation] = cd;
    string v = value;
    frontend->put(key, value, ss_continuation);
    DBID dkey(key);
    if (cache)
        cache->insert(dkey, value);
    //cout << "Put Done for CID: " << cid << " continuation: " << continuation << " reqNumber: " << ss_continuation << endl;
    pthread_mutex_unlock(p_mutex);

}
Пример #23
0
/*====================================================================================
// Function : search the Clients information in list.
// Pre		: list has to have one Clients at least.
// Post		: display the Clients information if found.
=====================================================================================*/
void Application::BorrowMoney()
{
	ClientData data;
	ClientData data2;
	account temp;
	account temp2;
	if(!SearchList(data))
		return;
	data2.Copy(data);
	if(!data.SearchAccount(temp))
		return;
	temp2.Copy(temp);
	temp.Borrow();
	data.Account.DeleteItem(temp2);
	data.Account.InsertItem(temp);
	m_ClientList.DeleteItem(data2);
	m_ClientList.InsertItem(data);
}
Пример #24
0
void pumpPacketProximity(SerialPacket* const argPacket, int roomIndex, Vector2 position, int distance) {
	RoomData* roomData = RoomManager::GetSingleton().Get(roomIndex);

	if (!roomData) {
		throw(std::runtime_error("Failed to pump to a non-existant room"));
	}

	AccountData* accountData = nullptr;
	ClientData* clientData = nullptr;

	for (auto& characterIt : *roomData->GetCharacterList()) {
		if (distance == -1 || (characterIt->GetOrigin() - position).Length() <= distance) {
			accountData = AccountManager::GetSingleton().Get(characterIt->GetOwner());
			clientData = ClientManager::GetSingleton().Get(accountData->GetClientIndex());
			UDPNetworkUtility::GetSingleton().SendTo(clientData->GetAddress(), argPacket);
		}
	}
}
Пример #25
0
/*====================================================================================
// Function : read all Clients information from file.
// Pre		: file is opened.
// Post		: update list that has all Clients information from file.
=====================================================================================*/
void Application::GetClientListFromFile()
{
	if(!m_ListInFile.good())
	{
		cout << "\t해당 파일을 읽을 수 없습니다." << endl;
		return;
	}

	while(!m_ListInFile.eof())
	{
		ClientData* temp = new ClientData;				//집어넣고자하는 부품 타입
		if(!temp->GetRecordFromFile(m_ListInFile))
			break;
		m_ClientList.InsertItem(*temp);
		delete temp;
	}
	cout << "\t정상적으로 파일에서 읽었습니다." << endl;
	m_ListInFile.close();
}
Пример #26
0
int callbackSendOperation(Packet& p)
{
	PacketSendOperation pp (p);

	//cout << "callbackSendOperation" << endl;

	// récupérer singleton serveur
	ClientData* cd = PolypeerClient::getInstance()->getClientData();

	// vérifier que l'on possède bien le chunk en question
	// --
	FileManager* fm = cd->getFileManager(pp.getIdFile());

	//cout <<" on demande a envoyé le "<<pp.getNumChunk()<<" du fichier "<< pp.getIdFile() <<endl;

	if(fm!=NULL)
	{
		Chunk* c = fm->getChunk((long)pp.getNumChunk());
		if(c !=NULL)
		{
			//cout << "Chunk prêt à envoyer n°" << c->getNumber()<<endl;
			// envoie à la cible
			cd->getConnectionManager()->sendTo(pp.getTarget(), PacketSendChunk(*c));
			//cout << "Chunk envoyé"<<endl;
			// réponse au serveur du travail effectué
			cd->getConnectionManager()->sendTo(cd->getAddressServ(), PacketSendOperationFinished());
			//cout << "serveur prévenu"<<endl;

		}else
		{
			//cout << "ce Chunk n'est pas dispo"<<endl;
		}


	}else
	{

		//cout << "Ce fichier n'existe pas"<<endl;
	}


	return 1;
}
Пример #27
0
/* virtual */ SysStatusUval
LinuxPTYServer::recvfrom(struct iovec *vec, uval veclen, uval flags,
			 char *addr, uval &addrLen, GenState &moreAvail, 
			 void *controlData, uval &controlDataLen,
			 __XHANDLE xhandle)
{
    addrLen = 0;

    controlDataLen = 0; /* setting to zero, since no control data */

    AutoLock<LockType> al(&_lock);
    ClientData *cd = getClientData(xhandle);
    SysStatusUval rc = 0;


    ProcessLinux::LinuxInfo info;
    ProcessID pid = XHandleTrans::GetOwnerProcessID(xhandle);
    rc = DREFGOBJ(TheProcessLinuxRef)->getInfoNativePid(pid, info);
    tassertMsg(_SUCCESS(rc),
	       "Couldn't get info about k42 process 0x%lx\n", pid);

    PTYTaskInfo ptyTI(info.pid, info.pgrp, info.session, info.tty,
		      info.pid == info.session);

    LinuxEnv sc(SysCall, ptyTI.t);
    rc = 0;
    for (uval i = 0; i<veclen; ++i) {
	int nr = ttydev_read(oli, (char*)vec[i].iov_base,
			     vec[i].iov_len, &availMask);
	if (nr < 0) {
	    if (rc>0) break;
	    if (nr==-EWOULDBLOCK) break;
	    rc = _SERROR(2495, 0, -nr);
	    break;
	}
	rc += nr;
    }
    availMask = ttydev_poll(oli);
    calcAvailable(moreAvail);
    cd->setAvail(moreAvail);
    return rc;
}
Пример #28
0
static nsresult
AssembleClientData(const nsAString& aOrigin, const nsAString& aTyp,
                   const nsAString& aChallenge, CryptoBuffer& aClientData)
{
  ClientData clientDataObject;
  clientDataObject.mTyp.Construct(aTyp); // "Typ" from the U2F specification
  clientDataObject.mChallenge.Construct(aChallenge);
  clientDataObject.mOrigin.Construct(aOrigin);

  nsAutoString json;
  if (NS_WARN_IF(!clientDataObject.ToJSON(json))) {
    return NS_ERROR_FAILURE;
  }

  if (NS_WARN_IF(!aClientData.Assign(NS_ConvertUTF16toUTF8(json)))) {
    return NS_ERROR_FAILURE;
  }

  return NS_OK;
}
Пример #29
0
void FawnKVServerHandler::get(const std::string& key, const int64_t continuation, const int32_t cid) {
    pthread_mutex_lock(p_mutex);
    // Generating unique server-side continuation
	//cout << reqNumber << endl;
    int64_t ss_continuation = reqNumber++;

	ClientData *cd = get_client(cid);
    DBID dkey(key);
    string value;
    if ((cache) && (cache->lookup(dkey, value))){
        cd->fc->get_response(value, continuation);
    }
    else {
        //cout << "Get from CID: " << cid << " continuation: " << continuation << " reqNumber: " << ss_continuation << endl;
        cd->addContinuation(continuation, ss_continuation);
        req_client_map[ss_continuation] = cd;
        frontend->get(key, ss_continuation);
        //cout << "Get Done for CID: " << cid << " continuation: " << continuation << " reqNumber: " << ss_continuation << endl;
    }

	if ((reqNumber % 2000) == 0) {
//    if (1) {
		gettimeofday(&tim, NULL);
		t  = tim.tv_sec + (tim.tv_usec/1000000.0);
		if ((t_since > 0) && (t-t_since > 0)) {
			double rr = (reqNumber - reqSince)/1000.00/(t-t_since);
            r = 0.8 * r + 0.2 * rr;
			cout << r << "k query/sec " ; //<<  t  - t_since << endl;
            if (cache)
                cout << "hit_ratio " << cache->hit_ratio() << " cache_size " << cache->size() << endl;
            else
                cout << "hit_ratio " << 0 << endl;
		}

		t_since = t;
		reqSince = reqNumber;
	}

    pthread_mutex_unlock(p_mutex);

}
Пример #30
0
int callbackSendChunk(Packet& p)
{
	PacketSendChunk pp (p);

	//cout << "callbackSendChunk";

	// récupérer singleton serveur
	ClientData* cd = PolypeerClient::getInstance()->getClientData();

	Chunk* tmp = pp.getChunk();

	if(tmp->isIntegrate())
    {

    	FileManager* fm = cd->getFileManager(tmp->getIdFile());
        fm->saveChunk(*tmp);

        cd->getConnectionManager()->sendTo(cd->getAddressServ(), PacketChunkReceived(tmp->getIdFile(), fm->getCurrentNumberChunk()));
    }
    else
    {
        //cout << "erreur du Chunk reçu :";
        //cout << tmp->getNumber()<<endl;
        cd->getConnectionManager()->sendTo(cd->getAddressServ(), PacketMd5Error(tmp->getIdFile(), tmp->getNumber()));
    }
	delete tmp;
	return 1;
}