summaryrefslogtreecommitdiff
path: root/source4/lib
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2005-06-16 05:39:40 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 13:18:14 -0500
commitbab977dad76e9204278c7afe0bb905cda064f488 (patch)
treeff48dba24a28edb88ba6a5485688bf9f920a2928 /source4/lib
parent9105bf4054b8ebac0c73b504bf38d49f81661176 (diff)
downloadsamba-bab977dad76e9204278c7afe0bb905cda064f488.tar.gz
samba-bab977dad76e9204278c7afe0bb905cda064f488.tar.bz2
samba-bab977dad76e9204278c7afe0bb905cda064f488.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 (This used to be commit 2e3c660b2fc20e046d82bf1cc296422b6e7dfad0)
Diffstat (limited to 'source4/lib')
-rw-r--r--source4/lib/socket/config.mk3
-rw-r--r--source4/lib/socket/connect.c74
-rw-r--r--source4/lib/socket/socket.c5
-rw-r--r--source4/lib/socket/socket.h5
4 files changed, 82 insertions, 5 deletions
diff --git a/source4/lib/socket/config.mk b/source4/lib/socket/config.mk
index e4719c3f67..13fe584373 100644
--- a/source4/lib/socket/config.mk
+++ b/source4/lib/socket/config.mk
@@ -35,7 +35,8 @@ NOPROTO=YES
INIT_OBJ_FILES = \
lib/socket/socket.o
ADD_OBJ_FILES = \
- lib/socket/access.o
+ lib/socket/access.o \
+ lib/socket/connect.o
NOPROTO=YES
# End SUBSYSTEM SOCKET
################################################
diff --git a/source4/lib/socket/connect.c b/source4/lib/socket/connect.c
new file mode 100644
index 0000000000..f3f9134f26
--- /dev/null
+++ b/source4/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;
+}
diff --git a/source4/lib/socket/socket.c b/source4/lib/socket/socket.c
index 39379be678..9d5b67a966 100644
--- a/source4/lib/socket/socket.c
+++ b/source4/lib/socket/socket.c
@@ -243,13 +243,10 @@ NTSTATUS socket_sendto(struct socket_context *sock,
/*
- ask for the number of bytes in a pending incoming datagram
+ ask for the number of bytes in a pending incoming packet
*/
NTSTATUS socket_pending(struct socket_context *sock, size_t *npending)
{
- if (sock->type != SOCKET_TYPE_DGRAM) {
- return NT_STATUS_INVALID_PARAMETER;
- }
if (!sock->ops->fn_pending) {
return NT_STATUS_NOT_IMPLEMENTED;
}
diff --git a/source4/lib/socket/socket.h b/source4/lib/socket/socket.h
index e2879e5247..8645ba28bc 100644
--- a/source4/lib/socket/socket.h
+++ b/source4/lib/socket/socket.h
@@ -139,4 +139,9 @@ BOOL socket_check_access(struct socket_context *sock,
const char *service_name,
const char **allow_list, const char **deny_list);
+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);
+
#endif /* _SAMBA_SOCKET_H */