~registry/scalestack/trunk

« back to all changes in this revision

Viewing changes to scalestack/network/local/stream/connection_service.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:
36
36
 * Public methods.
37
37
 */
38
38
 
39
 
connection_service::connection_service(kernel::module& creator):
40
 
  stream_service(creator)
 
39
connection_service::connection_service(kernel::module& module,
 
40
                                       stream_service& stream_service):
 
41
  event::handler_service(module),
 
42
  _stream_service(stream_service)
41
43
{
42
44
}
43
45
 
44
46
connection_service::~connection_service()
45
47
{
 
48
  shutdown();
46
49
}
47
50
 
48
51
network::stream* connection_service::add_accepted(int file_descriptor,
73
76
 * Private methods.
74
77
 */
75
78
 
76
 
network::stream* connection_service::_add_connection(connection** connection_ret)
 
79
network::stream* connection_service::_add_connection(connection** connection)
77
80
{
78
 
  network::stream* new_stream = NULL;
79
 
  connection* new_connection = NULL;
 
81
  network::stream* stream = NULL;
 
82
  *connection = NULL;
80
83
 
81
84
  try
82
85
  {
83
 
    new_stream = add_stream();
84
 
    new_connection = new connection(*this);
85
 
    new_connection->set_stream(new_stream);
86
 
    add_handler(new_connection);
 
86
    stream = _stream_service.add_stream();
 
87
    *connection = new stream::connection(*this);
 
88
    (*connection)->set_stream(stream);
 
89
    add_handler(*connection);
87
90
  }
88
 
  catch (exception& e)
 
91
  catch (exception&)
89
92
  {
90
 
    if (new_connection != NULL)
91
 
      remove_stream(new_stream);
 
93
    if (*connection != NULL)
 
94
      _stream_service.remove_stream(stream);
92
95
 
93
96
    throw;
94
97
  }
95
98
 
96
 
  *connection_ret = new_connection;
97
 
 
98
 
  return new_stream;
 
99
  return stream;
99
100
}
100
101
 
101
102
void connection_service::remove_handler(event::handler* handler)
102
103
{
103
 
  remove_stream(reinterpret_cast<connection*>(handler)->get_stream());
 
104
  _stream_service.remove_stream(static_cast<connection*>(handler)->get_stream());
104
105
  delete handler;
105
106
}
106
107