This commit is contained in:
tqchen 2014-12-03 11:19:43 -08:00
parent ceeb6f0690
commit a186f8c3aa

View File

@ -336,23 +336,25 @@ class TCPSocket : public Socket{
* \param str the string to be sent * \param str the string to be sent
*/ */
inline void SendStr(const std::string &str) { inline void SendStr(const std::string &str) {
unsigned len = static_cast<int>(str.length()); int len = static_cast<int>(str.length());
utils::Assert(this->SendAll(&len, sizeof(len)) == sizeof(len), utils::Assert(this->SendAll(&len, sizeof(len)) == sizeof(len),
"error during send SendStr"); "error during send SendStr");
utils::Assert(this->SendAll(str.c_str(), str.length()) == str.length(), if (len != 0) {
"error during send SendStr"); utils::Assert(this->SendAll(str.c_str(), str.length()) == str.length(),
"error during send SendStr");
}
} }
/*! /*!
* \brief recv a string from network * \brief recv a string from network
* \param out_str the string to receive * \param out_str the string to receive
*/ */
inline void RecvStr(std::string *out_str) { inline void RecvStr(std::string *out_str) {
unsigned len; int len;
utils::Assert(this->RecvAll(&len, sizeof(len)) == sizeof(len), utils::Assert(this->RecvAll(&len, sizeof(len)) == sizeof(len),
"error during send RecvStr"); "error during send RecvStr");
out_str->resize(len); out_str->resize(len);
if (len != 0) { if (len != 0) {
utils::Assert(this->RecvAll(&(*out_str)[0], len) == len, utils::Assert(this->RecvAll(&(*out_str)[0], len) == out_str->length(),
"error during send SendStr"); "error during send SendStr");
} }
} }