-
Notifications
You must be signed in to change notification settings - Fork 4
Platform
Sudheer edited this page Jun 29, 2023
·
25 revisions
Allocates size bytes of memory. Throws exception in case of error
It is ensured that a maximum of 1GB of data is allowed to be allocated
per given lua state.
Parameters:
size : integer, requested size of memory
Return:
buf: Pointer to allocated buffer
Runs a mentioned lua script asynchronously, with the inputs provided as string arguments
to the function
The function does not return, any exception has to be managed within the script
Paramters:
Variable number of arguments, with atlease 1
The first string parameter is the lua script to run
Rest of the parametes are arguments to the script
Return:
None
Similar to platform.async_run_lua_script, except that it is ensured that a single instance
of the given script is running, i.e. if an already existing instance of the script is
currently running, another instance will not be started.
Closes the session objects and the associated TCP connection
Parameters:
http_session: Session object acquired by platform.make_http_connection
Return:
None
Closes the given TCP connection
Parameters:
tcp_conn: TCP connection object acquired by platform.make_tcp_connection
Return:
None
Prints details pertaining to TCP connection to standard output
Information printed are
pointer to lua state,
file descriptor of the scoket,
if the socket fd is live
Parameters:
tcp_conn: Socket connection pointer
Return:
None
Prints the thread id of the current thread, along with an optional string argument to
standard output
Parameters:
debug_str: Optional debug string, which will be printed along with the thread id
Return:
None
Suspends execution of a lua thread for time_in_sec seconds
While the lua thread is put in sleep, the underlying OS thread
will process another task
Parameters:
time_in_sec: integer number of seconds the lua thread should sleep
Return:
None
Opens a file and returns the file handle to be used for read and write operations
Parameters:
file_name : type string, contains the filename with path which will be opened
open_mode : mode in which the file will be opened
"r" : Opens the file in read-only mode
"w" : Opens the file in write mode and positions the file pointer at the begining of file
"a" : Opens the file in append mode (reand and write and file pointer at the end)
"r+" : Opens the file in read-write mode with pointer at the begining
"w+" : Opens the file in read-write mode after truncating the file, if the file does not
exist it is created
"a+" : Opens the file in read-write mode in append mode, if the file does not exist it
is created
Return values
fh : file handle using which read and write operations can be achieved
err: In case of any error during the opening process the error is returned in the second
return parameter while fh will have null
Gets the state variable _cl_state in Accepted socket of the platform (evluaserver)
Parameters:
None
Return:
cl_state: boolean, true - the socket is marked for closure, false - socket is not marked
for closure
Sets the state variable _cl_state in Accepted socket of the platform (evluaserver)
Parameters:
cl_state: boolean, true - the socket is marked for closure, false - socket is not marked
for closure
Return:
None
Gets the IP address and the port number being listened to by the current evluaserver
as configured in the properties file.
Parameters:
None
Return:
ip_address: string
port: string
Gets the associated request object with respect to the current request processing lua state
Parameters:
None
Return:
request : Request object
Gets the associated response object with respect to the current response processing lua state
Parameters:
None
Return:
response : Response object
Gets the pointer of lua_State * of the current coroutine for debugging purpose
Parameters:
None
Return:
lua_State : Pointer to lua_State of current coroutine
Gets the file descriptor of the stream socket pointer
Parameters:
ss: stream socket pointer
Return:
fd : integer file descriptor
Gets the upgraded state of the accepted socket of the lua coroutine.
Parameters:
None
Return:
upg : integer, 0 - Not upgraded (still accepts HTTP 1.1 requests), 1 - Upgraded as WEBSOCKET
Gets the lua file that has implemented an object with handle_message function associated with the WEBSOCKET
The handle_message function if implemented will get called upon arrival of a new WEBSOCKET message
Parameters:
None, works on the accepted socket associated with the lua coroutine
Return:
lua_file_name: string, lua file, that should be passed to require as an input parameter to get the handle
to the implementation class
Returns the SMTP client module, which can be used to construct and send emails.
Paramters:
None
Return:
smtp_client : A lua module that contains the functions necessary to construct and send email.
Establishes a TCP connection and constructs a HTTP client object around the TCP connection
and returns the same
Parameters:
server_address: string, Either IP address or URL of the server
port_num: Interger, port number to which the connection has to be established
timeout: Integer, optional parameter, that indicates how long to wait before giving up
Return:
http_session: The client http session object
ss : The underlying stream socket
ERROR:
Throws appropriate error using perror, which can be caught using pcall or xpcall mechanism
Makes the established HTTP session secure
This function must be called after calling netSSL.conect_TLS on ss returned by make_http_connection
Parameters:
http_connection: http_connection, handle to http session
ss: Stream socket
Return:
None
ERROR:
Throws appropriate error using perror, which can be caught using pcall or xpcall mechanism
Establishes a TCP connection and constructs and returns a handle to the connection
Parameters:
server_address: string, Either IP address or URL of the server
port_num: Interger, port number to which the connection has to be established
timeout: Integer, optional parameter, that indicates how long to wait before giving up
Return:
ss : The stream socket
ERROR:
Throws appropriate error using perror, which can be caught using pcall or xpcall mechanism
Constructs a new HTTP request object and returns a handle to the same
Parameters:
None
Return:
http_req: Handle to a HTTP request object
Loads a lua module containg a set of properties access functions
Parameters:
None
Return:
properties_funcs: A lua module with the following functions
properties_funcs.get_bool_property(name): given the string property name, gets the boolean value
properties_funcs.get_int_property(name): given the string property name, gets the integer value
properties_funcs.get_string_property(name): given the string property name, gets the string value
Receives response from a HTTP server after having sent a request on the same connection.
Parameters:
http_session: Client session established via platform.make_http_connection
timeout: Optional, integer value, which indicates the number of seconds to wait for response to arrive
ERROR:
Any error is thrown using perror, can be caught using pcall / xpcall
Interface to receive data from an opened socket connection
Parameters:
ss: Stream socket, either accepted socket or connected socket (via platform.make_tcp_conccetion)
buf: Memory buffer created via alloc_buffer
size: Integer number of bytes to be received
timeout: Optional integer, number of seconds to wait for arrival of the response
Return:
ret: Integer, number of bytes received
ERROR:
Any error is thrown using perror, can be caught using pcall / xpcall
Resolves the domain_name to actual list of IP addresses and corresponding port numbers using the DNS resolution protocol.
Parameters:
domain_name: string
service_name: string, name of the service like HTTP, HTTTP(s), SMTP, FTP etc...
Return:
address_array: An array of resolved host addresses where each member contains { hostaddress, portnum, addrfamily }
ERROR:
Any error is thrown using perror, can be caught using pcall / xpcall
Sends data in a chunked memory stream (an efio data structure) buffer completely on an open socket
Parameters:
ss: An open stream socket
cms: Handle to chunked memory stream (produced for example in mail message serialization)
ERROR:
Any error is thrown using perror, can be caught using pcall / xpcall
Sends data to peer on an accepted socket instance
Parameters:
ss: Handle to stream socket
buf: Data buffer acquired via platform.alloc_buffer
size: Integer, size of data to be sent
Return:
ret: Integer, size of data sent on the socket
ERROR:
Any error is thrown using perror, can be caught using pcall / xpcall
Sends data to peer on a previously opened socket
Parameters:
ss: Handle to stream socket
buf: Data buffer acquired via platform.alloc_buffer
size: Integer, size of data to be sent
Return:
ret: Integer, size of data sent on the socket
ERROR:
Any error is thrown using perror, can be caught using pcall / xpcall
Asynchronously sends request body of a HTTP request (created by new_request) over an established http session
Parameters:
http_client: handle to http session
request: handle to request object
ERROR:
Any error is thrown using perror, can be caught using pcall / xpcall
Asynchronously sends request header of a HTTP request (created by new_request) over an established http session
Parameters:
http_client: handle to http session
request: handle to request object
ERROR:
Any error is thrown using perror, can be caught using pcall / xpcall
Sets the _cl_state variable in the accepted socket associated with the lua thread to be true
Parameters:
None
Return:
None
ERROR:
Any error is thrown using perror, can be caught using pcall / xpcall
Used to set the upgraded status of accepted socket to WEBSOCKET
ERROR:
Any error is thrown using perror, can be caught using pcall / xpcall
Sets the lua file that has implemented an object with handle_message function as the associated message
handler with the WEBSOCKET
The handle_message function if implemented will get called upon arrival of a new WEBSOCKET message
Parameters:
msg_handler: message handler lua file name (complete path)
Return:
None
ERROR:
Any error is thrown using perror, can be caught using pcall / xpcall
Closes the given websocket
Parameters:
ss: handle to websocket
type: Integer value, one of
1 - Stop receiving messages on serve side (accepted) websocket
2 - Send shutdown message to peer, Not implemented as of now.
3 - Shut down opened websocket
Return:
None
ERROR:
Any error is thrown using perror, can be caught using pcall / xpcall
Establishes if the socket handle is still active
Parameters:
ss: Handle to socket connection
Return:
status: true if active, false if not active
ERROR:
Any error is thrown using perror, can be caught using pcall / xpcall
Upon invoking this function the server starts taking further requests from any client
Parameters:
None
Return:
None
ERROR:
Any error is thrown using perror, can be caught using pcall / xpcall
The evluaserver and evlua platforms ensure that any new connections made during the processing
of a request are kept track of and are closed at the end of request processing.
If this function is called for a connected stream socket, the stream socket is taken off the
list of tracked sockets, so that the connection can be used across multiple requests. Typically
such connections are held in a pool.
Paramters:
ss: Connected stream socket.
Return:
None
ERROR:
Any error is thrown using perror, can be caught using pcall / xpcall
Upgrades a connected stream socket to WEBSCOKET and adds it to the list of sockets tracked by the server
for incoming messages
Parameters:
ss: Connected stream socket
msg_handler: optional string, a lua file that implements a websocket message handler.
Return:
None
ERROR:
Any error is thrown using perror, can be caught using pcall / xpcall
Checks if the underlying socket fd of the websocket is active or not
Parameters:
ss: Handle to websocket (stream socket)
Return:
status: boolean, true if active, false otherwise
ERROR:
Any error is thrown using perror, can be caught using pcall / xpcall
Compresses the input data using zlib compression
Parameters:
input_data : string/userdata, the input data to be compressed
length : number, required in case input_data is userdata
Return:
out_data : userdata, compressed output
length : number, length of the compressed output
ERROR:
Any error is thrown using perror, can be caught using pcall / xpcall
Deompresses the input data using zlib inflate and returns text (string)
Parameters:
input_data : userdata, the input data to be uncompressed
length : number
Return:
out_data : string, uncompressed output
ERROR:
Any error is thrown using perror, can be caught using pcall / xpcall
Decompresses the input data using zlib inflate and returns binary (userdata)
Parameters:
input_data : userdata, the input data to be uncompressed
length : number
Return:
out_data : userdata, uncompressed output
length : number
ERROR:
Any error is thrown using perror, can be caught using pcall / xpcall