Ejemplo n.º 1
0
int main() {
  std::thread a_thread(a);
  std::thread b_thread(b);
  
  a_thread.join();
  b_thread.join();
}
Ejemplo n.º 2
0
void UploadManager::handleNewConnection(int recvFD) {

	//read in resourceURI length
	//move the following code to MP4FileUpload.cpp
	/*	int URIlength;

		int ret = recvExact(recvFD, (char *) &URIlength, sizeof(int));
		if (ret <= 0) {
			if (ret == 0)
				std::cerr
						<< "Client closed connection, could not read in size of URI"
						<< std::endl;
			else {
				std::cerr << "Could not read in size of URI: " << strerror(errno)
						<< std::endl;
				UploadProtocol::reply(recvFD, UploadProtocol::STATUS_ERROR);
			}
			close(recvFD);
			return;
		}

		URIlength = ntohl(URIlength);
		std::cout << "URIlength: " << URIlength << std::endl;

		//read in resourceURI and reply to client
		char URIarray[URIlength];

		ret = recvExact(recvFD, URIarray, URIlength);
		if (ret <= 0) {
			if (ret == 0)
				std::cerr << "Client closed connection, could not read in URI"
						<< std::endl;
			else {
				std::cerr << "Could not read in URI: " << strerror(errno)
						<< std::endl;
				UploadProtocol::reply(recvFD, UploadProtocol::STATUS_ERROR);
			}
			close(recvFD);
			return;
		}


		//take care, the char array is not null-terminated!
		std::string URI = std::string(URIarray, URIlength);
		std::cout << "URI: " << URI << std::endl;


		UploadProtocol::reply(recvFD, UploadProtocol::STATUS_OK);*/

	MP4FileUpload upThread;
	boost::thread b_thread(boost::bind(&upload::MP4FileUpload::start, upThread,
									recvFD, s_queue));



	//start the correct UploadThread type
	//note: we only close recvFD on errors, as it is still needed in the started thread!
	/*prm::pResource_t pRes;
	if (prm::PrivateResourceManager::Instance().read(URI, pRes) == prm::ok) {
		//send OK to server
		UploadProtocol::reply(recvFD,UploadProtocol::STATUS_OK);

		if (prm::pStreamResource_t derived = boost::dynamic_pointer_cast<
				prm::StreamResource>(pRes)) {
			switch (derived->container) {
			case prm::StreamResource::CONTAINER_MP4: {
				MP4FileUpload upThread;
				//we had to implement a non-virtual start()-method in UploadThread, that subsequently calls the virtual
				//startReceive functions in the derived classes. If we would call directly the startReceive function,
				//which would in that case be purely virtual in UploadThread, we encounter runtime errors.
				//In that case, the object upThread is deleted before the boost::bind call can call the actual method (multithreading issues...)
				//an alternative can be to create upThread with the new method, but then you have
				//to do some housekeeping: e.g. MP4Upload thread must then say it is finished, so the object
				//can be destroyed here...
				boost::thread b_thread(
						boost::bind(&upload::MP4FileUpload::start, upThread,
								recvFD));
				return;
			}
			case prm::StreamResource::CONTAINER_GPS: {
				GPSUpload upThread;
				//boost::thread b_thread(boost::bind(&upload::GPSUpload::startReceive, &upThread));
				return;
			}
			case prm::StreamResource::CONTAINER_RTSP_RTP: {
				RTSP_RTPUpload upThread;
				//boost::thread b_thread(boost::bind(&upload::RTSPRTPUpload::startReceive, &upThread));
				return;
			}
			default:
				std::cerr
						<< "Unknown container format of stream, closing connection"
						<< std::endl;
				UploadProtocol::reply(recvFD, UploadProtocol::STATUS_ERROR);
				close(recvFD);
			}
		} else {
			std::cerr
					<< "ResourceID is not a stream, closing connection to client"
					<< std::endl;
			UploadProtocol::reply(recvFD, UploadProtocol::STATUS_ERROR);
			close(recvFD);
			return;
		}

	} else {
		std::cerr << "Wrong resource ID, closing connection" << std::endl;
		UploadProtocol::reply(recvFD, UploadProtocol::STATUS_ERROR);
		close(recvFD);
		return;
	}*/
}