uniserver(1)December 2019uniserver(1)

Index
 

NAME

uniserver - execute aime programs on client connections  

SYNOPSIS

uniserver [OPTIONS] PATH|PORT PROGRAM [TYPE NAME VALUE]...  

DESCRIPTION

uniserver establishes a local TCP (UNIX) or a TCP/IP (INET) server and executes the PROGRAM program on each client connection. The local TCP server is receiving connection requests on PATH while the TCP/IP server is running on port PORT. The TYPE NAME VALUE definitions introduce program accessible constants.

uniserver executes programs written in aime, a C like programming language.

The connection to the client is available for the programs as one read file (incoming, also aliased as is) and one write file (outgoing, also aliased as os).  

OPTIONS

-C, --client-allocation BYTES
Allow no more than BYTES for one client. The memory allocation limit refers to the data allocated for and by the program execution. The default is 4 megabytes.
-D, --database PATH
Use PATH for database. Default is unidetail. A zero length PATH has the database not available.
-K, --database-cache MEGABYTES
Limit database cache to MEGABYTES. Default is 32. Large transactions will see the limit exceeded.
-R, --client-run COUNT
Run COUNT client instructions before switching to another task. The execution of the aime program on client connections is carried out together with other activities, and each client gets to execute up to COUNT aime program instruction every time is on turn. Applies similarly for the control program, if any. The default is 64.
-c
Execute the PROGRAM program instead the program read from the PROGRAM file.
-d
Execute the CONTROL program instead the program read from the CONTROL file.
-i, --inet
Establish an INET server.
-l, --control CONTROL
Run the CONTROL program server side. See THE CONTROL PROGRAM for more information.
-u, --unix
Establish an UNIX server (default).
--data
List defined constants and exit.
--hold
Defer taking client connections until the CONTROL program agrees (and calls commence). No effect for no CONTROL program.
--list
List available functions and exit.
--help
Print a usage message and exit.
--version
Print version information on standard output then exit.
 

SERVER SPECIFIC FUNCTIONS

void cancel(course c);
terminates c if c is a program execution course
void commence(void);
starts accepting connections (if accepting has been deferred)
course course(void);
is the calling program execution course
void exit(integer e);
terminates program execution, current execution course if there are others. Called from a (sub)program executed through function link, it terminates the calling (sub)program.
integer link(text p);
is the exit code of p program execution
void lower(void);
decrements the exclusive execution flag (if not zero already)
void o_flush(void);
flushes standard output
void raise(void);
increments the exclusive execution flag
file refit(file f);
is f, replaces the f file data transfer methods for interruptible operation
void rend(object f, ...);
arranges for a concurrent call of function f with the remaining arguments
course render(object f, ...);
is the concurrent program execution course detaching the call of function f with the remaining arguments (same as rend except for the result)
void resume(course c);
awakens c if c is a sleeping program execution course
void sleep(integer s);
arranges for a s seconds sleep if s is greater than 0, does nothing otherwise
void suspend(void);
puts the calling program execution course to sleep. Terminates program execution if there are no remaining unsuspended execution courses.
integer state(course c);
is the c state: 0 for running, 1 for sleeping, 2 for reading, -1 for the rest (not a course, completed, etc)
void usleep(integer u);
arranges for a u microseconds sleep if u is greater than 0, does nothing otherwise
void v_flush(void);
flushes standard error

The concurrent execution concerned functions (cancel, course, rend, render, resume, state) are available to procedural programs only.

The commence function is available to control programs only.  

SERVER DEFINED DATA

The client connection files (is, incoming, os, outgoing) are all uniserver defined. Other definitions include:
record context;
an associative array, of no initial content

All definitions are constant, i.e. the "variables" are read only. The objects indicated are themselves not constants. They belong to a single program execution (i.e. they are not shared between connections).  

PROGRAM EXECUTION

The aime program is executed on each client connection, until it completes or fails or the connection closes. The client connection is closed upon program termination, immediately for program failure and as soon as data written to client is sent for program successful completion.

Output buffers are purged for program failure, with data not yet sent to client being dumped.

Connection closing is only detected when reading the connection. Programs are not stopped for lack of activity. Both conditions may be fixed in future versions.  

INTERRUPTIBLE FILES

The input client connection (is, incoming) functions as if blocking when reading, yet it is opened in a server wise non blocking mode. The read functions that work properly on it suspend program execution while client input is not available and resume it when data has been read. They include f_peek, f_pick, f_yank and f_b_read (the latter always reading at least one byte). Other read functions may fail or lose client input.

No flushing is required for the output client connection (os, outgoing), as it is not buffered. Data is nonetheless buffered by non file layers, and may not leave for the client until later.

f_close called on connection files puts them in the unopened state, but it does not close the connection.

