File: balance.h

package info (click to toggle)
balance 3.56-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 188 kB
  • ctags: 126
  • sloc: ansic: 1,619; makefile: 96
file content (134 lines) | stat: -rw-r--r-- 3,486 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/*
 * balance.h
 */

/*
 * $Id: balance.h,v 1.2 2011/02/10 13:52:47 t Exp $
 */

#include <stdio.h>
#include <strings.h>
#include <ctype.h>
#include <errno.h>
#include <netdb.h>
#include <signal.h>
#include <stdlib.h>
#include <sysexits.h>
#include <syslog.h>
#ifndef	NO_MMAP
#include <unistd.h>
#include <sys/mman.h>
#endif

#ifdef __FreeBSD__
#define BalanceBSD 1
#endif 

#ifdef bsdi
#define BalanceBSD 1
#endif

#ifdef BSD
#define BalanceBSD 1
#endif

#ifdef MAC_OS_X_VERSION_10_4 
#define BalanceBSD 1
#endif

#ifdef BalanceBSD
#include <sys/wait.h>
#else
#include <sys/resource.h>
#endif

#include <sys/socket.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>
#include <sys/shm.h>

#include <netinet/in.h>
#include <arpa/inet.h>
#include <netinet/tcp.h>	/* for TCP_NODELAY definition */

/* solaris 9, solaris 10 do not have INADDR_NONE */
#ifndef INADDR_NONE
#define INADDR_NONE ((unsigned long) -1)
#endif

#define MAXTXSIZE 	(32*1024)
#define FILENAMELEN 	1024
/*
 * this should be a directory that isn't cleaned up periodically, or at
 * reboot of the machine (/tmp is cleaned at reboot on many OS versions)
 */
#define SHMDIR 		"/var/run/balance/"
#define	SHMFILESUFFIX	".shm"

#define MAXCHANNELS 		64	/* max channels in group          */
#define MAXGROUPS   		32	/* max groups                     */
#define MAXINPUTLINE 		128	/* max line in input mode         */
#define DEFAULTTIMEOUT  	5	/* timeout for unreachable hosts  */
#define DEFAULTSELTIMEOUT  	0 	/* timeout for select             */


typedef struct {
  int status;
  int port;
  struct in_addr ipaddr;
  int c;			/* current # of connections           */
  int tc;			/* total # of connections             */
  int maxc;			/* max # of connections, 0 = no limit */
  unsigned long long bsent;	/* bytes sent                         */
  unsigned long long breceived;	/* bytes received                     */
} CHANNEL;

#define GROUP_RR	0	/* Round Robin            */
#define GROUP_HASH	1	/* Hash on Client Address */

typedef struct {
  int nchannels;		/* number of channels in group         */
  int current;			/* current channel in group            */
  int type;			/* either GROUP_RR or GROUP_HASH       */
  CHANNEL channels[MAXCHANNELS];
} GROUP;

typedef struct {
  int   release;
  int   subrelease;
  int   pid;
  GROUP groups[MAXGROUPS];
} COMMON;

/*
 * Macros to access various elements of struct GROUP and struct CHANNEL 
 * within COMMON array
 *
 * a       pointer to variable of type COMMON
 * g       group index
 * i       channel index
 */

#define cmn_group(a,g)       	 ((a)->groups[(g)])
#define grp_nchannels(a,g) 	 (cmn_group((a),(g)).nchannels)
#define grp_current(a,g)    	 (cmn_group((a),(g)).current)
#define grp_type(a,g)  	 	 (cmn_group((a),(g)).type)
#define grp_channel(a,g,i)  	 (cmn_group((a),(g)).channels[(i)])
#define chn_status(a,g,i)   	 (grp_channel((a),(g),(i)).status)
#define chn_port(a,g,i)		 (grp_channel((a),(g),(i)).port)
#define chn_ipaddr(a,g,i)	 (grp_channel((a),(g),(i)).ipaddr)
#define chn_c(a,g,i)		 (grp_channel((a),(g),(i)).c)
#define chn_tc(a,g,i)		 (grp_channel((a),(g),(i)).tc)
#define chn_maxc(a,g,i)		 (grp_channel((a),(g),(i)).maxc)
#define chn_bsent(a,g,i)	 (grp_channel((a),(g),(i)).bsent)
#define chn_breceived(a,g,i)	 (grp_channel((a),(g),(i)).breceived)

/*
 * function prototypes
 */
unsigned int hash_fold(char *, int);
ssize_t writen(int, unsigned char *, size_t);