2 * Unix SMB/CIFS implementation.
3 * Send messages once a second
4 * Copyright (C) Volker Lendecke 2014
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
22 #include "lib/util/server_id.h"
24 #include "lib/util/tevent_unix.h"
28 struct tevent_context
*ev
;
29 struct messaging_context
*msg_ctx
;
31 struct timeval interval
;
35 static void source_waited(struct tevent_req
*subreq
);
37 static struct tevent_req
*source_send(TALLOC_CTX
*mem_ctx
,
38 struct tevent_context
*ev
,
39 struct messaging_context
*msg_ctx
,
41 struct timeval interval
,
44 struct tevent_req
*req
, *subreq
;
45 struct source_state
*state
;
47 req
= tevent_req_create(mem_ctx
, &state
, struct source_state
);
52 state
->msg_ctx
= msg_ctx
;
53 state
->msg_type
= msg_type
;
54 state
->interval
= interval
;
57 subreq
= tevent_wakeup_send(
59 timeval_current_ofs(state
->interval
.tv_sec
,
60 state
->interval
.tv_usec
));
61 if (tevent_req_nomem(subreq
, req
)) {
62 return tevent_req_post(req
, ev
);
64 tevent_req_set_callback(subreq
, source_waited
, req
);
68 static void source_waited(struct tevent_req
*subreq
)
70 struct tevent_req
*req
= tevent_req_callback_data(
71 subreq
, struct tevent_req
);
72 struct source_state
*state
= tevent_req_data(
73 req
, struct source_state
);
75 uint8_t buf
[200] = { };
77 ok
= tevent_wakeup_recv(subreq
);
80 tevent_req_error(req
, ENOMEM
);
84 messaging_send_buf(state
->msg_ctx
, state
->dst
, state
->msg_type
,
87 subreq
= tevent_wakeup_send(
89 timeval_current_ofs(state
->interval
.tv_sec
,
90 state
->interval
.tv_usec
));
91 if (tevent_req_nomem(subreq
, req
)) {
94 tevent_req_set_callback(subreq
, source_waited
, req
);
97 static int source_recv(struct tevent_req
*req
)
101 if (tevent_req_is_unix_error(req
, &err
)) {
107 int main(int argc
, const char *argv
[])
109 TALLOC_CTX
*frame
= talloc_stackframe();
110 struct tevent_context
*ev
;
111 struct messaging_context
*msg_ctx
;
112 struct tevent_req
*req
;
114 struct server_id my_id
, id
;
117 fprintf(stderr
, "Usage: %s <dst>\n", argv
[0]);
121 lp_load_global(get_dyn_CONFIGFILE());
123 ev
= tevent_context_init(frame
);
125 perror("tevent_context_init failed");
129 msg_ctx
= messaging_init(ev
, ev
);
130 if (msg_ctx
== NULL
) {
131 perror("messaging_init failed");
134 my_id
= messaging_server_id(msg_ctx
);
136 id
= server_id_from_string(my_id
.vnn
, argv
[1]);
137 if (!procid_valid(&id
)) {
138 fprintf(stderr
, "pid %s invalid\n", argv
[1]);
142 req
= source_send(ev
, ev
, msg_ctx
, MSG_SMB_NOTIFY
,
143 timeval_set(0, 10000), id
);
145 perror("source_send failed");
149 if (!tevent_req_poll(req
, ev
)) {
150 perror("tevent_req_poll failed");
154 ret
= source_recv(req
);
156 printf("source_recv returned %d\n", ret
);