示例#1
0
文件: Server.cpp 项目: Thywin/Thywin
	void Server::Listen()
	{
		if (!HasConnection())
		{
			throw std::runtime_error("Couldn't listen because server has no connection");
		}
		if (listen(serverSocket, amountOfConnectionsAccept) < 0)
		{
			std::string errorMessage(strerror(errno));
			throw std::runtime_error("Failed have socket listen: " + errorMessage);
		}

		struct sockaddr_in clientAddr;
		socklen_t sizeOfClientAddr = sizeof(clientAddr);
		pthread_t thread_id;

		logger.Log(INFO, std::string("Server is awaiting connections"));

		while (HasConnection())
		{
			int client = accept(serverSocket, (struct sockaddr *) &clientAddr, (socklen_t*) &sizeOfClientAddr);
			printf("Connection accepted with client: %s port %i | CLIENT: %i\n", inet_ntoa(clientAddr.sin_addr),
					ntohs(clientAddr.sin_port), client);

			logger.Log(INFO, std::string("Connection accepted with client: port"));
			int* arg = (int*) malloc(sizeof(*arg));
			*arg = client;
			if (pthread_create(&thread_id, NULL, setUpConnectionWithClient, arg) < 0)
			{
				close(client);
				logger.Log(ERROR, std::string("Failed to create a new thread for client connection"));
				throw std::runtime_error("Failed to create a new thread for client connection");
			}
			else
			{
				pthread_detach(thread_id);
			}
		}
	}
示例#2
0
 bool CheckVersionDiff()
 {
     bool diff = false;
     if(HasConnection())
     {
         std::string js = RetrieveContent("https://api.github.com/repos/xortroll/goldleaf/releases", "application/json");
         json j = json::parse(js);
         std::string latestid = j[0]["tag_name"].get<std::string>();
         Version latestv = Version::FromString(latestid);
         Version currentv = Version::FromString("0.3");
         diff = latestv.IsLower(currentv);
     }
     return diff;
 }
示例#3
0
OSStatus		AUInputElement::PullInput(	AudioUnitRenderActionFlags &  	ioActionFlags,
											const AudioTimeStamp &			inTimeStamp,
											AudioUnitElement				inElement,
											UInt32							nFrames)
{	
	if (!IsActive())
		return kAudioUnitErr_NoConnection;
		
	AudioBufferList *pullBuffer;
	
	if (HasConnection() || !WillAllocateBuffer())
		pullBuffer = &mIOBuffer.PrepareNullBuffer(mStreamFormat, nFrames);
	else
		pullBuffer = &mIOBuffer.PrepareBuffer(mStreamFormat, nFrames);
	
	return PullInputWithBufferList (ioActionFlags, inTimeStamp, inElement, nFrames, pullBuffer);
}