tanghai 14 лет назад
Родитель
Сommit
c395734e4a
2 измененных файлов с 40 добавлено и 40 удалено
  1. 20 20
      Cpp/Platform/Rpc/RpcCommunicatorTest.cc
  2. 20 20
      Cpp/Platform/Rpc/RpcServer.cc

+ 20 - 20
Cpp/Platform/Rpc/RpcCommunicatorTest.cc

@@ -9,7 +9,7 @@
 
 namespace Egametang {
 
-static int global_port = 10001;
+static int globalPort = 10001;
 
 class RpcServerTest: public RpcCommunicator
 {
@@ -20,8 +20,8 @@ public:
 	boost::asio::ip::tcp::acceptor acceptor;
 
 public:
-	RpcServerTest(boost::asio::io_service& io_service, int port, CountBarrier& barrier):
-		RpcCommunicator(io_service), acceptor(io_service),
+	RpcServerTest(boost::asio::io_service& ioService, int port, CountBarrier& barrier):
+		RpcCommunicator(ioService), acceptor(ioService),
 		barrier(barrier)
 	{
 		boost::asio::ip::address address;
@@ -69,11 +69,11 @@ public:
 
 		boost::hash<std::string> string_hash;
 
-		RpcMetaPtr response_meta(new RpcMeta());
+		RpcMetaPtr responseMeta(new RpcMeta());
 		StringPtr response_message(new std::string("response test rpc communicator string"));
-		response_meta->size = response_message->size();
-		response_meta->method = 123456;
-		SendMeta(response_meta, response_message);
+		responseMeta->size = response_message->size();
+		responseMeta->method = 123456;
+		SendMeta(responseMeta, response_message);
 
 		barrier.Signal();
 	}
@@ -90,9 +90,9 @@ public:
 	RpcMeta recvMeta;
 
 public:
-	RpcClientTest(boost::asio::io_service& io_service, int port,
+	RpcClientTest(boost::asio::io_service& ioService, int port,
 			CountBarrier& barrier):
-		RpcCommunicator(io_service), barrier(barrier)
+		RpcCommunicator(ioService), barrier(barrier)
 	{
 		boost::asio::ip::address address;
 		address.from_string("127.0.0.1");
@@ -122,11 +122,11 @@ public:
 		}
 		boost::hash<std::string> string_hash;
 
-		RpcMetaPtr send_meta(new RpcMeta());
-		StringPtr send_message(new std::string("send test rpc communicator string"));
-		send_meta->size = send_message->size();
-		send_meta->method = 654321;
-		SendMeta(send_meta, send_message);
+		RpcMetaPtr sendMeta(new RpcMeta());
+		StringPtr sendMessage(new std::string("send test rpc communicator string"));
+		sendMeta->size = sendMessage->size();
+		sendMeta->method = 654321;
+		SendMeta(sendMeta, sendMessage);
 
 		RpcMetaPtr meta(new RpcMeta());
 		StringPtr message(new std::string);
@@ -158,8 +158,8 @@ protected:
 public:
 	RpcCommunicatorTest():
 		ioServer(), ioClient(),
-		barrier(2), rpcServer(ioServer, global_port, barrier),
-		rpcClient(ioClient, global_port, barrier)
+		barrier(2), rpcServer(ioServer, globalPort, barrier),
+		rpcClient(ioClient, globalPort, barrier)
 	{
 	}
 
@@ -171,11 +171,11 @@ public:
 
 TEST_F(RpcCommunicatorTest, SendAndRecvString)
 {
-	ThreadPool thread_pool(2);
-	thread_pool.Schedule(boost::bind(&RpcServerTest::Start, &rpcServer));
-	thread_pool.Schedule(boost::bind(&RpcClientTest::Start, &rpcClient));
+	ThreadPool threadPool(2);
+	threadPool.Schedule(boost::bind(&RpcServerTest::Start, &rpcServer));
+	threadPool.Schedule(boost::bind(&RpcClientTest::Start, &rpcClient));
 	barrier.Wait();
-	thread_pool.Wait();
+	threadPool.Wait();
 	rpcServer.Stop();
 	rpcClient.Stop();
 

+ 20 - 20
Cpp/Platform/Rpc/RpcServer.cc

@@ -44,10 +44,10 @@ void RpcServer::OnAsyncAccept(RpcSessionPtr session, const boost::system::error_
 	}
 	session->Start();
 	sessions.insert(session);
-	RpcSessionPtr new_session(new RpcSession(ioService, *this));
-	acceptor.async_accept(new_session->Socket(),
+	RpcSessionPtr newSession(new RpcSession(ioService, *this));
+	acceptor.async_accept(newSession->Socket(),
 			boost::bind(&RpcServer::OnAsyncAccept, this,
-					new_session, boost::asio::placeholders::error));
+					newSession, boost::asio::placeholders::error));
 }
 
 void RpcServer::OnCallMethod(RpcSessionPtr session, ResponseHandlerPtr responseHandler)
@@ -67,35 +67,35 @@ void RpcServer::Stop()
 void RpcServer::RunService(RpcSessionPtr session, RpcMetaPtr meta,
 		StringPtr message, MessageHandler messageHandler)
 {
-	MethodInfoPtr method_info = methods[meta->method];
+	MethodInfoPtr methodInfo = methods[meta->method];
 
-	ResponseHandlerPtr response_handler(
-			new ResponseHandler(method_info, meta->id, messageHandler));
-	response_handler->Request()->ParseFromString(*message);
+	ResponseHandlerPtr responseHandler(
+			new ResponseHandler(methodInfo, meta->id, messageHandler));
+	responseHandler->Request()->ParseFromString(*message);
 
 	google::protobuf::Closure* done = google::protobuf::NewCallback(
 			this, &RpcServer::OnCallMethod,
-			session, response_handler);
+			session, responseHandler);
 
 	threadPool.Schedule(
-			boost::bind(&google::protobuf::Service::CallMethod, method_info->service,
-					response_handler->Method(), (google::protobuf::RpcController*)(NULL),
-					response_handler->Request(), response_handler->Response(),
+			boost::bind(&google::protobuf::Service::CallMethod, methodInfo->service,
+					responseHandler->Method(), (google::protobuf::RpcController*)(NULL),
+					responseHandler->Request(), responseHandler->Response(),
 					done));
 }
 
 void RpcServer::Register(RpcServicePtr service)
 {
-	boost::hash<std::string> string_hash;
-	const google::protobuf::ServiceDescriptor* service_descriptor = service->GetDescriptor();
-	for (int i = 0; i < service_descriptor->method_count(); ++i)
+	boost::hash<std::string> stringHash;
+	const google::protobuf::ServiceDescriptor* serviceDescriptor = service->GetDescriptor();
+	for (int i = 0; i < serviceDescriptor->method_count(); ++i)
 	{
-		const google::protobuf::MethodDescriptor* method_descriptor =
-				service_descriptor->method(i);
-		std::size_t method_hash = string_hash(method_descriptor->full_name());
-		MethodInfoPtr method_info(new MethodInfo(service, method_descriptor));
-		CHECK(methods.find(method_hash) == methods.end());
-		methods[method_hash] = method_info;
+		const google::protobuf::MethodDescriptor* methodDescriptor =
+				serviceDescriptor->method(i);
+		std::size_t methodHash = stringHash(methodDescriptor->full_name());
+		MethodInfoPtr methodInfo(new MethodInfo(service, methodDescriptor));
+		CHECK(methods.find(methodHash) == methods.end());
+		methods[methodHash] = methodInfo;
 	}
 }