Exemplo n.º 1
0
int VNCServer::End()
{
	Log(">VNCServer::End\n");

	//Lock
	use.WaitUnusedAndLock();

	//Get client iterator
	Clients::iterator it=clients.begin();

	//Close clients
	while (it!=clients.end())
	{
		//Get client
		Client *client = it->second;
		//Erase it and move forward
		clients.erase(it++);
		//End it
		client->Close();
		//Delete it
		delete(client);
	}

	//Unlock
	use.Unlock();

	Log("<VNCServer::End\n");
}
Exemplo n.º 2
0
int VNCServer::Connect(int partId,const std::wstring &name,WebSocket *socket,const std::string &to)
{
	Log(">VNCServer connecting participant viewer [id:%d,to:%s]\n",partId,to.c_str());

	//Lock
	use.WaitUnusedAndLock();

	//Create new client
	Client *client = new Client(partId,name,this);
	//Set client as as user data
	socket->SetUserData(client);

	//Check if there was one already ws connected for that user
	Clients::iterator it = clients.find(partId);
	//If it was
	if (it!=clients.end())
	{
		//Get old client
		Client *old = it->second;
		//End it
		old->Close();
		//Delete it
		delete(old);
		//Set new one
		it->second = client;
	} else {
		//Append to client list
		clients[partId] = client;
	}

	//If it was editor
	if (partId==editorId)
		//Set client editor
		client->SetViewOnly(false);

	//Check if it is freezed
	if (to.rfind("vnc-freeze")!=std::string::npos)
		//Freeze
		client->FreezeUpdate(true);

	//Unlock clients list
	use.Unlock();

	//Accept incoming connection and add us as listeners
	socket->Accept(this);

	//Connect to socket
	return client->Connect(socket);
}
Exemplo n.º 3
0
int main(int argc, char **argv)
{
    Client client;
    int initret = client.Init();
    if (BLADE_ERROR == initret)
        abort();

    int64_t fid;
    ssize_t readlen;
    int writelocallen;
    int32_t buffersize = 10485760;
    char *buf = (char *)malloc(buffersize);
    string src(argv[1]);

    int localfid = open("readfile", O_RDWR | O_APPEND | O_CREAT | O_TRUNC);//本地文件

    fid = client.Open(src, O_RDONLY);
//    printf("bladefid:%d\n", fid);
    if (fid == -4) { 
        printf("BLADE_FILE_NOT_EXIST\n");
        return -1;
    } else {
        printf("start read\n");

        do {
//            printf("buffersize: %d\n", buffersize);
            readlen = client.Read(fid, (void *)buf, buffersize);
//            printf("readlen:%d\n", readlen);
            //把缓存内容写入本地文件
              if (readlen > 0) {
                writelocallen = write(localfid, buf, readlen);
//               printf("writelocallen:%d\n", writelocallen);
            }
        } while (readlen > 0);
        close(localfid);
        free(buf);
    }
    printf("finish read\n");
    client.Close(fid);
	return 0;
}
Exemplo n.º 4
0
void ClientMgr::update()
{
	google::dense_hash_map<unsigned int, Client*>::iterator it = m_mapClient.begin();
	for (; it != m_mapClient.end(); ++it)
	{
		Client* client = it->second;
		if (NULL == client)
		{
			continue;
		}
		
		if (0 != client->getTick())
		{
			client->decTick();
		}
		else
		{
			client->Close();
		}
	}
}