File: init.cc

package info (click to toggle)
crossroads 2.65-1
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 2,664 kB
  • ctags: 355
  • sloc: cpp: 4,212; perl: 1,658; xml: 269; makefile: 186; sh: 46
file content (33 lines) | stat: -rw-r--r-- 978 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
#include "balancer"

void Balancer::init() {
    // Set the listening socket.
    if (config.stype() != Servertype::t_udp) {
	if (config.sport())
	    server_fd = serversocket(config.sipaddr(), config.sport(),
				     "balancer", Servertype::t_tcp);
	else
	    server_fd = 0;
    } else {
	server_fd = serversocket(config.sipaddr(), config.sport(),
				 "balancer", Servertype::t_udp);
    }
    
    // Start the web interface if requested.
    if (config.usewebinterface() && !config.foregroundmode()) {
	webinterface = new Webinterface();
	if (! webinterface)
	    throw Error("Memory fault in Balancer::init");
	webinterface->start();
    }

    // Add workable back ends, display initial states.
    for (int i = 0; i < config.backends(); i++)
	addbackend (config.backend(i));

    if (config.verbose()) {
	for (unsigned i = 0; i < nbackends(); i++)
	    _msg ("Initial backend state: " + backend(i).description() +
		  " is " + backend(i).availablestr() + "\n");
    }
}