Skip to main content

3.5 Interface Routines

In a modular, multi-process system such as the UCL facsimile system, the structure of the interface routines is very important. The CSI of section 3.3 is fundamental to the modular interface; a common control structure is also essential. This section gives some details both about the sharable control structure and the buffer management.

3.5.1 Sharable Control Structure​

Though the CSI specification is straightforward, the implementation of the inter-process communication interface may be rather tedious, especially in our system, where there are many task processes to be written. Not only does each process have to implement the same control structure for signal handling, but also the buffer management routines must be included in all the processes.

For the sake of simplicity and efficiency, a package of standard interface routines is provided which are shared by the task processes in the system. These routines are re-entrant, so that they can be shared by all processes.

The 'csinit' primitive is called for a task process to check in. An information table is allocated and the pointer to the table is returned to the caller as the task identifier, which is to be used for each call of these interface routines.

Then, each task process waits by invoking the 'csopen' primitive which does not return until the calling process is scheduled. When the connection between the process and the fitter is established, the call returns the pointer to the open parameter string of the task, the corresponding task being started. A typical structure of the task process (written in c) is shown below. After the task program is executed, the process calls the 'csopen' and waits again. It can be seen that the portability of the task routines is improved to a great extent. Only the interface routines should be changed if the system were to run in a different operating environment.

static int mytid;       /* task identifier */

task()
{
char *op; /* open parameter */

mytid = csinit();
for(;;) {
op = csopen(mytid);
... /* the body of the task */
}
}

3.5.2 Buffer Management​

The package of the interface routines also provides a universal buffer management, so that the task processes are freed from this burden. The allocation of the data buffers is the responsibility of the higher level process, the fitter. If the task processes allocated their own buffers, some redundant copying would have to be done. Thus, the primitives for data transfer, 'csread' and 'cswrite', are designed as:

char *csread(tid, need);
char *cswrite(tid, need);

where 'tid' is the identifier of the task and 'need' is the number of data bytes to be transferred. The primitives return the pointer to the area satisfying the caller's requirement. The 'csread' returns an area containing the data required by the caller. The 'cswrite' returns an area into which the caller can copy the data to be transferred. The copied data will be written to its destination at a proper time without the caller's interference. Obviously the unnecessary copy operations can be avoided. It is recommended that the data buffer returned by the primitives be used directly to attain higher performance.

In order to implement this strategy, each time a piece of data is required, the size of the buffer needed is compared with that of the unused buffer area in the current CSB. If the latter is not less than the former, the current buffer pointer is returned. Otherwise, a temporary buffer has to be employed. The data is copied into the buffer until the requested size is reached. In this case, instead of a part of the current buffer, the temporary buffer will be returned.

A 'cswrite' call with the 'need' field set to zero tells the interface routine that no more data will be sent. It causes a 'close' CSB to be sent to the destination routine.

If there is not enough data available, 'csread' returns zero to indicate the end of data.