TCPBlock

Command group Flag affected Reversible Execute on client Platform(s)
External commands YES NO NO All

Syntax

TCPBlock (socket,option {Zero for blocking; Non-zero for non-blocking}) Returns status

Description

Note: The flag is set according to whether Omnis was able to make a call to this external command.

This Web command is multi-threaded, allowing another thread to execute in the multi-threaded server while it runs. Note that the same socket cannot safely be used concurrently by more than one thread.

The TCPBlock command makes a socket blocking or non-blocking.

The blocking state of a socket affects the commands TCPAcceptTCPReceiveTCPSend, and HTTPSend. If you use TCPBlock to change the blocking state of sockets returned for FTP connections, this could result in undesirable behavior of the FTP commands.

If a socket is blocking, the commands listed above wait until they can complete successfully; in other words, a receive waits until it has received some data, a send waits until it has sent some data, and an accept waits until an incoming connection request arrives.

If a socket is non-blocking, the commands listed above will complete successfully if they can do so immediately; if not, they will return the error code –10035, which means that the command needs to block before it can complete successfully.

Socket is an Omnis Long Integer field containing a number identifying a valid socket.

Option is an Omnis integer field. Non-zero means non-blocking and zero means blocking.

Status is an Omnis Long Integer field which receives the value zero for success, or an error code < 0 for failure. Possible error codes are listed in the Web Command Error Codes Appendix.

Note:

If the connection is secure (see TCPConnect) then calls to TCPSend will always be blocking, even if the socket is marked as non-blocking.

Example

# Listen for incoming connections with blocking off
Calculate iPort as 6000
TCPSocket Returns iSocket
TCPBind (iSocket,iPortReturns lStatus
TCPBlock (iSocket,1) Returns lStatus
TCPListen (iSocketReturns lStatus
If lStatus=0
  Repeat
    TCPAccept (iSocketReturns lConnectedSocket
  Until lConnectedSocket>=0
  # client connected
End If
TCPClose (iSocketReturns lStatus