Next: , Previous: , Up: Coserver   [Contents][Index]

4.2 Writing coservers

4.2.1 Making and configuring preparations

First you have to change into the src/libserveez/coserver/ directory of the Serveez package. Then edit the and add your header and implementation file to the libcoserver_la_SOURCES variable.

4.2.2 Coserver header file

You have to declare the coserver handle routine here. This callback gets the input buffer argument and delivers the output buffer result. Both of these buffers are supposed to be lines separated by a ‘\n’.

4.2.3 Coserver implementation file

Here you need to #include "libserveez/coserver/coserver.h" and implement the coserver handle routine declared in the coserver header file. This can be any blocking system call. On successful completion you can return the result or NULL on errors. The input and output buffers are plain strings and can have any format with one exception. Because the coservers communicate via a line protocol with Serveez these buffers must not contain ‘\n’ (0x0d).

4.2.4 Make your coserver available in Serveez

For this you have to edit coserver.h and coserver.c files which are located in the src/libserveez/coserver/ directory. In the header file you have to define a further COSERVER_* id (macro) and set the MAX_COSERVER_TYPES define to the appropriate value. Then you should define a further svz_coserver_* macro in the same file.

In coserver.c you have to implement the svz_coserver_* macro. This macro takes three arguments. The first is always specific to your coserver and is used to create the actual request string. Then follows the result callback routine, and an optional argument for this callback. The latter two are simply passed to the svz_coserver_send_request routine. This routine takes four arguments where the first is the previously defined COSERVER_* id and the second is the input buffer for the coserver handle routine without the trailing ‘\n’.

Then you need to add your coserver to the svz_coservertypes array specifying the COSERVER_* id, the coserver description, the coserver handle routine discussed above, the number of coserver instances to be created and an optional initialization routine.

Next: Existing coservers, Previous: What are coservers, Up: Coserver   [Contents][Index]