Skip to content

Commit

Permalink
FIX NetEase#23 不能正确处理Protobuf的请求
Browse files Browse the repository at this point in the history
  • Loading branch information
losingle committed Dec 3, 2016
1 parent 375b776 commit 6f4204e
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
22 changes: 19 additions & 3 deletions src/tr/uv/pr_msg.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

#include "pr_msg.h"
#include "tr_uv_tcp_i.h"
#include "pc_pomelo_i.h"

#define PC_MSG_FLAG_BYTES 1
#define PC_MSG_ROUTE_LEN_BYTES 1
Expand Down Expand Up @@ -165,7 +166,7 @@ static pc__msg_raw_t *pc_msg_decode_to_raw(const pc_buf_t* buf)
return msg;
}

pc_msg_t pc_default_msg_decode(const pc_JSON* code2route, const pc_JSON* server_protos, const pc_buf_t* buf)
pc_msg_t pc_default_msg_decode(const pc_JSON* code2route, const pc_JSON* server_protos, const pc_buf_t* buf, QUEUE* requestQueue)
{
const char *route_str = NULL;
const char *origin_route = NULL;
Expand Down Expand Up @@ -194,7 +195,22 @@ pc_msg_t pc_default_msg_decode(const pc_JSON* code2route, const pc_JSON* server_
/* route */
if (PC_MSG_HAS_ROUTE(raw_msg->type)) {
/* uncompress route dictionary */
route_str = NULL;
QUEUE* q;
pc_request_t* req;
QUEUE_FOREACH(q, requestQueue) {
req = (pc_request_t* )QUEUE_DATA(q, pc_common_req_t, queue);
if (req->req_id == msg.id) {
msg.route = (char* )pc_lib_malloc(strlen(req->base.route) + 1);
strcpy((char* )msg.route, req->base.route);
break;
}
}
if (msg.route == NULL) {
msg.id = PC_INVALID_REQ_ID;
pc_lib_free(raw_msg);
return msg;
}

if (raw_msg->is_route_compressed) {
origin_route = pc__resolve_dictionary(code2route, raw_msg->route.route_code);
if (!origin_route) {
Expand Down Expand Up @@ -489,5 +505,5 @@ pc_msg_t pr_default_msg_decoder(tr_uv_tcp_transport_t* tt, const uv_buf_t* buf)
pb.base = buf->base;
pb.len = buf->len;

return pc_default_msg_decode(tt->code_to_route, tt->server_protos, &pb);
return pc_default_msg_decode(tt->code_to_route, tt->server_protos, &pb, &tt->client->req_queue);
}
3 changes: 2 additions & 1 deletion src/tr/uv/pr_msg.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

#include "pr_pkg.h"
#include <pc_JSON.h>
#include <queue.h>

typedef struct tr_uv_tcp_transport_s tr_uv_tcp_transport_t;

Expand All @@ -31,7 +32,7 @@ typedef struct {
} pc_buf_t;

pc_buf_t pc_default_msg_encode(const pc_JSON* route2code, const pc_JSON* client_protos, const pc_msg_t* msg);
pc_msg_t pc_default_msg_decode(const pc_JSON* code2route, const pc_JSON* server_protos, const pc_buf_t* buf);
pc_msg_t pc_default_msg_decode(const pc_JSON* code2route, const pc_JSON* server_protos, const pc_buf_t* buf, QUEUE* requestQueue);

pc_buf_t pc_body_json_encode(const pc_JSON* msg);
pc_JSON* pc_body_json_decode(const char *data, size_t offset, size_t len);
Expand Down
2 changes: 1 addition & 1 deletion src/tr/uv/tr_uv_tcp_aux.c
Original file line number Diff line number Diff line change
Expand Up @@ -871,7 +871,7 @@ void tcp__on_data_recieved(tr_uv_tcp_transport_t* tt, const char* data, size_t l
}

assert((msg.id == PC_NOTIFY_PUSH_REQ_ID && msg.route)
|| (msg.id != PC_NOTIFY_PUSH_REQ_ID && !msg.route));
|| (msg.id != PC_NOTIFY_PUSH_REQ_ID && msg.route));

pc_lib_log(PC_LOG_INFO, "tcp__on_data_recieved - recived data, req_id: %d", msg.id);
if (msg.id != PC_NOTIFY_PUSH_REQ_ID) {
Expand Down

0 comments on commit 6f4204e

Please sign in to comment.