阅读:2339回复:8
socket同步/异步方式的区别
socket同步/异步方式的区别?最好从协议处理和驱动低层讲一下,谢谢!同步方式返回是到IP层,还是到由驱动发送设备缓冲区后?
|
|
沙发#
发布于:2002-08-12 19:08
在Socket中,你完全不用理会低层的问题。同步和异步同通讯中常提到的同异步是一样的概念,一般我们都使用异步通讯。
还有,一旦Socket连接成功,内部会自动在双方分配缓存,你要作的就是在缓存满之前将数据取走,如果你用的是TCP/IP协议的话。 |
|
板凳#
发布于:2002-08-13 16:40
我用的是UDP。请问同步方式时,send函数是什么时候返回的?
|
|
地板#
发布于:2002-08-15 08:25
不同的tcpip实现(操作系统),可能不同。
|
|
|
地下室#
发布于:2002-08-16 11:11
的确是这样?那里可以找到这方面的资料?
我发现在NT4.0下,同步/异步发送没有区别,而在Win2000下,同步/异步才有区别,现在我把程序转到Win2000下,采用异步方式,效率提高了不少! |
|
5楼#
发布于:2002-08-16 11:26
经过实验,我发现在NT4.0下,同步/异步发送没有区别,而在Win2000下,同步/异步才有区别,现在我把程序转到Win2000下,采用异步方式,效率提高了不少!
看来不同的tcpip实现(操作系统),可能不同,哪里可以找到这方面的资料? 并且,我还发现同一个网卡,win2000下,同步send,使用不同的驱动程序,send函数的耗费时间在网络吞吐较高的情况下有较大差异,产生此现象原因是什么?驱动程序如何导致这一现象的?请指点,谢谢! |
|
6楼#
发布于:2002-08-16 16:02
我测了一些数据(两个不同的计算机)
Win2000: Send time of packet(1200 BYTES) Bolcking Mode: about 80 us/packet Non-block Mode: about 20 us/packet Win NT: Send time of packet(1200 BYTES) Bolcking Mode: about 105 us/packet Non-block Mode:about 105 us/packet 不知道为什么会这样。你能帮我解释吗? |
|
7楼#
发布于:2002-08-17 23:14
我测了一些数据(两个不同的计算机) 这充分说明了NT4网络层没有2000的好 另外,你在2000下使用同步和异步有这样的差别,可能是因为你只有发送了一次数据的缘故,如果你在一端连续(当然你可能需要使用Sleep等来延时)发送数据,其差别恐怕不一样了,前提是网络的另外一端能够正确接收数据。 |
|
|
8楼#
发布于:2002-08-21 14:04
各位驱动大侠,下面的解释是否合理?
In nonblocking mode AFD.DLL & AFD.SYS ( transport level before UDP/TCP and IP ) do copy of your data to system ( TCP/UDP stack ) and release you app to continue all next flow is done concurrently with your app , but in blocked mode you wait up to data will be send by driver ( NDIS ) and on only after that received back the result and continue to flow. So the results in W2K is obvious , but result of NT are not and the only explanation is ( if your measurements are correct ) that most of time system spend in NT on coping the data but sending is very quick, which looks very strange. In TCP IO it\'s very common to receive WSAEWOULDBLOCK which mean that operation is still in process for non-blocked sockets both in the NT and W2K but during that time you can do some calculations where in blocked socket you locked on IO operation. Maybe because UDP don\'t do all packet checking the that times for UDP have no difference opposite to TCP. Arkady |
|