Other blocking files may be put in the interruptable mode via refit, so that reading suspends program execution and the writing is deferred for later, just like for client connection.

Non reading functions working on refitted files include accept.  

GLOBAL NAMESPACE

One associative table of the aime type record may be accessed as context. The table is private for the client connection.  

DATABASE ACCESS

If support is compiled in, nonblonde databases may be accessed via the aimedb functions. One database is opened by uniserver and it is available as global db (of the aimedb type database).  

SERVER GRAB

Programs are executed in an exclusive mode when they raise their exclusive execution flag. The flag is a counter starting from 0 and to allow other programs execution it has to be lowered back to 0. Client connection reading and sleeping resets the flag and breaks the exclusive execution (0s sleeping included). So do the cancel (called for the running course) and suspend functions. No client output occurs while the flag is raised.  

SUBPROGRAM EXECUTION

(Sub)programs may be executed through function link. Procedural programs may execute procedural programs, non procedural programs may execute non procedural programs. Untrapped errors in executed programs propagate to and may be trapped by the executing programs.

The executed programs inherit the global variables access from the executing programs.  

CONCURRENT EXECUTION

Functions may be executed concurrently via rend and render. The functions create a new program execution course that picks up the function call.

The concurrent execution courses are not completely unlike threads, in that they share the client connection, memory space and the memory allocator. They access the same set of objects via the global variables.

Error is any execution course terminate program execution.

The aime type for the concurrent execution courses is course.

The sleep, usleep functions interrupt execution even for 0 arguments, and see concurrent, ready courses resumed.  

CONCURRENT PROGRAM EXECUTION CONSIDERATIONS

uniserver can execute any number of programs / serve any number of clients simultaneously, though not if the executed programs block.

The sleep, usleep functions and the communication on client connection do not block. Reading and writing non regular, not refitted files may block.  

THE CONTROL PROGRAM

In a similar fashion to executing a program on every client connection, a program (the control program) may be executed server side and unbound to any incoming connection.

The program (if one is indicated) is started when the server is established.

The uniserver specific link function is not defined for the control program.

The command line introduced TYPE NAME VALUE constants are defined for the control program.

Except for the connection specific objects, the server defined constants (db for compiled database support) are also defined.  

OUTPUT SCHEDULING AND MEMORY MANAGEMENT

uniserver prioritizes I/O over program execution. While there's data to be transmitted and the connection allows transmission, the execution is stayed.

Programs generating large amounts of output data will need to consider their memory allocation limit (the -C one), as the out transmission buffers are included in their memory accounting.

The memory allocation limit may be exceeded, but only for a set amount (1Mb) and while there's data to be transmitted.

When the limit is exceeded (and there's data going out), the program execution is suspended until the connection allows sufficient transmission for output buffers to be freed and the total allocation to come below the limit.  

EXAMPLES

A time of day server program:
date d;

d_now(d);
f_form(os, "/f2/:/f2/:/f2/", d_d_hour(d), d_h_minute(d),
       d_m_second(d));

A postfix expression evaluation server program:

data a, b;
integer o, v;

while (1) {
    v = a.place('\n');
    if (v ^ -1) {
        file f;
        list z;
        text s;

        f.b_affix(a);
        while (-1 < (v = f.word(s))) {
            if (v == 1 && (o = place("+-*/", s[0])) ^ -1) {
                real x, y;

                y = lb_pick(z);
                x = lb_pick(z);
                if (!o) {
                    x += y;
                } elif (o == 1) {
                    x -= y;
                } elif (o == 2) {
                    x *= y;
                } else {
                    x /= y;
                }
                z.append(x);
            } else {
                z.append(atof(s));
            }
        }

        f_(os, z[0], "\n");
        a.erase(0, f.tell - 1);
    } else {
        is.b_read(b, 256);
        a.add(b);
    }
}

The server replies to transmissions like:

128 64 32 16 + + + 256 1 - 15 / *\n

with results like:

4080\n
 

SEE ALSO

aime(1), uniclient(1)  

AUTHORS

Ciprian Niculescu
 

Index

NAME
SYNOPSIS
DESCRIPTION
OPTIONS
SERVER SPECIFIC FUNCTIONS
SERVER DEFINED DATA
PROGRAM EXECUTION
INTERRUPTIBLE FILES
GLOBAL NAMESPACE
DATABASE ACCESS
SERVER GRAB
SUBPROGRAM EXECUTION
CONCURRENT EXECUTION
CONCURRENT PROGRAM EXECUTION CONSIDERATIONS
THE CONTROL PROGRAM
OUTPUT SCHEDULING AND MEMORY MANAGEMENT
EXAMPLES
SEE ALSO
AUTHORS

This document was created by man2html using the manual pages.
Time: 15:00:33 GMT, April 19, 2020