From f1d3e2c3b8698e25868d2459cd735f920d5594e6 Mon Sep 17 00:00:00 2001 From: Caesar11 Date: Mon, 12 Jan 2015 03:59:37 -0500 Subject: [PATCH] fix a bug in Socket::recv(). --- Query/BasicQuery.cpp | 36 ++++++++++++++++++++---------------- Query/BasicQuery.h | 1 + Server/Socket.cpp | 29 ++++++++++++++++------------- 3 files changed, 37 insertions(+), 29 deletions(-) diff --git a/Query/BasicQuery.cpp b/Query/BasicQuery.cpp index 77edbc5..3cbbf64 100644 --- a/Query/BasicQuery.cpp +++ b/Query/BasicQuery.cpp @@ -11,22 +11,7 @@ /* _query is a SPARQL query string */ BasicQuery::BasicQuery(const string _query) { - this->option_vs.clear(); - this->triple_vt.clear(); - this->var_str2id.clear(); - this->var_degree = NULL; - this->is_literal_candidate_added = NULL; - this->edge_id = NULL; - this->edge_nei_id = NULL; - this->edge_pre_id = NULL; - this->edge_type = NULL; - this->var_sig = NULL; - this->edge_sig = NULL; - this->encode_method = BasicQuery::NOT_JUST_SELECT; - this->candidate_list = NULL; - this->graph_var_num = 0; - this->select_var_num = 0; - this->var_name = 0; + this->initial(); } BasicQuery::~BasicQuery() @@ -410,6 +395,25 @@ const Triple& BasicQuery::getTriple(int _i_th_triple) } /* private methods */ +void BasicQuery::null_initial() +{ + this->option_vs.clear(); + this->triple_vt.clear(); + this->var_str2id.clear(); + this->var_degree = NULL; + this->is_literal_candidate_added = NULL; + this->edge_id = NULL; + this->edge_nei_id = NULL; + this->edge_pre_id = NULL; + this->edge_type = NULL; + this->var_sig = NULL; + this->edge_sig = NULL; + this->encode_method = BasicQuery::NOT_JUST_SELECT; + this->candidate_list = NULL; + this->graph_var_num = 0; + this->select_var_num = 0; + this->var_name = 0; +} void BasicQuery::initial() { diff --git a/Query/BasicQuery.h b/Query/BasicQuery.h index c3f9012..e590928 100644 --- a/Query/BasicQuery.h +++ b/Query/BasicQuery.h @@ -71,6 +71,7 @@ private: void findVarNotInSelect(); void buildTuple2Freq(); void initial(); + void null_initial(); public: static const char EDGE_IN = 'i'; diff --git a/Server/Socket.cpp b/Server/Socket.cpp index ca3800a..aea512b 100644 --- a/Server/Socket.cpp +++ b/Server/Socket.cpp @@ -178,22 +178,25 @@ int Socket::recv(std::string& _msg)const } char* buf = new char[msg_len]; - recv_return = ::recv(this->sock, buf, msg_len, 0); - - if (recv_return == -1) + int recv_len = 0; + do { - std::cerr << "receive message context error, errno=" << errno << ".@Socket::recv" << std::endl; - delete[] buf; + int cur_len = ::recv(this->sock, buf + recv_len, msg_len - recv_len, 0); - return 0; - } - else - { - _msg = buf; - delete[] buf; + if (cur_len == -1) + { + std::cerr << "receive message context error, errno=" << errno << ".@Socket::recv" << std::endl; + delete[] buf; - return recv_return; - } + return 0; + } + recv_len += cur_len; + }while (recv_len < msg_len); + + _msg = buf; + delete[] buf; + + return msg_len; } bool Socket::connect(const std::string _hostname, const unsigned short _port)