src/util/server_nonblocking.cpp
// Waits for a task and returns it. If no further tasks are availabe, a nullptr is returned.
Waits for a task and returns it. If no further tasks are availabe, a nullptr is returned.
Waits for a task and returns it . If no further tasks are availabe a nullptr is returned .
NonblockingServer::Connection *NonblockingServer::popTask() {
	std::unique_lock<std::mutex> lock(job_queue_mutex);
	while (true) {
		while (running && job_queue.empty()) {
			job_queue_cond.wait(lock);
		}
		if (!running)
			return nullptr;
		auto connection = job_queue.front();
		job_queue.pop();
		if (connection->is_closed) {
			connection->state = Connection::State::IDLE;
			continue;
		}
		if (connection->state != Connection::State::PROCESSING_DATA_ASYNC)
			throw MustNotHappenException("NonblockingServer: popped a connection from the job queue which is not in state PROCESSING_ASYNC");
		return connection;
	}
	return nullptr;
}
NonblockingServer :: Connection * NonblockingServer :: popTask ( ) { std :: unique_lock < std :: mutex > lock ( job_queue_mutex ) ; while ( true ) { while ( running && job_queue . empty ( ) ) { job_queue_cond . wait ( lock ) ; } if ( ! running ) return nullptr ; auto connection = job_queue . front ( ) ; job_queue . pop ( ) ; if ( connection -> is_closed ) { connection -> state = Connection :: State :: IDLE ; continue ; } if ( connection -> state != Connection :: State :: PROCESSING_DATA_ASYNC ) throw MustNotHappenException ( " " ) ; return connection ; } return nullptr ; }
Waits for a task and returns it.
Waits for a task and returns it .
// it's possible that the connection had a problem somewhere.. // We don't want to spend work on it, but we need to pass ownership back to the main thread so it can be reaped. // dear eclipse: please stop complaining