在这种情况下,我应该为每个WSASend调用传递唯一的重叠结构吗?
Should i pass unique OVERLAPPED structure for each WSASend call , in this case?
我有一个套接字列表。打开的连接(
我有 n 个工作线程。
线程循环:
while (1)
{
_this.result = GetQueuedCompletionStatus(a_server.server_iocp, &_this.numberOfBytesTransfered,
&_this.completionKey, (OVERLAPPED**)&_this.iocp_task, INFINITE);
...
}
我有这个简单的结构:
struct iocp_send_global :public iocp_task<IOCP_SEND_GLOBAL> {
OVERLLAPED ov; //overlapped struct at top
std::atomic_uint32_t ref;
bool decr_ref(){ return ref.fetch_sub(1, std::memory_order_acq_rel) == 1;}
//packet data here
}
...
这是"广播"功能:
iocp_send_global * packet = new iocp_send_global;
[set packet data here]
for(int i=0;i<connectionsCount;++i){
WSASend(connections[i],...,&packet,...); //posting same packet to all connections
}
我想在 GetQueuedCompletionStatus 调用返回具有重叠结果后在工作线程循环中执行此操作;
if (_this.iocp_task->type == IOCP_SEND_GLOBAL) {
auto* task = (iocp_send_global*)_this.iocp_task;
if (!task->decr_ref()) {
_this.iocp_task = nullptr;
//dont delete the task yet,
//all send post must finish first
//[all posts share the same buffer]
}
else {
//delete the task containing the send data after all send posts finished
delete _this.iocp_task;
_this.iocp_task = nullptr;
}
}
从我在WSASend文档中读到的内容Microsoft每个WSASend重叠调用sould都有自己的重叠结构传递,但是当我WSASend相同的缓冲区时,这是否有效?
谢谢!
您必须为每个调用传递不同的OVERLAPPED
缓冲区,因为您将进行多个挂起的调用。 这在OVERLAPPED
结构的文档中有明确说明。
相关文章:
- 何时在引用或唯一指针上使用移动语义
- Ardunio UNO解决了多个重叠的定时器循环
- C++优先级队列,按对象的唯一指针的特定方法升序排列
- 计算排序向量的向量中唯一值的计数
- 在c++中检查长方体是否尽可能快地重叠(无迭代)
- 如何使用Visual Studio 2017在C++中为参数化对象数组使用唯一指针
- 算术序列与区间的最大重叠
- 通过组合不同的类型来创建唯一的id
- 使用Unique_ptr确保工厂中的对象唯一
- c++多进程编写一个唯一的文件
- 在以唯一ptr为值的C++映射中,动态内存何时会被销毁
- 如何更改唯一指针向量的可见性
- 在C++的两个字符串中连接以逗号分隔的唯一值
- 共享指针和具有自定义删除程序的唯一指针之间的语法差异背后的任何原因
- C++尝试深度复制唯一指针时出现内存访问冲突
- 具有引用成员的结构是否具有唯一的对象表示形式
- 使用 RTTI 克隆唯一指针的向量
- 如何在 c++ 中迭代数组中的唯一元素
- 按顺序声明的字符数组重叠
- 在这种情况下,我应该为每个WSASend调用传递唯一的重叠结构吗?