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
|
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
#include <stdio.h>
#include <proton/driver.h>
#include <qpid/dispatch/server.h>
#include <qpid/dispatch/container.h>
#include <qpid/dispatch/timer.h>
#include <qpid/dispatch/log.h>
#include <qpid/dispatch/router.h>
#include <signal.h>
#include <sys/types.h>
#include <unistd.h>
static int exit_with_sigint = 0;
static void thread_start_handler(void* context, int thread_id)
{
}
static void signal_handler(void* context, int signum)
{
dx_server_pause();
switch (signum) {
case SIGINT:
exit_with_sigint = 1;
case SIGQUIT:
case SIGTERM:
fflush(stdout);
dx_server_stop();
break;
case SIGHUP:
break;
default:
break;
}
dx_server_resume();
}
static void startup(void *context)
{
// TODO - Move this into a configuration framework
dx_server_pause();
static dx_server_config_t server_config;
server_config.host = "0.0.0.0";
server_config.port = "5672";
server_config.sasl_mechanisms = "ANONYMOUS";
server_config.ssl_enabled = 0;
dx_server_listen(&server_config, 0);
/*
static dx_server_config_t client_config;
client_config.host = "0.0.0.0";
client_config.port = "10000";
client_config.sasl_mechanisms = "ANONYMOUS";
client_config.ssl_enabled = 0;
dx_server_connect(&client_config, 0);
*/
dx_server_resume();
}
int main(int argc, char **argv)
{
dx_log_set_mask(LOG_INFO | LOG_TRACE | LOG_ERROR);
dx_server_initialize(4);
dx_container_initialize();
dx_server_set_signal_handler(signal_handler, 0);
dx_server_set_start_handler(thread_start_handler, 0);
dx_router_t *router = dx_router(0);
dx_timer_t *startup_timer = dx_timer(startup, 0);
dx_timer_schedule(startup_timer, 0);
dx_server_signal(SIGHUP);
dx_server_signal(SIGQUIT);
dx_server_signal(SIGTERM);
dx_server_signal(SIGINT);
dx_server_run();
dx_router_free(router);
dx_server_finalize();
if (exit_with_sigint) {
signal(SIGINT, SIG_DFL);
kill(getpid(), SIGINT);
}
return 0;
}
|