Commit bab70ab0 authored by wangxuefeng's avatar wangxuefeng

Update as comments.

parent e634500c
...@@ -80,8 +80,7 @@ public: ...@@ -80,8 +80,7 @@ public:
res->data = req->data + " (processed directly)"; res->data = req->data + " (processed directly)";
} }
LOG(INFO) << "Process success in server side for thrift_method_name: " <<
cntl->thrift_method_name();
} }
private: private:
......
...@@ -454,7 +454,7 @@ public: ...@@ -454,7 +454,7 @@ public:
void set_thrift_method_name(const std::string& method_name) { void set_thrift_method_name(const std::string& method_name) {
_thrift_method_name = method_name; _thrift_method_name = method_name;
} }
std::string thrift_method_name() { return _thrift_method_name; } const std::string& thrift_method_name() { return _thrift_method_name; }
private: private:
struct CompletionInfo { struct CompletionInfo {
......
...@@ -47,12 +47,12 @@ ...@@ -47,12 +47,12 @@
#endif #endif
extern "C" { extern "C" {
void bthread_assign_data(void* data); void bthread_assign_data(void* data) __THROW;
} }
namespace brpc { namespace brpc {
int32_t get_thrift_method_name(const butil::IOBuf& body, std::string* method_name) { static int32_t parse_thrift_method_name(const butil::IOBuf& body, std::string* method_name) {
// Thrift protocol format: // Thrift protocol format:
// Version + Message type + Length + Method + Sequence Id // Version + Message type + Length + Method + Sequence Id
...@@ -144,7 +144,7 @@ void ThriftClosure::Run() { ...@@ -144,7 +144,7 @@ void ThriftClosure::Run() {
_response.head = _request.head; _response.head = _request.head;
if (_response.thrift_raw_instance) { if (_response.thrift_raw_instance) {
std::string method_name = _controller.thrift_method_name(); const std::string& method_name = _controller.thrift_method_name();
if (method_name == "" || if (method_name == "" ||
method_name.length() < 1 || method_name.length() < 1 ||
method_name[0] == ' ') { method_name[0] == ' ') {
...@@ -282,8 +282,8 @@ static void CallMethodInBackupThread(void* void_args) { ...@@ -282,8 +282,8 @@ static void CallMethodInBackupThread(void* void_args) {
CallMethodInBackupThreadArgs* args = (CallMethodInBackupThreadArgs*)void_args; CallMethodInBackupThreadArgs* args = (CallMethodInBackupThreadArgs*)void_args;
std::string method_name; std::string method_name;
if (get_thrift_method_name(args->request->body, &method_name) < 0) { if (parse_thrift_method_name(args->request->body, &method_name) < 0) {
LOG(FATAL) << "Fail to get thrift method name"; LOG(ERROR) << "Fail to get thrift method name";
delete args; delete args;
return; return;
} }
...@@ -421,28 +421,37 @@ void ProcessThriftRequest(InputMessageBase* msg_base) { ...@@ -421,28 +421,37 @@ void ProcessThriftRequest(InputMessageBase* msg_base) {
span->AsParent(); span->AsParent();
} }
try { std::string method_name;
std::string method_name; if (parse_thrift_method_name(req->body, &method_name) < 0) {
if (get_thrift_method_name(req->body, &method_name) < 0) { cntl->SetFailed(EREQUEST, "Fail to get thrift method name!");
cntl->SetFailed(EREQUEST, "Fail to get thrift method name!"); return;
} }
cntl->set_thrift_method_name(method_name); cntl->set_thrift_method_name(method_name);
if (!FLAGS_usercode_in_pthread) { if (!FLAGS_usercode_in_pthread) {
try {
return service->ProcessThriftFramedRequest(*server, cntl, return service->ProcessThriftFramedRequest(*server, cntl,
req, res, thrift_done); req, res, thrift_done);
} catch (::apache::thrift::TException& e) {
cntl->SetFailed(EREQUEST, "Invalid request data, reason: %s", e.what());
} catch (...) {
cntl->SetFailed(EINTERNAL, "Internal server error!");
} }
if (BeginRunningUserCode()) {
}
if (BeginRunningUserCode()) {
try {
service->ProcessThriftFramedRequest(*server, cntl, req, res, thrift_done); service->ProcessThriftFramedRequest(*server, cntl, req, res, thrift_done);
return EndRunningUserCodeInPlace(); } catch (::apache::thrift::TException& e) {
} else { cntl->SetFailed(EREQUEST, "Invalid request data, reason: %s", e.what());
return EndRunningCallMethodInPool( } catch (...) {
service, *server, cntl, req, res, thrift_done); cntl->SetFailed(EINTERNAL, "Internal server error!");
} }
} catch (::apache::thrift::TException& e) { return EndRunningUserCodeInPlace();
cntl->SetFailed(EREQUEST, "Invalid request data, reason: %s", e.what()); } else {
} catch (...) { return EndRunningCallMethodInPool(
cntl->SetFailed(EINTERNAL, "Internal server error!"); service, *server, cntl, req, res, thrift_done);
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment