2 Unix SMB/CIFS implementation.
4 Copyright (C) Stefan Metzmacher 2009
6 ** NOTE! The following LGPL license applies to the tevent
7 ** library. This does NOT imply that all of Samba is released
10 This library is free software; you can redistribute it and/or
11 modify it under the terms of the GNU Lesser General Public
12 License as published by the Free Software Foundation; either
13 version 3 of the License, or (at your option) any later version.
15 This library is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 Lesser General Public License for more details.
20 You should have received a copy of the GNU Lesser General Public
21 License along with this library; if not, see <http://www.gnu.org/licenses/>.
25 #include "system/network.h"
27 #include "tsocket_internal.h"
29 struct tsocket_connect_state {
30 /* this structs are owned by the caller */
32 struct tsocket_context *sock;
33 const struct tsocket_address *dst;
37 static void tsocket_connect_handler(struct tsocket_context *sock,
40 struct tevent_req *tsocket_connect_send(struct tsocket_context *sock,
42 const struct tsocket_address *dst)
44 struct tevent_req *req;
45 struct tsocket_connect_state *state;
51 req = tevent_req_create(mem_ctx, &state,
52 struct tsocket_connect_state);
57 state->caller.sock = sock;
58 state->caller.dst = dst;
60 ret = tsocket_connect(state->caller.sock,
62 err = tsocket_error_from_errno(ret, errno, &retry);
67 if (tevent_req_error(req, err)) {
75 ret = tsocket_set_readable_handler(state->caller.sock,
76 tsocket_connect_handler,
78 err = tsocket_error_from_errno(ret, errno, &dummy);
79 if (tevent_req_error(req, err)) {
86 return tevent_req_post(req, sock->event.ctx);
89 static void tsocket_connect_handler(struct tsocket_context *sock,
92 struct tevent_req *req = talloc_get_type(private_data,
94 struct tsocket_connect_state *state = tevent_req_data(req,
95 struct tsocket_connect_state);
100 ret = tsocket_get_status(state->caller.sock);
101 err = tsocket_error_from_errno(ret, errno, &retry);
106 if (tevent_req_error(req, err)) {
110 tevent_req_done(req);
113 int tsocket_connect_recv(struct tevent_req *req, int *perrno)
117 ret = tsocket_simple_int_recv(req, perrno);
119 tevent_req_received(req);