Fortinet white logo
Fortinet white logo

Script Reference Guide

TCP:after_timer_set(timer_cb_name, timeout, periodic)

TCP:after_timer_set(timer_cb_name, timeout, periodic)

Allows the user to create and schedule a timer with a callback function and timeout value. This allows you to create multiple timers each with a unique callback function name. Periodic timers will be executed periodically until the associated session is closed or the after_timer is closed.

Returns Boolean true if successful, otherwise, returns Boolean false.

Syntax

TCP:after_timer_set (timer_cb_name, timeout, periodic);

Arguments

Name Description

timer_cb_name

A string of the callback function name. This is also the unique identification of a timer. This parameter is required.

timeout

An integer as the timeout value in milliseconds. This parameter is required.

periodic

A Boolean to indicate whether this timer is periodic. This parameter is required.

Events

Applicable in the following events:

  • HTTP_DATA_REQUEST

  • HTTP_DATA_RESPONSE

  • HTTP_REQUEST

  • HTTP_RESPONSE

  • SERVER_BEFORE_CONNECT

  • SERVER_CONNECTED

  • TCP_ACCEPTED

Example

when TCP_ACCEPTED {
    debug("[%s]------> TCP accepted begin:\n",ctime());
	local_count = 10
	cip = IP:client_addr();
	debug("[%s]------> client IP %s\n", ctime(),cip);
	cport = IP:client_port();
	debug("[%s]------> client Port %s\n", ctime(),cport);
	debug("[%s]------> local_count= %d\n", ctime(),local_count);
	debug("[%s]------> After function called here.\n",ctime());
 
	AFTER_TIMER_NAME = function ()
		debug("[%s]=======> After function call begin:\n",ctime())
		cport = IP:client_port();
		debug("[%s]=======> client Port %s\n",ctime(),cport);
		debug("[%s]=======> After function call end.\n",ctime())
	end
 
	TCP:after_timer_set("AFTER_TIMER_NAME", 5000, true);
}

When the client successfully creates a TCP connection, the script will be executed. The function will be executed every 5 seconds (5000 milliseconds) and print out the text.

FortiADC console debug output:

[Thu Jan 11 16:30:50 2024]------> TCP accepted begin:
[Thu Jan 11 16:30:50 2024]------> client IP 10.1.0.161
[Thu Jan 11 16:30:50 2024]------> client Port 37818
[Thu Jan 11 16:30:50 2024]------> local_count= 10
[Thu Jan 11 16:30:50 2024]------> After function called here.
[Thu Jan 11 16:30:55 2024]=======> After function call begin:
[Thu Jan 11 16:30:55 2024]=======> client Port 37818
[Thu Jan 11 16:30:55 2024]=======> After function call end.
[Thu Jan 11 16:31:00 2024]=======> After function call begin:
[Thu Jan 11 16:31:00 2024]=======> client Port 37818
[Thu Jan 11 16:31:00 2024]=======> After function call end.

Supported Version

FortiADC version 7.4.1 and later.

TCP:after_timer_set(timer_cb_name, timeout, periodic)

TCP:after_timer_set(timer_cb_name, timeout, periodic)

Allows the user to create and schedule a timer with a callback function and timeout value. This allows you to create multiple timers each with a unique callback function name. Periodic timers will be executed periodically until the associated session is closed or the after_timer is closed.

Returns Boolean true if successful, otherwise, returns Boolean false.

Syntax

TCP:after_timer_set (timer_cb_name, timeout, periodic);

Arguments

Name Description

timer_cb_name

A string of the callback function name. This is also the unique identification of a timer. This parameter is required.

timeout

An integer as the timeout value in milliseconds. This parameter is required.

periodic

A Boolean to indicate whether this timer is periodic. This parameter is required.

Events

Applicable in the following events:

  • HTTP_DATA_REQUEST

  • HTTP_DATA_RESPONSE

  • HTTP_REQUEST

  • HTTP_RESPONSE

  • SERVER_BEFORE_CONNECT

  • SERVER_CONNECTED

  • TCP_ACCEPTED

Example

when TCP_ACCEPTED {
    debug("[%s]------> TCP accepted begin:\n",ctime());
	local_count = 10
	cip = IP:client_addr();
	debug("[%s]------> client IP %s\n", ctime(),cip);
	cport = IP:client_port();
	debug("[%s]------> client Port %s\n", ctime(),cport);
	debug("[%s]------> local_count= %d\n", ctime(),local_count);
	debug("[%s]------> After function called here.\n",ctime());
 
	AFTER_TIMER_NAME = function ()
		debug("[%s]=======> After function call begin:\n",ctime())
		cport = IP:client_port();
		debug("[%s]=======> client Port %s\n",ctime(),cport);
		debug("[%s]=======> After function call end.\n",ctime())
	end
 
	TCP:after_timer_set("AFTER_TIMER_NAME", 5000, true);
}

When the client successfully creates a TCP connection, the script will be executed. The function will be executed every 5 seconds (5000 milliseconds) and print out the text.

FortiADC console debug output:

[Thu Jan 11 16:30:50 2024]------> TCP accepted begin:
[Thu Jan 11 16:30:50 2024]------> client IP 10.1.0.161
[Thu Jan 11 16:30:50 2024]------> client Port 37818
[Thu Jan 11 16:30:50 2024]------> local_count= 10
[Thu Jan 11 16:30:50 2024]------> After function called here.
[Thu Jan 11 16:30:55 2024]=======> After function call begin:
[Thu Jan 11 16:30:55 2024]=======> client Port 37818
[Thu Jan 11 16:30:55 2024]=======> After function call end.
[Thu Jan 11 16:31:00 2024]=======> After function call begin:
[Thu Jan 11 16:31:00 2024]=======> client Port 37818
[Thu Jan 11 16:31:00 2024]=======> After function call end.

Supported Version

FortiADC version 7.4.1 and later.