本文整理汇总了C++中Sock::send方法的典型用法代码示例。如果您正苦于以下问题:C++ Sock::send方法的具体用法?C++ Sock::send怎么用?C++ Sock::send使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Sock
的用法示例。
在下文中一共展示了Sock::send方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: execCommand
void execCommand(string& str)
{
cdb::StringUtils::trim(str);
if (str.empty()) return;
if (str == "exit" || str == "quit") {
g_keepGoing = false;
return;
}
vector< string > tokens;
cdb::StringUtils::split(str, " ", tokens);
if (tokens.size() == 2 && tokens[0] == "start") {
int threadCount = boost::lexical_cast<int>(tokens[1]);
loadTest(threadCount);
return;
}
int ret;
uint16_t length = str.length();
ret = g_sock.send((const char*)& length, 2);
if (ret != 2) THROW("Failed to send command's length");
ret = g_sock.send(str.c_str(), length);
if (ret != length) THROW("Failed to send command");
ret = g_sock.receive((char*) &length, 2);
if (ret != 2) THROW("Failed to receive response length");
if (g_buffer.size() < length) {
g_buffer.extend(length - g_buffer.size() + 1);
}
g_buffer.clear();
ret = g_sock.receive(g_buffer.raw(), length);
if (ret != length) THROW("Failed to receive response");
g_buffer.commit(length);
g_buffer.closeText();
cout << g_buffer.raw() << endl;
}
示例2: execCommand
static void execCommand(Sock& sock, string& str, Buffer& buffer)
{
int ret;
uint16_t length = str.length();
ret = sock.send((const char*)& length, 2);
if (ret != 2) THROW("Failed to send command's length");
ret = sock.send(str.c_str(), length);
if (ret != length) THROW("Failed to send command");
ret = sock.receive((char*) &length, 2);
if (ret != 2) THROW("Failed to receive response length");
if (buffer.size() < length) {
buffer.extend(length - buffer.size() + 1);
}
buffer.clear();
ret = sock.receive(buffer.raw(), length);
if (ret != length) THROW("Failed to receive response");
buffer.commit(length);
buffer.closeText();
}