125 lines
3.2 KiB
C
125 lines
3.2 KiB
C
/*
|
|
************************************************************************
|
|
**
|
|
** Copyright (c) 2008..2012 by
|
|
** Core|Vision B.V.
|
|
** Cereslaan 10b
|
|
** 5384 VT Heesch
|
|
** The Netherlands
|
|
**
|
|
** All Rights Reserved
|
|
**
|
|
************************************************************************
|
|
*/
|
|
/*
|
|
************************************************************************
|
|
**
|
|
** Project name: Dual Inventive: Zelfsignalerende Kortsluit Lans
|
|
** Filename: tcpserver.h
|
|
** Author: Jack Weeland
|
|
** Date: September 2, 2008
|
|
** File version: $Revision: 1.55 $
|
|
** $Date: 2013/04/15 15:31:46 $
|
|
**
|
|
************************************************************************
|
|
*/
|
|
/*
|
|
************************************************************************
|
|
**
|
|
** TCP server; communication with the ZKL3000
|
|
** Local header file
|
|
**
|
|
************************************************************************
|
|
*/
|
|
|
|
#ifndef _TCPSERVER_H
|
|
#define _TCPSERVER_H
|
|
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <stdio.h>
|
|
#include <errno.h>
|
|
#include <limits.h>
|
|
#include <netdb.h>
|
|
#include <unistd.h>
|
|
#include <time.h>
|
|
#include <sys/types.h>
|
|
#include <sys/select.h>
|
|
#include <sys/wait.h>
|
|
#include <fcntl.h>
|
|
#include <signal.h>
|
|
|
|
#include <cp3000-cmd.h>
|
|
#include <cp3000-errno.h>
|
|
|
|
#include <di-util/cp3000.h>
|
|
#include <di-util/cp3000-shmem.h>
|
|
#include <di-util/cp3000-sem.h>
|
|
#include <di-util/database.h>
|
|
|
|
/*
|
|
** Error and status bits (currently only used to give a reason for a disconnect)
|
|
*/
|
|
#define TCP_NO_ERROR 0 // success; never a reason for a disconnect
|
|
#define TCP_ERROR 1 // generic
|
|
#define TCP_DISCONNECTED 2 // client disconnected
|
|
#define TCP_TIMEOUT 3 // time-out on the client connection
|
|
#define TCP_ABORTED 4 // connection aborted by $ABORT command
|
|
#define TCP_KILLED 5 // process killed
|
|
|
|
/*
|
|
** Client authorization
|
|
*/
|
|
#define AUTH_ALL 0
|
|
#define AUTH_MTINFO 1
|
|
#define AUTH_SECURE 2
|
|
#define AUTH_DEBUG 3
|
|
|
|
/*
|
|
** Definitions
|
|
*/
|
|
|
|
// Database identifier for a device, device type and server
|
|
typedef int zkl_t;
|
|
typedef int device_t;
|
|
typedef int client_t;
|
|
typedef int server_t;
|
|
|
|
/*
|
|
** Implemented in 'tcpserver.c'
|
|
*/
|
|
|
|
// debug mode
|
|
extern int debug;
|
|
|
|
// internal/lan address or hostname; useful when a load balancer is deployed
|
|
// on the external network
|
|
// default value is NULL when not set
|
|
extern const char *tcp_internal_addr;
|
|
|
|
// timing parameters
|
|
extern int t_device_timeout, t_client_timeout;
|
|
extern int t_watchdog, t_heartbeat;
|
|
extern int t_secure_expiry;
|
|
|
|
// configurable options
|
|
extern int log_retries;
|
|
|
|
// server signature and database identifier (cached from config)
|
|
extern const char *server_signature;
|
|
extern server_t server_id;
|
|
|
|
// get disconnect reason (TCP_NO_ERROR is not a valid reason)
|
|
// implemented in "database-if.c" due to its close relationship to the
|
|
// database table 'log_tcp'
|
|
const char *db_disconnect_reason(int reason);
|
|
|
|
// create IPC fifo, shared memory, semaphore
|
|
cp3000_device_t tcp_create_fifo(cp3000_device_t device, int status_updates);
|
|
cp3000_shmem_t tcp_create_shmem(cp3000_device_t device);
|
|
cp3000_sem_t tcp_create_sem(cp3000_device_t device);
|
|
// connect to the IPC fifo (client side)
|
|
cp3000_device_t tcp_connect_fifo(cp3000_device_t device, int status_updates);
|
|
|
|
#endif /* _TCPSERVER_H */
|