为什么ws2_32在函数调用终止之前发送不工作? [英] why is ws2_32 send not working until after function-call terminates?

查看:59
本文介绍了为什么ws2_32在函数调用终止之前发送不工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


(这个问题在WSK论坛上首次[天真]发布。) 


我是使用VC ++ 2008构建一个DLL,它使用ws2_32 函数通过TCP协议将命令发送到另一个应用程序(然后等待响应)。   DLL目前实现了一些功能,包括Connect,WriteRead和
Close。   Connect 获取套接字描述符。   WriteRead函数调用"发送"按钮(发送命令) 后跟"recv" (收到回复)。


WriteRead没有按预期工作,因为直到WriteRead终止后才发送命令。  我已尝试在"发送"之后进行5秒钟的睡眠。 (发送,睡眠(5000),recv),给予充足的时间。 
即使有延迟,在DLL WriteRead函数调用终止之前,[sent] 命令才会出现在目标应用中。  我已经尝试将套接字选项设置为TCP_NODELAY配置的ioctl用于阻塞和非阻塞模式。


显然WriteRead无法"recv"除非 "发送"在函数调用期间工作。


我的最后一个实验是在一个衍生线程(_beginthread)中调用Write(send)-logic但是到目前为止我只设法使应用程序崩溃正在调用DLL。


感谢任何帮助!

解决方案

你有一些代码吗? ...

Hi,

(This question was first [naively] posted in the WSK forum.) 

I'm using VC++ 2008 to build a DLL which uses ws2_32 functions to send commands to another application (then waits for a response) via a TCP protocol.  The DLL currently implements a few functions, including Connect, WriteRead, and Close.  Connect gets the socket descriptor.  The WriteRead function calls "send" (sends a command) followed by "recv" (receives a response).

WriteRead isn't working as intended because the command isn't sent until immediately after WriteRead terminates.  I have experimented with putting a 5 second sleep after the "send" (send, Sleep(5000), recv), to give send plenty of time.  Even with the delay, the [sent] command doesn't appear at target app until after the DLL WriteRead function-call terminates.  I've tried setting socket options to TCP_NODELAY configured ioctl for blocking and nonblocking modes.

Obviously WriteRead isn't going to be able to "recv" a response unless "send" works during the function-call.

My last experiment was to call the Write(send)-logic in a spawned-thread (_beginthread) but so far I only manage to crash the app which is calling the DLL.

Any help is appreciated!

解决方案

do you have some code? ...


这篇关于为什么ws2_32在函数调用终止之前发送不工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