2 Unix SMB/CIFS implementation.
4 implements a non-blocking connect operation that is aware of the samba4 events
7 Copyright (C) Andrew Tridgell 2005
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 #include "lib/socket/socket.h"
26 #include "lib/events/events.h"
30 handle write events on connect completion
32 static void socket_connect_handler(struct event_context *ev, struct fd_event *fde,
33 uint16_t flags, void *private)
35 NTSTATUS *status = (NTSTATUS *)private;
36 *status = NT_STATUS_OK;
41 just like socket_connect() but other events can happen while the
42 connect is ongoing. This isn't as good as making the calling code
43 fully async during its connect phase, but at least it means that any
44 calling code that uses this won't interfere with code that is
47 NTSTATUS socket_connect_ev(struct socket_context *sock,
48 const char *my_address, int my_port,
49 const char *server_address, int server_port,
50 uint32_t flags, struct event_context *ev)
52 TALLOC_CTX *tmp_ctx = talloc_new(sock);
55 set_blocking(socket_get_fd(sock), False);
57 status = socket_connect(sock, my_address, my_port,
58 server_address, server_port, flags);
59 if (NT_STATUS_IS_ERR(status) &&
60 !NT_STATUS_EQUAL(status, NT_STATUS_MORE_PROCESSING_REQUIRED)) {
64 event_add_fd(ev, tmp_ctx, socket_get_fd(sock), EVENT_FD_WRITE,
65 socket_connect_handler, &status);
67 while (NT_STATUS_EQUAL(status, STATUS_MORE_ENTRIES)) {
68 if (event_loop_once(ev) != 0) {
70 return NT_STATUS_INTERNAL_ERROR;
74 status = socket_connect_complete(sock, flags);