~registry/scalestack/trunk

« back to all changes in this revision

Viewing changes to scalestack/network/local/stream/listener.cc

  • Committer: Eric Day
  • Date: 2010-12-04 17:17:34 UTC
  • mfrom: (56.1.9)
  • Revision ID: git-v1:9c392b034d652023a4b28ae2976aca128bb856c2
Merged Eric's branch with style updates, config file support, and other cleanup.

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
 
16
16
#include "config.h"
17
17
 
18
 
#include <cerrno>
19
 
#include <cstring>
20
 
#include <exception>
 
18
#include <netdb.h>
 
19
#include <sys/socket.h>
21
20
#include <sys/types.h>
22
 
#include <sys/socket.h>
23
 
#include <netdb.h>
24
21
#include <sys/un.h>
25
22
 
26
23
#include <scalestack/kernel/module.h>
27
24
#include <scalestack/kernel/option.h>
28
 
#include <scalestack/network/local/stream/connection_service.h>
29
25
#include <scalestack/network/local/stream/listener.h>
30
26
#include <scalestack/network/local/stream/listener_service.h>
31
27
 
44
40
 * Public methods.
45
41
 */
46
42
 
47
 
listener::listener(listener_service& creator,
48
 
                   connection_service& associated_connection_service,
 
43
listener::listener(listener_service& listener_service,
49
44
                   const std::string local_socket):
50
 
  network::listener(creator, associated_connection_service),
51
 
  network::local::common(),
 
45
  network::listener(listener_service),
52
46
  _local_socket(local_socket)
53
47
{
54
 
  struct addrinfo ai;
 
48
  struct addrinfo addrinfo;
55
49
  struct sockaddr_un sun;
56
50
 
57
51
  memset(&sun, 0, sizeof(sun));
59
53
  /* leave the NULL at end of sun_path always */
60
54
  strncpy(sun.sun_path, _local_socket.c_str(), sizeof(sun.sun_path) - 1);
61
55
 
62
 
  memset(&ai, 0, sizeof(ai));
63
 
  ai.ai_family = AF_UNIX;
64
 
  ai.ai_socktype = SOCK_STREAM;
65
 
  ai.ai_addr = reinterpret_cast<struct sockaddr*>(&sun);
66
 
  ai.ai_addrlen = sizeof(sun);
 
56
  memset(&addrinfo, 0, sizeof(addrinfo));
 
57
  addrinfo.ai_family = AF_UNIX;
 
58
  addrinfo.ai_socktype = SOCK_STREAM;
 
59
  addrinfo.ai_addr = reinterpret_cast<struct sockaddr*>(&sun);
 
60
  addrinfo.ai_addrlen = sizeof(sun);
67
61
 
68
62
  _module.log_info("Trying to listen on %s", _local_socket.c_str());
69
63
 
70
 
  listen(ai, _module.get_option("local_backlog").get_int_value());
 
64
  listen(addrinfo, _module.get_option("local_backlog").get_int_value());
71
65
 
72
66
  _module.log_notice("Listening on %s", _local_socket.c_str());
73
67