server.h 2.02 KB
#ifndef __SERVER_H__
#define __SERVER_H__

#include <stdio.h>      /* for printf() and fprintf() */
#include <sys/select.h> /* for select system call and related */

#include "client.h"

/*
 * tClient does not belong here....it's an unneccessary external
 * dependency.
 * Except that the server should implement methods to read and
 * write to sockets and give the possibility to define
 * a dataAvailable(Callback|Hook) when data comes available.
 * additinally an acceptHook. Data will be written as soon as
 * the is date within the writebuffer of the connection and the
 * connection becomes ready for writing...
 * No threaded handling neccessary for writes!!! As soon as there
 * is data to write the server puts the handle into wfds and
 * whenever the socket it ready for writing data will be written.
 * This happens as long as there remains data in the writebuffer.
 * After that the handle will no longer be written to wfds or
 * it will be closed at all if we define that on request should
 * have only one answer...maybe we have to create a hook again
 * to give the client the possibility to trigger a connection end.
 *
 * One NOTE: If we want to use preforked workers in future we have
 * to ffigure out how to handle an open filehandle from one process
 * to another. To make the worker exchangeable at runtime it needs
 * to be a shared object or such...
 * And we need to be careful to define a sane ABI.
 * !!! Maybe this stuff should then be called connection worker. !!!
 */
typedef struct {
    int            servSock;
    tClient        clients[FD_SETSIZE];
    unsigned int   maxFd;
    fd_set         socks;
    char           logPath[512];
    char           namePat[512];
    FILE         * wHandle;
} tVirtualItemServer;


void serverClose(tVirtualItemServer *);
void serverShutdown(tVirtualItemServer *);
void serverInit(
        tVirtualItemServer *,
        unsigned int,
        unsigned int,
        const char *,
        const char *);
void serverRun(tVirtualItemServer *);
void logRotate(tVirtualItemServer *);

#endif // __SERVER_H__