summaryrefslogtreecommitdiff
path: root/source4/include
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2004-07-23 06:40:49 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 12:57:42 -0500
commit5ddf678e0113f81aa2b5f99134cda4fe8c01afb7 (patch)
tree68e10d04766a1ad8e05f30c4d58e4398343ac7fb /source4/include
parent1ce4a2d5fecae297e5b6f6e8f0d68534d9dc7c92 (diff)
downloadsamba-5ddf678e0113f81aa2b5f99134cda4fe8c01afb7.tar.gz
samba-5ddf678e0113f81aa2b5f99134cda4fe8c01afb7.tar.bz2
samba-5ddf678e0113f81aa2b5f99134cda4fe8c01afb7.zip
r1578: the first stage of the async client rewrite.
Up to now the client code has had an async API, and operated asynchronously at the packet level, but was not truly async in that it assumed that it could always write to the socket and when a partial packet came in that it could block waiting for the rest of the packet. This change makes the SMB client library full async, by adding a separate outgoing packet queue, using non-blocking socket IO and having a input buffer that can fill asynchonously until the full packet has arrived. The main complexity was in dealing with the events structure when using the CIFS proxy backend. In that case the same events structure needs to be used in both the client library and the main smbd server, so that when the client library is waiting for a reply that the main server keeps processing packets. This required some changes in the events library code. Next step is to make the generated rpc client code use these new capabilities. (This used to be commit 96bf4da3edc4d64b0f58ef520269f3b385b8da02)
Diffstat (limited to 'source4/include')
-rw-r--r--source4/include/cli_context.h42
-rw-r--r--source4/include/dlinklist.h14
-rw-r--r--source4/include/events.h2
-rw-r--r--source4/include/rewrite.h7
4 files changed, 54 insertions, 11 deletions
diff --git a/source4/include/cli_context.h b/source4/include/cli_context.h
index 22a9898188..e0bf1689ad 100644
--- a/source4/include/cli_context.h
+++ b/source4/include/cli_context.h
@@ -134,7 +134,7 @@ struct cli_transport {
uint_t readbraw_pending:1;
/* an idle function - if this is defined then it will be
- called once every period milliseconds while we are waiting
+ called once every period seconds while we are waiting
for a packet */
struct {
void (*func)(struct cli_transport *, void *);
@@ -151,7 +151,11 @@ struct cli_transport {
uint16_t ecode;
} dos;
NTSTATUS nt_status;
- enum socket_error socket_error;
+ enum {SOCKET_READ_TIMEOUT,
+ SOCKET_READ_EOF,
+ SOCKET_READ_ERROR,
+ SOCKET_WRITE_ERROR,
+ SOCKET_READ_BAD_SIG} socket_error;
uint_t nbt_error;
} e;
} error;
@@ -164,12 +168,30 @@ struct cli_transport {
void *private;
} oplock;
- /* a list of async requests that are pending on this connection */
- struct cli_request *pending_requests;
+ /* a list of async requests that are pending for send on this connection */
+ struct cli_request *pending_send;
+
+ /* a list of async requests that are pending for receive on this connection */
+ struct cli_request *pending_recv;
/* remember the called name - some sub-protocols require us to
know the server name */
struct nmb_name called;
+
+ /* a buffer for partially received SMB packets. */
+ struct {
+ uint8_t header[NBT_HDR_SIZE];
+ size_t req_size;
+ size_t received;
+ uint8_t *buffer;
+ } recv_buffer;
+
+ /* the event handle for waiting for socket IO */
+ struct {
+ struct event_context *ctx;
+ struct fd_event *fde;
+ struct timed_event *te;
+ } event;
};
/* this is the context for the user */
@@ -216,6 +238,15 @@ struct cli_tree {
};
+/*
+ a client request moves between the following 4 states.
+*/
+enum cli_request_state {CLI_REQUEST_INIT, /* we are creating the request */
+ CLI_REQUEST_SEND, /* the request is in the outgoing socket Q */
+ CLI_REQUEST_RECV, /* we are waiting for a matching reply */
+ CLI_REQUEST_DONE, /* the request is finished */
+ CLI_REQUEST_ERROR}; /* a packet or transport level error has occurred */
+
/* the context for a single SMB request. This is passed to any request-context
* functions (similar to context.h, the server version).
* This will allow requests to be multi-threaded. */
@@ -226,6 +257,9 @@ struct cli_request {
/* a talloc context for the lifetime of this request */
TALLOC_CTX *mem_ctx;
+ /* each request is in one of 4 possible states */
+ enum cli_request_state state;
+
/* a request always has a transport context, nearly always has
a session context and usually has a tree context */
struct cli_transport *transport;
diff --git a/source4/include/dlinklist.h b/source4/include/dlinklist.h
index 6191299384..40f7f0a0c7 100644
--- a/source4/include/dlinklist.h
+++ b/source4/include/dlinklist.h
@@ -77,3 +77,17 @@ do { \
DLIST_REMOVE(list, p); \
DLIST_ADD_END(list, p, tmp); \
} while (0)
+
+/* concatenate two lists - putting all elements of the 2nd list at the
+ end of the first list */
+#define DLIST_CONCATENATE(list1, list2, type) \
+do { \
+ if (!(list1)) { \
+ (list1) = (list2); \
+ } else { \
+ type tmp; \
+ for (tmp = (list1); tmp->next; tmp = tmp->next) ; \
+ tmp->next = (list2); \
+ (list2)->prev = tmp; \
+ } \
+} while (0)
diff --git a/source4/include/events.h b/source4/include/events.h
index 7dde3b2ba0..edded2632b 100644
--- a/source4/include/events.h
+++ b/source4/include/events.h
@@ -67,6 +67,8 @@ struct event_context {
BOOL exit_now;
int code;
} exit;
+
+ int ref_count;
};
diff --git a/source4/include/rewrite.h b/source4/include/rewrite.h
index c8587f5e4e..21cc7342d1 100644
--- a/source4/include/rewrite.h
+++ b/source4/include/rewrite.h
@@ -50,13 +50,6 @@ typedef int BOOL;
/* Debugging stuff */
#include "debug.h"
-/* types of socket errors */
-enum socket_error {SOCKET_READ_TIMEOUT,
- SOCKET_READ_EOF,
- SOCKET_READ_ERROR,
- SOCKET_WRITE_ERROR,
- SOCKET_READ_BAD_SIG};
-
#include "doserr.h"
/*