示例#1
0
data_chunk HttpResponse::doSerialize() const
{
	// Reevaluate content length
	const_cast<http::Header&>(getHeaderLength()).setHeadValue(to_string(getContent().length()));

	DBG << "About to start serializing" << std::endl;
	data_chunk ret(itsResponse.Serialize());
	DBG << "Serialized itsResponse" << std::endl;
	data_chunk tmph(itsHeaders.Serialize());
	ret.insert(ret.end(), tmph.begin(), tmph.end());
	DBG << "Serialized itsHeaders" << std::endl;
	data_chunk tmpc(itsContent.Serialize());
	ret.insert(ret.end(), tmpc.begin(), tmpc.end());
	DBG << "Serialized itsContent" << std::endl;
	return ret;
}
示例#2
0
	void generateAll(vector<PNoeud>& l,bool elseOther=true) {
		PNoeud& n= *this;
		Pion pion = n.max?n.computer:!n.computer;
		for(size_t i=0;i<n.plat.pions.size();i++) {
			for(size_t j=0;j<n.plat.pions[i].size();j++) {
				try {
					Case tmpc((int)i,(int)j);
					l.push_back(PNoeud(n.plat,tmpc,pion,n.computer,!n.max));
				} catch (othelloException&) {
				}
			}
		}
		if(l.empty() && elseOther) {
			n.max = !n.max;
			generateAll(l,false);
		}
	}
示例#3
0
int main(int argc, char **argv) {
	struct sigaction handler;
	handler.sa_sigaction = signalHandler;
	handler.sa_flags = SA_SIGINFO;
	sigaction(SIGINT, &handler, NULL);
	sigaction(SIGPIPE, &handler, NULL);
	sigaction(SIGTERM, &handler, NULL);
	string ip = "localhost";
	int port = 5000;
	string tracker_ip = "127.0.0.1";
	int tracker_port = 7500;
	storage_directory = "/home/deepthought/sandbox/p2pvideo/files";
	char *tip, *dir, *cip;
	int bsize;
	getClientConfig(&tip, &tracker_port, &cip, &clients_port, &streaming_port, &dir, &bsize, &cache_size);
	tracker_ip = tip;
	ip = cip;
	storage_directory = dir;
	if (argc == 5) {
		ip = argv[1];
		port = atoi(argv[2]);
		storage_directory = argv[3];
		streaming_port = atoi(argv[4]);
		cout<<"storage directory is "<<storage_directory<<endl;
		clients_port = port;

		/*
		ip += ":";
		ip += argv[2];
		*/
		cout<<ip<<endl;
	}

	/*
	vector<bool> tmap;
	int tnum = 5;
	for (int i = 0; i < tnum; i++) {
		bool val = (i % 2 == 0);
		tmap.push_back(val);
	}

	BlockMap tblock(tmap);
	//tblock.print();

	int size;
	char *data = tblock.serialize(size);
	BlockMap dblock;
	dblock.deserialize(data, size);
	//dblock.print();

	string filename = "testurl1234567890";
	File tfile(filename, tmap);
	//tfile.print();
	data = tfile.serialize(size);
	File dfile;
	dfile.deserialize(data, size);
	//dfile.print();
	Client tclient(ip, port, "/tmp");
	tclient.addFile(tfile);
	//tclient.print();

	cout<<endl<<endl;

	Client dclient;
	int size2;
	char *data2 = tclient.serialize(size2);
	//dclient.deserialize(data2, size2);
	//dclient.print();

	int sockfd = connectToTracker(tracker_ip, tracker_port);
	if (sockfd != -1) {
		cout<<"Connected to tracker"<<endl;
	}
	//registerWithTracker(sockfd, tclient);

	for (int i = 0; i < tnum; i++) {
		tmap[i] = true;
	}
	int file_idx = tclient.getFileIdxByURL(filename);
	//tclient.updateFile(file_idx, tmap);
	//updateOnTracker(sockfd, tclient);
	*/
	pthread_rwlock_init(&client_mutex, NULL);
	Client tmpc(ip, clients_port, storage_directory);
	c = tmpc;
	c.connectToTracker(tracker_ip, tracker_port);
	c.registerWithTracker();
	c.queryTracker();
	c.client_mutex = &client_mutex;
	pthread_t streamer, queryThread, updateThread, statsThread;
	pthread_create(&streamer, NULL, handleStreaming, NULL);
	pthread_create(&queryThread, NULL, handleQuery, NULL);
	pthread_create(&updateThread, NULL, handleUpdate, NULL);
	pthread_create(&statsThread, NULL, handleStats, NULL);
	clients_sockfd = bindToPort(ip, clients_port);
	if(clients_sockfd == -1)
	{
		cout << "Could not create a socket for incoming client connections" << endl;
		abort();
		exit(1);
	}
	pthread_t client_threads[MAX_CLIENT_THREADS];
	int thread_id = 0;
	while(listen(clients_sockfd, BACKLOG) == 0)
	{
		struct sockaddr_storage incoming;
		socklen_t incoming_sz = sizeof(incoming);
		long new_fd = accept(clients_sockfd, (struct sockaddr *)&incoming, &incoming_sz);
		if (new_fd == -1) 
		{
			cout<<"peer accept failed with error: "<<strerror(errno)<<endl;
			exit(1);
		}
		else
		{
			if(pthread_create(&client_threads[thread_id], NULL, fileTransfer, (void *)new_fd)) 
			{
				cout<<"Thread creating failed"<<endl;
			}
			else
			{
				thread_id++;
			}
		}
	}
	while(1);
	return 0;
}