コード例 #1
0
ファイル: socket_listener.cpp プロジェクト: zhdtty/storm_net
void SocketListener::doRequest(Connection::ptr pack) {
	int ret = 0;
	RpcRequest req;
	RpcResponse resp;

	//解析RpcRequest
	if (!req.ParseFromString(pack->buffer)) {
		STORM_ERROR << "rpc request error";
		m_sockServer->close(pack->id, CloseType_Packet_Error);
		return;
	}

	//业务逻辑
	ret = doRpcRequest(pack, req, resp);

	if (req.invoke_type() == InvokeType_OneWay) {
		return;
	}

	//回包
	resp.set_ret(ret);
	resp.set_proto_id(req.proto_id());
	resp.set_request_id(req.request_id());

	IOBuffer::ptr respBuf = FrameProtocolLen::encode(resp);
	m_sockServer->send(pack->id, respBuf);
}
コード例 #2
0
void StormService::onRequest(const Connection& conn, const char* buffer, uint32_t len) {
	int32_t ret = 0;
	RpcRequest req;
	RpcResponse resp;

	// 解析RpcRequest
	if (!req.ParseFromArray(buffer, len)) {
		STORM_ERROR << "rpc request error";
		m_loop->close(conn.id, CloseType_PacketError);
		return;
	}

	// 业务逻辑
	ret = onRpcRequest(conn, req, resp);

	if (req.invoke_type() == InvokeType_OneWay) {
		return;
	}

	//回包
	resp.set_ret(ret);
	resp.set_proto_id(req.proto_id());
	resp.set_request_id(req.request_id());

	IoBuffer* data = PacketProtocolLen::encode(resp);
	m_loop->send(conn.id, data->getHead(), data->getSize());
	delete data;
}