CAsyncSocket和ThreadPool问题
我有一个具有以下结构的服务器应用程序: 有一个对象,称为服务器,它无限循环地侦听并接受连接。 我有 CAsyncSocket 的后代类,它重写了 OnReceive 事件,称他为 ProxySocket。 我还有一个带有早期创建的线程的线程池。
当服务器对象接收到连接时,他接受新对象 ProxySocket 上的新连接。 当数据到达ProxySocket时,他创建一个命令对象并将其交给线程池。在此命令对象中,我给出了 ProxySocket 的套接字句柄。当创建新的命令对象时 - 我在工作线程中创建一个新的套接字并将句柄附加到它。
我的问题是下一个: 当命令结束时,套接字不会关闭,我只是按照计划分离它的句柄并将 CSocket 句柄设置为 INVALID_SOCKET 值。但是我的第一个 ProxySocket 对象在此之后没有收到新数据接收的消息。我该如何解决这个问题?
I have a server application with such structure:
There is one object, call him Server, that in endless cycle listens and accepts connections.
I have descendant class from CAsyncSocket, that has overriden event OnReceive, call him ProxySocket.
Also I have a thread pool with early created threads.
When connection is received by server object he accepts the new connection on the new object ProxySocket.
When data arrives to the ProxySocket, he creates a command object and gives it to thread pool. In this command object I giving the socket handle of a ProxySocket. When new object of command is creating - I creating a new Socket in working thread and attach handle to it.
My issue is next:
When command ends, socket doesn't close, I just detach handle it and set CSocket handle to INVALID_SOCKET value, as planned. But my first ProxySocket object doesn't receives messages of new data receiving after that. How can I solve this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为您不能在线程池场景中使用 CAsyncSocket 对象(或其后代)。 CAsyncSockets 是在 WSASsyncSelect 之上实现的 - 它告诉 Winsock 将通知发送到窗口句柄。
由于 Windows 具有线程关联性,因此永远无法将 CAsyncSocket 处理“移动”到不同的线程。
I don't think you can use CAsyncSocket objects (or their descendants) in a thread pool secenario. CAsyncSockets are implemented on top of WSASsyncSelect - which tells the winsock to send notifcations to a window handle.
Because windows have thread affinity, one can never "move" the CAsyncSocket handling to a different thread.