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
*/
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),
"error during send SendStr");
utils::Assert(this->SendAll(str.c_str(), str.length()) == str.length(),
"error during send SendStr");
if (len != 0) {
utils::Assert(this->SendAll(str.c_str(), str.length()) == str.length(),
"error during send SendStr");
}
}
/*!
* \brief recv a string from network
* \param out_str the string to receive
*/
inline void RecvStr(std::string *out_str) {
unsigned len;
int len;
utils::Assert(this->RecvAll(&len, sizeof(len)) == sizeof(len),
"error during send RecvStr");
out_str->resize(len);
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");
}
}