QP_add_*()

Synopsis

     #include <quintus/quintus.h>
     
     int QP_add_input(id,fn,data,flush_fn, flush_data)
     int  id;
     void (*fn)();
     char *data;
     void (*flush_fn)();
     char *flush_data;
     
     int QP_add_output(id,fn,data,flush_fn,flush_data)
     int  id;
     void (*fn)();
     char *data;
     void (*flush_fn)();
     char *flush_data;
     
     int QP_add_exception(id,fn,data,flush_fn,flush_data)
     int  id;
     void (*fn)();
     char *data;
     void (*flush_fn)();
     char *flush_data;
     
     int QP_add_timer(msecs,fn,data)
     int  msecs;
     void (*fn)();
     char *data;
     
     int QP_add_absolute_timer(timeo,fn,data)
     struct timeval *timeo;
     void (*fn)();
     char *data;
     

These C functions register callback functions to be called on input/output or timing events.

Description

QP_add_input() arranges for a function to be called when input becomes available on the file descriptor id. The callback function fn is called with two arguments: the file descriptor id and the specified call data data.

Before the function is called, the callback is disabled so that the function will not be inadvertently reentered while it is running. The callback will be enabled automatically after the callback function returns.

If the flush function flush_fn is not NULL then it is called whenever Prolog needs to wait for input. This is useful when you communicate with another process using bidirectional buffered connections, where you must flush the output before you wait for input, lest your process waits for a response to a message that is still buffered in your output queue.

QP_add_output() is like QP_add_input() except that the callback function is called if output is ready on file descriptor id. QP_add_exception() is like QP_add_input() except that the callback function is called if an exception condition occurs on file descriptor id.

QP_add_timer() arranges for a function to be called in msecs milliseconds time with two arguments: the actual time waited and the specified call data data. This timer does not repeat automatically; if you want a repeating timer, you should call QP_add_timer() within the callback function explicitly.

QP_add_absolute_timer() is like QP_add_timer() except that an absolute time is specified by the timeval structure timeo; see gettimeofday(2).

Return Values


timerid
Returned by QP_add_timer() and QP_add_absolute_time() if successful.
QP_SUCCESS
Returned by other functions.
QP_ERROR
Returned by all functions if an error occurs.

Tips

Often your code will maintain a buffer associated with an input connection. If this is the case, then your flush function must check for this buffered input, and as long as it finds some, it should repeatedly call your callback function directly. If you don't do this, then your callback function may not be called, even though you have pending input, since the operating system isn't aware of your buffer.

See Also

QP_wait_input(), QP_select(), QP_remove_*()