diff options
author | Andrew Tridgell <tridge@samba.org> | 2005-06-16 05:39:40 +0000 |
---|---|---|
committer | Andrew Tridgell <tridge@samba.org> | 2005-06-16 05:39:40 +0000 |
commit | 910e8e8768b9cd01497c1d4609199f0ea6680416 (patch) | |
tree | 370b2fed6d2f1064834824f804011ff8563cb53d /source/lib/socket/connect.c | |
parent | ecec4d66c703bebdc1b72b2346d47c0346218848 (diff) | |
download | samba-910e8e8768b9cd01497c1d4609199f0ea6680416.tar.gz samba-910e8e8768b9cd01497c1d4609199f0ea6680416.tar.xz samba-910e8e8768b9cd01497c1d4609199f0ea6680416.zip |
r7626: a new ldap client library. Main features are:
- hooked into events system, so requests can be truly async and won't
interfere with other processing happening at the same time
- uses NTSTATUS codes for errors (previously errors were mostly
ignored). In a similar fashion to the DOS error handling, I have
reserved a range of the NTSTATUS code 32 bit space for LDAP error
codes, so a function can return a LDAP error code in a NTSTATUS
- much cleaner packet handling
Diffstat (limited to 'source/lib/socket/connect.c')
-rw-r--r-- | source/lib/socket/connect.c | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/source/lib/socket/connect.c b/source/lib/socket/connect.c new file mode 100644 index 00000000000..f3f9134f263 --- /dev/null +++ b/source/lib/socket/connect.c @@ -0,0 +1,74 @@ +/* + Unix SMB/CIFS implementation. + + implements a non-blocking connect operation that is aware of the samba4 events + system + + Copyright (C) Andrew Tridgell 2005 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include "includes.h" +#include "lib/socket/socket.h" +#include "lib/events/events.h" + + +/* + handle write events on connect completion +*/ +static void socket_connect_handler(struct event_context *ev, struct fd_event *fde, + uint16_t flags, void *private) +{ + NTSTATUS *status = (NTSTATUS *)private; + *status = NT_STATUS_OK; +} + + +/* + just like socket_connect() but other events can happen while the + connect is ongoing. This isn't as good as making the calling code + fully async during its connect phase, but at least it means that any + calling code that uses this won't interfere with code that is + properly async + */ +NTSTATUS socket_connect_ev(struct socket_context *sock, + const char *my_address, int my_port, + const char *server_address, int server_port, + uint32_t flags, struct event_context *ev) +{ + TALLOC_CTX *tmp_ctx = talloc_new(sock); + NTSTATUS status; + + set_blocking(socket_get_fd(sock), False); + + status = socket_connect(sock, my_address, my_port, + server_address, server_port, flags); + + event_add_fd(ev, tmp_ctx, socket_get_fd(sock), EVENT_FD_WRITE, + socket_connect_handler, &status); + + while (NT_STATUS_EQUAL(status, STATUS_MORE_ENTRIES)) { + if (event_loop_once(ev) != 0) { + talloc_free(tmp_ctx); + return NT_STATUS_INTERNAL_ERROR; + } + } + + status = socket_connect_complete(sock, flags); + + talloc_free(tmp_ctx); + return status; +} |