呼叫send()关闭申请的情况下没有错误
Calling send() closes the applicaiton without error
我有一个客户端应用程序通过TCP发送数据。在某个时候,请致电发送()返回,而无需发送所有可用的bytes和下一个呼叫以发送申请即可发送申请。
调用send()的循环看起来像:
// m_buf is an std::vector of size 65536
auto total_bytes = fill_buffer(m_buf.data(),m_buf.size());
while(total_bytes > 0){
// m_socket is a straightforward wrapper around a socket descriptor that
// throws if a call to send() returns an error.
auto total_bytes_sent = m_socket.send(m_buf.data(),total_bytes);
auto remaining_bytes = total_bytes - total_bytes_sent;
while(remaining_bytes > 0){
total_bytes_sent += m_socket.send(m_buf.data()+total_bytes_sent,remaining_bytes);
remaining_bytes = total_bytes - total_bytes_sent;
}
total_bytes = fill_buffer(m_buf.data(),m_buf.size());
}
我也有一些调试打印:
send: total_bytes 65536
send: total_bytes_sent 65536
send: remaining_bytes 0
send: total_bytes 65536
send: total_bytes_sent 65536
send: remaining_bytes 0
send: total_bytes 65536
send: total_bytes_sent 65536
send: remaining_bytes 0
send: total_bytes 65536
send: total_bytes_sent 65536
send: remaining_bytes 0
send: total_bytes 65536
send: total_bytes_sent 65536
send: remaining_bytes 0
send: total_bytes 65536
send: total_bytes_sent 65536
send: remaining_bytes 0
send: total_bytes 65536
send: total_bytes_sent 65536
send: remaining_bytes 0
send: total_bytes 65536
send: total_bytes_sent 8127
send: remaining_bytes 57409
[computer@localhost test]$
在末尾,send()被召唤发送剩余的_bytes,但呼叫永远不会返回(也没有例外)关闭。
一种可能性是您从send()获得错误返回,但您没有检查-1。这可能会使total_bytes_sent成为负数,这将使您的第二个发送到无效的内存中。
相关文章:
- 如何在不知道C++中有多少可选参数的情况下在循环中使用va_arg?
- 有没有办法在不使用 getline() 的情况下从.csv文件中读取?
- 有没有办法在不使用 #ifdef 的情况下不编译发布版本中的单元测试函数体?
- C++有什么方法可以在既不调用函数模板也不提供其模板参数的情况下引用函数模板?
- 我的调试器说我有一个隔离错误错误,但无法告诉我在哪里,在非常特殊的情况下发生
- 呼叫send()关闭申请的情况下没有错误
- 在不包括任何内容的情况下获得错误声音
- 为什么在这种情况下打印错误
- 为什么std::istringstream在没有引发故障位标志的情况下生成错误的结果
- LeetCode210.为什么我的代码在特定情况下是错误的
- C++ 异常情况下的错误 C2228(".val"的左侧必须具有类/结构/联合)
- 为什么我在没有calloc函数的情况下得到错误运行时
- 如何在给定指向派生类型的指针的情况下有条件地将指针强制转换为基类型
- Visual Studio 2010在没有错误的情况下,错误地在代码/注释下面加上红色错误线
- 无效使用不完整的类型-为什么在这种情况下没有错误
- 如何在不打印的情况下获取C++错误(errno)消息
- c++在没有tryCatch块的情况下捕获错误输入
- Winsock: Overlapped AcceptEx表示在没有客户端连接的情况下有一个新的连接
- 在不更改成员范围的情况下有条件地启用静态成员
- 一个模板专门化用于pod,一个模板专门化用于类层次结构,在其他情况下出现错误