阻止套接字触发了哪些事件? [英] What events are fired for a blocking socket?
问题描述
出于好奇,如果是ThreadBlocking类型,则将触发TServerSocket / TClientSocket中的哪些事件?
Out of curiosity, what events in TServerSocket/TClientSocket are fired if it is a ThreadBlocking type?
推荐答案
TClientSocket
处于阻止模式会触发其所有事件,但 OnRead
和 OnWrite
除外。另外,仅当客户端关闭其自己的套接字末端时,才会在远程断开连接上触发 OnDisconnect
事件。代码负责读取/写入数据以检测这些套接字状态。通过 TWinSocketStream.WaitForRead()
或WinSock select()
函数可以检测到可读性。仅通过WinSock select()
函数检测可写性。通过首先检测可读性,然后 TCustomWinSocket.ReceiveBuf()
或 TWinSocketStream.Read()
,返回0来检测远程断开连接。
TClientSocket
in blocking mode fires all of its events except for OnRead
and OnWrite
. Also, the OnDisconnect
event is not triggered on a remote disconnect, only when the client closes its own end of the socket. It is the responsibility of code that is reading/writing data to detect these socket states. Readibility is detected via TWinSocketStream.WaitForRead()
or the WinSock select()
function. Writibility is detected via the WinSock select()
function only. Remote disconnect is detected by first detecting readablity and then TCustomWinSocket.ReceiveBuf()
or TWinSocketStream.Read()
returning 0.
TServerSocket
默认情况下会触发其所有事件。但是,如果您从 TServerClientThread
派生一个类,该类将覆盖虚拟的 ClientExecute()
方法,然后返回一个实例。 OnGetThread
事件中的该类,则您丢失了 OnRead
和 OnWrite
事件,并且必须在阻塞模式下使用与 TClientSocket
类似的逻辑来检测这些套接字状态。
TServerSocket
in blocking mode fires all of its events by default. However, if you derive a class from TServerClientThread
that overrides the virtual ClientExecute()
method, and then return an instance of that class from the OnGetThread
event, then you lose the OnRead
and OnWrite
events and have to use similar logic to TClientSocket
in blocking mode to detect those socket states.
这篇关于阻止套接字触发了哪些事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!