Exemplo n.º 1
0
	virtual status_t Execute()
	{
		// connect to the server info port
		sockaddr_in addr = fServerInfo->GetAddress().GetAddress();
		addr.sin_port = htons(kDefaultServerInfoPort);
		if (connect(fFD, (sockaddr*)&addr, sizeof(addr)) < 0) {
			ERROR("ServerManager::ServerInfoTask: ERROR: Failed to connect "
				"to server info port: %s\n", strerror(errno));
			return errno;
		}

		// create a channel
		InsecureChannel channel(fFD);

		// receive a request
		RequestChannel requestChannel(&channel);
		Request* _request;
		status_t error = requestChannel.ReceiveRequest(&_request);
		if (error != B_OK) {
			ERROR("ServerManager::ServerInfoTask: ERROR: Failed to receive "
				"server info request: %s\n", strerror(errno));
			return error;
		}
		ObjectDeleter<Request> requestDeleter(_request);
		ServerInfoRequest* request = dynamic_cast<ServerInfoRequest*>(_request);
		if (!request) {
			ERROR("ServerManager::ServerInfoTask: ERROR: Received request "
				"is not a server info request.\n");
			return B_BAD_DATA;
		}

		// get the info
		error = fServerInfo->SetTo(&request->serverInfo);
		if (error != B_OK)
			return error;

		// notify the manager
		if (fOldServerInfo)
			fServerManager->_ServerUpdated(fServerInfo);
		else
			fServerManager->_ServerAdded(fServerInfo);

		fSuccess = true;
		return B_OK;
	}
Exemplo n.º 2
0
	virtual status_t Execute()
	{
		if (!fChannel) {
			SetDone(true);
			return B_NO_INIT;
		}

		RequestChannel requestChannel(fChannel);

		// create the server info request
		ServerInfoRequest request;
		request.serverInfo = fServerInfo;

		// send the request
		status_t error = requestChannel.SendRequest(&request);
		if (error != B_OK) {
			ERROR("ServerInfoSender: ERROR: Failed to send request: %s\n",
				strerror(error));
		}

		SetDone(true);
		return B_OK;
	}