PureBasic
PureBasic
Check Whether a Socket Is Writable
See more Socket/SSL/TLS Examples
Demonstrates Socket.CheckWriteable, which waits for the connected socket to become writable. It returns 1 if writable, 0 if it did not become writable before the timeout, or -1 on error.
Background. A maxWaitMs of 0 performs a nonblocking poll. This is useful for flow control before attempting a large send.
Chilkat PureBasic Downloads
IncludeFile "CkSocket.pb"
Procedure ChilkatExample()
success.i = 0
socket.i = CkSocket::ckCreate()
If socket.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
; Connect to the server using TLS.
bTls.i = 1
maxWaitMs.i = 5000
success = CkSocket::ckConnect(socket,"example.com",5000,bTls,maxWaitMs)
If success = 0
Debug CkSocket::ckLastErrorText(socket)
CkSocket::ckDispose(socket)
ProcedureReturn
EndIf
; Wait up to 5 seconds for the socket to become writable. Returns 1 if writable, 0 if it did not
; become writable before the timeout, or -1 on error.
writable.i = CkSocket::ckCheckWriteable(socket,5000)
If writable < 0
Debug CkSocket::ckLastErrorText(socket)
CkSocket::ckDispose(socket)
ProcedureReturn
EndIf
If writable <> 1
Debug "The socket did not become writable before the timeout."
CkSocket::ckDispose(socket)
ProcedureReturn
EndIf
Debug "The socket is writable."
CkSocket::ckDispose(socket)
ProcedureReturn
EndProcedure