OnReset (Socket function): Difference between revisions
m (→Syntax terms) |
(Automatically generated page update) |
||
(2 intermediate revisions by one other user not shown) | |||
Line 5: | Line 5: | ||
when a <var>RESET</var> socket is encountered in the current or a lower program scope. | when a <var>RESET</var> socket is encountered in the current or a lower program scope. | ||
It can also be used to clear without replacing an existing <var>ONRESET</var> label. | It can also be used to clear without replacing an existing <var>ONRESET</var> label. | ||
The <var>OnReset</var> function has an effect similar to <var>[[$ | The <var>OnReset</var> function has an effect similar to <var>[[$Sock_OnReset]]</var>. | ||
==Syntax== | ==Syntax== | ||
Line 15: | Line 15: | ||
<td>Numeric return string, which is to contain 0 (success) or a negative integer (see <var class="term">label</var>, below). | <td>Numeric return string, which is to contain 0 (success) or a negative integer (see <var class="term">label</var>, below). | ||
</td></tr> | </td></tr> | ||
<tr><th><var>%(Socket)</var></th> | <tr><th><var class="nobr">%(Socket)</var></th> | ||
<td>The class name in parentheses denotes a shared method. | <td>The class name in parentheses denotes a shared method. <var>OnReset</var> can also be invoked via a <var>Socket</var> object variable, which may be <var>Null</var>.</td></tr> | ||
</td></tr> | |||
<tr><th>label</th> | <tr><th>label</th> | ||
<td>The label in the program to which to jump to for <var>ONRESET</var> handling. If <var class="term">label</var> is the null string or all blanks, any existing <var>ONRESET</var> label in the current scope is cleared, and <var>OnReset</var> returns: <ul> <li>-3, if <var>OnReset</var> is issued from an <var>ON</var> unit <li>-1, otherwise </ul> | <td>The label in the program to which to jump to for <var>ONRESET</var> handling. If <var class="term">label</var> is the null string or all blanks, any existing <var>ONRESET</var> label in the current scope is cleared, and <var>OnReset</var> returns: <ul> <li>-3, if <var>OnReset</var> is issued from an <var>ON</var> unit <li>-1, otherwise </ul> |
Latest revision as of 00:59, 16 February 2014
Jump to label when this socket resets (Socket class)
This callable, shared method
specifies the label in the User Language sockets program to jump to
when a RESET socket is encountered in the current or a lower program scope.
It can also be used to clear without replacing an existing ONRESET label.
The OnReset function has an effect similar to $Sock_OnReset.
Syntax
[%number =] %(Socket):OnReset[( [label])]
Syntax terms
%number | Numeric return string, which is to contain 0 (success) or a negative integer (see label, below). |
---|---|
%(Socket) | The class name in parentheses denotes a shared method. OnReset can also be invoked via a Socket object variable, which may be Null. |
label | The label in the program to which to jump to for ONRESET handling. If label is the null string or all blanks, any existing ONRESET label in the current scope is cleared, and OnReset returns:
|
Usage notes
- If label is a valid label and the OnReset function call is successful, any existing ONRESET label definition in the current scope is replaced, and OnReset returns 0.
- If the OnReset call fails to clear or to set the ONRESET label, the request is cancelled.
OnReset can fail for the following reasons:
- label is not found in the current scope.
- label is a subroutine.
- OnReset is invoked from an ON unit, and label is neither the null string nor all blank.
- label is in a loop, ON unit, or simple subroutine.
- OnReset is not affected by any ONRESET setting.
- A request may have multiple ONRESET labels set: as many as one for each
scope (the outer level of a request is a scope, as is each complex subroutine).
As described in "Handling connection errors and RESET sockets",
a jump to an ONRESET label is attempted if both of these are true:
- A RESET socket is encountered during a Janus Sockets operation
- The socket's ONRESET setting
is
LABEL
(orLABELC
, if the operation requires an OPEN socket)
- An attempted jump to a label is successful if there is an ONRESET label within the current or an invoking scope of the User Language request that encountered the RESET socket. If there is no such label, the User Language request is cancelled.
- Using OnReset to set an ONRESET handler reduces the amount of return code checking the application has to do on each method call.
Example
As a result of the OnReset code in the following example, encountering a RESET socket will print a set of error messages that provide the failing operation, return code, and socket identifier before terminating evaluation:
Call %(Socket):OnReset('KABOOM') ... KABOOM: %c = %(Socket):Errinfo('CODE') %s = %(Socket):Errinfo('SOCKNUM') %f = %(Socket):Errinfo('FUN') Print 'The connection was unexpectedly lost.' Print 'The last sockets error operation was:' Print 'Function: ' with %f Print 'Return code: ' with %c Print 'Socket: ' with %s Stop