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/>.
23 #include "lib/util/tevent_unix.h"
27 struct tevent_context
*ev
;
28 struct messaging_context
*msg_ctx
;
30 struct timeval interval
;
34 static void source_waited(struct tevent_req
*subreq
);
36 static struct tevent_req
*source_send(TALLOC_CTX
*mem_ctx
,
37 struct tevent_context
*ev
,
38 struct messaging_context
*msg_ctx
,
40 struct timeval interval
,
43 struct tevent_req
*req
, *subreq
;
44 struct source_state
*state
;
46 req
= tevent_req_create(mem_ctx
, &state
, struct source_state
);
51 state
->msg_ctx
= msg_ctx
;
52 state
->msg_type
= msg_type
;
53 state
->interval
= interval
;
56 subreq
= tevent_wakeup_send(
58 timeval_current_ofs(state
->interval
.tv_sec
,
59 state
->interval
.tv_usec
));
60 if (tevent_req_nomem(subreq
, req
)) {
61 return tevent_req_post(req
, ev
);
63 tevent_req_set_callback(subreq
, source_waited
, req
);
67 static void source_waited(struct tevent_req
*subreq
)
69 struct tevent_req
*req
= tevent_req_callback_data(
70 subreq
, struct tevent_req
);
71 struct source_state
*state
= tevent_req_data(
72 req
, struct source_state
);
74 uint8_t buf
[200] = { };
76 ok
= tevent_wakeup_recv(subreq
);
79 tevent_req_error(req
, ENOMEM
);
83 messaging_send_buf(state
->msg_ctx
, state
->dst
, state
->msg_type
,
86 subreq
= tevent_wakeup_send(
88 timeval_current_ofs(state
->interval
.tv_sec
,
89 state
->interval
.tv_usec
));
90 if (tevent_req_nomem(subreq
, req
)) {
93 tevent_req_set_callback(subreq
, source_waited
, req
);
96 static int source_recv(struct tevent_req
*req
)
100 if (tevent_req_is_unix_error(req
, &err
)) {
106 int main(int argc
, const char *argv
[])
108 TALLOC_CTX
*frame
= talloc_stackframe();
109 struct tevent_context
*ev
;
110 struct messaging_context
*msg_ctx
;
111 struct tevent_req
*req
;
116 fprintf(stderr
, "Usage: %s <dst>\n", argv
[0]);
120 lp_load_global(get_dyn_CONFIGFILE());
122 ev
= tevent_context_init(frame
);
124 perror("tevent_context_init failed");
128 msg_ctx
= messaging_init(ev
, ev
);
129 if (msg_ctx
== NULL
) {
130 perror("messaging_init failed");
134 id
= server_id_from_string(get_my_vnn(), argv
[1]);
135 if (!procid_valid(&id
)) {
136 fprintf(stderr
, "pid %s invalid\n", argv
[1]);
140 req
= source_send(ev
, ev
, msg_ctx
, MSG_SMB_NOTIFY
,
141 timeval_set(0, 10000), id
);
143 perror("source_send failed");
147 if (!tevent_req_poll(req
, ev
)) {
148 perror("tevent_req_poll failed");
152 ret
= source_recv(req
);
154 printf("source_recv returned %d\n", ret
);