当前位置: 首页>>代码示例>>C++>>正文


C++ TaskManager::RunTask方法代码示例

本文整理汇总了C++中TaskManager::RunTask方法的典型用法代码示例。如果您正苦于以下问题:C++ TaskManager::RunTask方法的具体用法?C++ TaskManager::RunTask怎么用?C++ TaskManager::RunTask使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在TaskManager的用法示例。


在下文中一共展示了TaskManager::RunTask方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: accept

// _ServerInfoConnectionListener
int32
NetFSServer::_ServerInfoConnectionListener()
{
	if (fServerInfoConnectionListenerSocket < 0)
		return B_BAD_VALUE;

	TaskManager taskManager;

	// accept a incoming connection
	while (!fTerminating) {
		int fd = -1;
		do {
			taskManager.RemoveDoneTasks();

			fd = accept(fServerInfoConnectionListenerSocket, NULL, 0);
			if (fd < 0) {
				status_t error = errno;
				if (error != B_INTERRUPTED)
					return error;
				if (fTerminating)
					return B_OK;
			}
		} while (fd < 0);

		// get a fresh server info
		ServerInfo info;
		status_t error = _GetServerInfo(info);
		if (error != B_OK) {
			closesocket(fd);
			return error;
		}

		// create a server info sender thread
		ServerInfoSender* sender = new(std::nothrow) ServerInfoSender(fd, info);
		if (!sender || sender->Init() != B_OK) {
			closesocket(fd);
			delete sender;
		}
		taskManager.RunTask(sender);
	}

	return B_OK;
}
开发者ID:Ithamar,项目名称:haiku,代码行数:44,代码来源:NetFSServer.cpp

示例2: netAddress


//.........这里部分代码省略.........
			continue;
		}

		// check message size, magic, and protocol version
		if (bytesRead != sizeof(BroadcastMessage)) {
			PRINT("ServerManager::_BroadcastListener(): received "
				"%ld bytes, but it should be %lu\n", bytesRead,
				sizeof(BroadcastMessage));
			continue;
		}
		if (message.magic != B_HOST_TO_BENDIAN_INT32(BROADCAST_MESSAGE_MAGIC)) {
			PRINT("ServerManager::_BroadcastListener(): message has"
				" bad magic.\n");
			continue;
		}
		if (message.protocolVersion
			!= (int32)B_HOST_TO_BENDIAN_INT32(NETFS_PROTOCOL_VERSION)) {
			PRINT("ServerManager::_BroadcastListener(): protocol "
				"version does not match: %" B_PRId32 " vs. %d.\n",
				(int32)B_BENDIAN_TO_HOST_INT32(
					message.protocolVersion),
				NETFS_PROTOCOL_VERSION);
			continue;
		}

		// check, if the server is local
		NetAddress netAddress(addr);
		#ifndef ADD_SERVER_LOCALHOST
			if (netAddress.IsLocal())
				continue;
		#endif	// ADD_SERVER_LOCALHOST

		AutoLocker<Locker> locker(fLock);
		ExtendedServerInfo* oldServerInfo = fServerInfos->Get(netAddress);

		// examine the message
		switch (B_BENDIAN_TO_HOST_INT32(message.message)) {
			case BROADCAST_MESSAGE_SERVER_TICK:
//				PRINT(("ServerManager::_BroadcastListener(): "
//					"BROADCAST_MESSAGE_SERVER_TICK.\n"));
				if (oldServerInfo)
					continue;
				break;
			case BROADCAST_MESSAGE_SERVER_UPDATE:
//				PRINT(("ServerManager::_BroadcastListener(): "
//					"BROADCAST_MESSAGE_SERVER_UPDATE.\n"));
				break;
			case BROADCAST_MESSAGE_CLIENT_HELLO:
//				PRINT(("ServerManager::_BroadcastListener(): "
//					"BROADCAST_MESSAGE_CLIENT_HELLO. Ignoring.\n"));
				continue;
				break;
		}

		if (oldServerInfo && oldServerInfo->GetState() != STATE_READY)
			continue;

		// create a new server info and add it
		ExtendedServerInfo* serverInfo
			= new(std::nothrow) ExtendedServerInfo(netAddress);
		if (!serverInfo)
			return B_NO_MEMORY;
		serverInfo->SetState(STATE_ADDING);
		BReference<ExtendedServerInfo> serverInfoReference(serverInfo, true);
		if (oldServerInfo) {
			oldServerInfo->SetState(STATE_UPDATING);
		} else {
			status_t error = fServerInfos->Put(netAddress, serverInfo);
			if (error != B_OK)
				continue;
			serverInfo->AcquireReference();
		}

		// create a task to add/update the server info
		ServerInfoTask* task = new(std::nothrow) ServerInfoTask(this, oldServerInfo,
			serverInfo);
		if (!task) {
			if (oldServerInfo) {
				oldServerInfo->SetState(STATE_READY);
			} else {
				fServerInfos->Remove(serverInfo->GetAddress());
				serverInfo->ReleaseReference();
			}
			continue;
		}
		// now the task has all info and will call the respective cleanup
		// method when being deleted
		if (task->Init() != B_OK) {
			delete task;
			continue;
		}
		status_t error = taskManager.RunTask(task);
		if (error != B_OK) {
			ERROR("ServerManager::_BroadcastListener(): Failed to start server "
				"info task: %s\n", strerror(error));
			continue;
		}
	}
	return B_OK;
}
开发者ID:AmirAbrams,项目名称:haiku,代码行数:101,代码来源:ServerManager.cpp


注:本文中的TaskManager::RunTask方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。