~markwright/scalestack/zeromq

« back to all changes in this revision

Viewing changes to scalestack/zeromq/echo/server/server.cc

  • Committer: Mark Wright
  • Date: 2011-03-20 13:23:26 UTC
  • Revision ID: markwright@internode.on.net-20110320132326-uoh8y0yitqctlxka
Initial sketch, incomplete and untested

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Scale Stack
 
3
 *
 
4
 * Copyright 2011 Mark Wright
 
5
 *
 
6
 * Licensed under the Apache License, Version 2.0 (the "License");
 
7
 * you may not use this file except in compliance with the License.
 
8
 * You may obtain a copy of the License at
 
9
 *
 
10
 *     http://www.apache.org/licenses/LICENSE-2.0
 
11
 *
 
12
 * Unless required by applicable law or agreed to in writing, software
 
13
 * distributed under the License is distributed on an "AS IS" BASIS,
 
14
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
15
 * See the License for the specific language governing permissions and
 
16
 * limitations under the License.
 
17
 */
 
18
 
 
19
/**
 
20
 * @file
 
21
 * @brief ZeroMQ Echo Server Module Definitions
 
22
 */
 
23
 
 
24
#include "config.h"
 
25
 
 
26
#include <scalestack/zeromq/connection_service.h>
 
27
#include <scalestack/zeromq/echo/server/socket_service.h>
 
28
#include <scalestack/zeromq/echo/server/socket_t.h>
 
29
 
 
30
using namespace std;
 
31
using namespace scalestack;
 
32
 
 
33
static void options(kernel::module& module)
 
34
{
 
35
  module.add_option("random_buffer_size", _("Size of random buffer to echo."),
 
36
                    "SIZE", "32768");
 
37
}
 
38
 
 
39
static void start(kernel::module& module)
 
40
{
 
41
  auto_ptr<zeromq::socket_service> socket_service(
 
42
    new zeromq::echo::server::socket_service(module));
 
43
  auto_ptr<zeromq::connection_service> connection_service(
 
44
    new zeromq::connection_service(module, socket_service));
 
45
 
 
46
  // the connection service handles both bind and/or connect. As zeromq
 
47
  // can do multiple binds and/or multiple connects on the same socket with
 
48
  // some zeromq socket types.
 
49
  // Hence is seems to be best to place the listener service / address stuff into the
 
50
  // the zeromq::connection_service, and not have a listener_service.
 
51
 
 
52
  connection_service->add_listeners();
 
53
  module.get_core().add_service("zeromq::echo::server", connection_service.get());
 
54
}
 
55
 
 
56
static void stop(kernel::module& module)
 
57
{
 
58
  delete module.get_core().remove_service("zeromq::echo::server");
 
59
}
 
60
 
 
61
SCALESTACK_KERNEL_MODULE(options, start, stop, NULL, NULL);