当前位置: 首页>>代码示例>>C++>>正文


C++ Sock::receive方法代码示例

本文整理汇总了C++中Sock::receive方法的典型用法代码示例。如果您正苦于以下问题:C++ Sock::receive方法的具体用法?C++ Sock::receive怎么用?C++ Sock::receive使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Sock的用法示例。


在下文中一共展示了Sock::receive方法的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;
}
开发者ID:michael-popov,项目名称:clockwork,代码行数:42,代码来源:mxdemo.cpp

示例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();
}
开发者ID:michael-popov,项目名称:clockwork,代码行数:24,代码来源:load_maker.cpp


注:本文中的Sock::receive方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。