COMCLOSE
The COMCLOSE instruction terminates activity on a communications device. The instruction uses the following format:
|
|
|
|
|
Where:
label
Optional. A Program Execution Label.
comfile
Required. A previously defined and opened COMFILE definition.
mode
Optional. A Numeric Variable whose value control the actions of operation.
Flags Affected: NONE
Note the following:
The {mode} value supported only applies to a {comfile} created for socket support.
The {mode} bit definition in this case is as follows:
|
Mode |
Meaning |
|
0x0 |
Close and destroy the socket. |
|
0x1 |
For a created socket, disconnect the current connection |
|
0x2 |
For an opened socket, shutdown the socket without closing it |
When a COMCLOSE is executed with the {mode} set to 0x2, a socket shutdown
operation is executed. Next, a COMCLOSE statement must be executed with the {mode} set to 0x1 or 0x0
that closes a socket completely.
The two-step COMCLOSE combination performs a soft close of the socket that causes the other end of
a connection to receive a connection reset message. For most protocols, this is an error but there are
many cases where this is desirable. In addition, it should be pointed out that a COMCLOSE with the {mode}
set to 0x2 causes an indeterminate can-write byte returned by the COMSTAT
statement until a COMCLOSE with the {Mode} set to zero or one is executed. Any attempt to write to a
socket that has been closed with the {mode} set to 0x2 results in an error.
When a socket is closed with no mode or mode 0x, it takes up to two minutes before the socket can be recreated on the same port. The amount of time varies by operating system. To simply close a connection, use mode 0x1 and the socket is immediately available for more incoming connections.
See Also: COMOPEN, Communication I/O Instructions
![]() |