"Fossies" - the Fresh Open Source Software Archive

Member "balance-3.57/balance.h" (28 Apr 2015, 3486 Bytes) of package /linux/privat/balance-3.57.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "balance.h" see the Fossies "Dox" file reference documentation.

    1 /*
    2  * balance.h
    3  */
    4 
    5 /*
    6  * $Id: balance.h,v 1.2 2011/02/10 13:52:47 t Exp $
    7  */
    8 
    9 #include <stdio.h>
   10 #include <strings.h>
   11 #include <ctype.h>
   12 #include <errno.h>
   13 #include <netdb.h>
   14 #include <signal.h>
   15 #include <stdlib.h>
   16 #include <sysexits.h>
   17 #include <syslog.h>
   18 #ifndef NO_MMAP
   19 #include <unistd.h>
   20 #include <sys/mman.h>
   21 #endif
   22 
   23 #ifdef __FreeBSD__
   24 #define BalanceBSD 1
   25 #endif 
   26 
   27 #ifdef bsdi
   28 #define BalanceBSD 1
   29 #endif
   30 
   31 #ifdef BSD
   32 #define BalanceBSD 1
   33 #endif
   34 
   35 #ifdef MAC_OS_X_VERSION_10_4 
   36 #define BalanceBSD 1
   37 #endif
   38 
   39 #ifdef BalanceBSD
   40 #include <sys/wait.h>
   41 #else
   42 #include <sys/resource.h>
   43 #endif
   44 
   45 #include <sys/socket.h>
   46 #include <sys/types.h>
   47 #include <sys/wait.h>
   48 #include <sys/stat.h>
   49 #include <fcntl.h>
   50 #include <unistd.h>
   51 #include <string.h>
   52 #include <sys/shm.h>
   53 
   54 #include <netinet/in.h>
   55 #include <arpa/inet.h>
   56 #include <netinet/tcp.h>    /* for TCP_NODELAY definition */
   57 
   58 /* solaris 9, solaris 10 do not have INADDR_NONE */
   59 #ifndef INADDR_NONE
   60 #define INADDR_NONE ((unsigned long) -1)
   61 #endif
   62 
   63 #define MAXTXSIZE   (32*1024)
   64 #define FILENAMELEN     1024
   65 /*
   66  * this should be a directory that isn't cleaned up periodically, or at
   67  * reboot of the machine (/tmp is cleaned at reboot on many OS versions)
   68  */
   69 #define SHMDIR      "/var/run/balance/"
   70 #define SHMFILESUFFIX   ".shm"
   71 
   72 #define MAXCHANNELS         64  /* max channels in group          */
   73 #define MAXGROUPS           32  /* max groups                     */
   74 #define MAXINPUTLINE        128 /* max line in input mode         */
   75 #define DEFAULTTIMEOUT      5   /* timeout for unreachable hosts  */
   76 #define DEFAULTSELTIMEOUT   0   /* timeout for select             */
   77 
   78 
   79 typedef struct {
   80   int status;
   81   int port;
   82   struct in_addr ipaddr;
   83   int c;            /* current # of connections           */
   84   int tc;           /* total # of connections             */
   85   int maxc;         /* max # of connections, 0 = no limit */
   86   unsigned long long bsent; /* bytes sent                         */
   87   unsigned long long breceived; /* bytes received                     */
   88 } CHANNEL;
   89 
   90 #define GROUP_RR    0   /* Round Robin            */
   91 #define GROUP_HASH  1   /* Hash on Client Address */
   92 
   93 typedef struct {
   94   int nchannels;        /* number of channels in group         */
   95   int current;          /* current channel in group            */
   96   int type;         /* either GROUP_RR or GROUP_HASH       */
   97   CHANNEL channels[MAXCHANNELS];
   98 } GROUP;
   99 
  100 typedef struct {
  101   int   release;
  102   int   subrelease;
  103   int   pid;
  104   GROUP groups[MAXGROUPS];
  105 } COMMON;
  106 
  107 /*
  108  * Macros to access various elements of struct GROUP and struct CHANNEL 
  109  * within COMMON array
  110  *
  111  * a       pointer to variable of type COMMON
  112  * g       group index
  113  * i       channel index
  114  */
  115 
  116 #define cmn_group(a,g)           ((a)->groups[(g)])
  117 #define grp_nchannels(a,g)   (cmn_group((a),(g)).nchannels)
  118 #define grp_current(a,g)         (cmn_group((a),(g)).current)
  119 #define grp_type(a,g)        (cmn_group((a),(g)).type)
  120 #define grp_channel(a,g,i)       (cmn_group((a),(g)).channels[(i)])
  121 #define chn_status(a,g,i)        (grp_channel((a),(g),(i)).status)
  122 #define chn_port(a,g,i)      (grp_channel((a),(g),(i)).port)
  123 #define chn_ipaddr(a,g,i)    (grp_channel((a),(g),(i)).ipaddr)
  124 #define chn_c(a,g,i)         (grp_channel((a),(g),(i)).c)
  125 #define chn_tc(a,g,i)        (grp_channel((a),(g),(i)).tc)
  126 #define chn_maxc(a,g,i)      (grp_channel((a),(g),(i)).maxc)
  127 #define chn_bsent(a,g,i)     (grp_channel((a),(g),(i)).bsent)
  128 #define chn_breceived(a,g,i)     (grp_channel((a),(g),(i)).breceived)
  129 
  130 /*
  131  * function prototypes
  132  */
  133 unsigned int hash_fold(char *, int);
  134 ssize_t writen(int, unsigned char *, size_t);