【问题标题】:outputting a buffer stream输出缓冲流
【发布时间】:2016-03-15 12:02:15
【问题描述】:

我只是想显示我从一个以“\r\n\r\n”结尾的 tcp 套接字接收到的消息。

但是,即使服务器指示消息已成功传输,C++ 也会立即终止。

        void handle_read( const boost::system::error_code& error, size_t bytes_transferred)
{
    std::istream response_stream(&response_);
    std::string incoming;
    std::string res_time = make_daytime_string();
    while (std::getline(response_stream, incoming) && incoming != "\r")
         std::cout << incoming << std::endl;
    std::cout <<"message received on "<< res_time <<std::endl;
}

在 Eclipse 中,我在控制台中看到以下内容, (退出值 = -1) 当程序终止时,如果我切换到 Linux 的控制台,我会看到以下错误: * `/home/administrator/Documents/eclipse/Projects/Asynchronous_TCP/Debug/Asynchronous_TCP' 中的错误:双重释放或损坏 (!prev):0x0000000001040580 *

【问题讨论】:

  • 如果你在单线程 io_service 上运行它,它很有可能会失败,因为你在完成处理程序中(因此你阻塞了事件循环)。如果您将其设为 SSCCE,我们可以对其进行验证。并可能提出修复建议

标签: boost tcp buffer cout


【解决方案1】:

已解决 显然我只需要解决套接字连接

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-09-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-10-25
    相关资源
    最近更新 更多