CloseStream

(Engine-Level Function)

Description: Closes and flushes any type of open stream and returns its own error code.
Returns: Boolean
Usage: Script Only.
Function Groups: Stream and Socket
Related to: BuffStream | FileStream | PipeStream | StreamEnd
Format: CloseStream(Stream[, CloseType])
Parameters:  
Stream
Required. Any expression that returns a stream value.
CloseType

Optional. Short integer with the following definitions:

0 STREAM_CLOSE_NORMAL, // Graceful shutdown - finish what you're doing first
1 STREAM_CLOSE_HARD, // Abortive shutdown - throw away outstanding work. To be used only when there is a valid reason such as the detection of a malicious request.
2 STREAM_TRANSACTION_END, // Flush the outgoing message and wait for the other end to close the connection.
Comments: The return value is true if the stream is successfully closed and invalid otherwise. This function closes the stream passed to it.
If the stream is invalid, or the stream is already closed, nothing happens.

Example:

  If GetStreamLength(Stream) == 0 && ! Valid(CloseOK);
  [
    CloseOK = CloseStream(Stream); 
  ]

This example checks to see if the stream has any data in it, and if it is empty and has not already been closed, closes it, setting CloseOK to 1 if the stream were closed and invalid otherwise.