2 Unix SMB/CIFS implementation.
4 Copyright (C) Volker Lendecke 2012
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/>.
21 #include "torture/proto.h"
22 #include "lib/util/tevent_unix.h"
23 #include "msg_channel.h"
25 struct msg_test_state {
26 struct tevent_context *ev;
27 struct messaging_context *msg;
28 struct msg_channel *channel;
31 static void msg_test_got_channel(struct tevent_req *subreq);
32 static void msg_test_got_msg(struct tevent_req *subreq);
34 static struct tevent_req *msg_test_send(TALLOC_CTX *mem_ctx,
35 struct tevent_context *ev)
37 struct tevent_req *req, *subreq;
38 struct msg_test_state *state;
40 req = tevent_req_create(mem_ctx, &state, struct msg_test_state);
46 state->msg = messaging_init(state, state->ev);
47 if (tevent_req_nomem(state->msg, req)) {
48 return tevent_req_post(req, ev);
50 subreq = msg_channel_init_send(state, state->ev, state->msg, MSG_PING);
51 if (tevent_req_nomem(subreq, req)) {
52 return tevent_req_post(req, ev);
54 tevent_req_set_callback(subreq, msg_test_got_channel, req);
58 static void msg_test_got_channel(struct tevent_req *subreq)
60 struct tevent_req *req = tevent_req_callback_data(
61 subreq, struct tevent_req);
62 struct msg_test_state *state = tevent_req_data(
63 req, struct msg_test_state);
66 ret = msg_channel_init_recv(subreq, state, &state->channel);
68 if (tevent_req_error(req, ret)) {
71 subreq = msg_read_send(state, state->ev, state->channel);
72 if (tevent_req_nomem(subreq, req)) {
75 tevent_req_set_callback(subreq, msg_test_got_msg, req);
78 static void msg_test_got_msg(struct tevent_req *subreq)
80 struct tevent_req *req = tevent_req_callback_data(
81 subreq, struct tevent_req);
82 struct msg_test_state *state = tevent_req_data(
83 req, struct msg_test_state);
84 struct messaging_rec *msg;
87 ret = msg_read_recv(subreq, state, &msg);
89 if (tevent_req_error(req, ret)) {
95 static int msg_test_recv(struct tevent_req *req)
99 if (tevent_req_is_unix_error(req, &err)) {
105 bool run_msg_test(int dummy)
107 struct tevent_context *ev;
108 struct tevent_req *req;
111 ev = tevent_context_init(talloc_tos());
113 fprintf(stderr, "tevent_context_init failed\n");
116 req = msg_test_send(ev, ev);
118 fprintf(stderr, "msg_test_send failed\n");
121 if (!tevent_req_poll(req, ev)) {
122 fprintf(stderr, "tevent_req_poll failed\n");
125 ret = msg_test_recv(req);
127 printf("msg_test_recv returned %s\n",
128 ret ? strerror(ret) : "success");