Add async timeout helpers
authorVolker Lendecke <vl@samba.org>
Sat, 3 Jan 2009 18:10:57 +0000 (19:10 +0100)
committerVolker Lendecke <vl@samba.org>
Sun, 4 Jan 2009 15:42:40 +0000 (16:42 +0100)
source3/include/async_req.h
source3/lib/async_req.c

index 2633027e37bae9d7a667983f489897c264beebfa..bbe52da723c5369697678ed09453195c40afd694 100644 (file)
@@ -132,4 +132,14 @@ bool async_req_is_error(struct async_req *req, NTSTATUS *status);
 
 NTSTATUS async_req_simple_recv(struct async_req *req);
 
+bool async_req_set_timeout(struct async_req *req, struct event_context *ev,
+                          struct timeval to);
+
+struct async_req *async_wait_send(TALLOC_CTX *mem_ctx,
+                                 struct event_context *ev,
+                                 struct timeval to);
+
+NTSTATUS async_wait_recv(struct async_req *req);
+
+
 #endif
index 8c9b2e6b47f23d5033517cbc9fd3be0488d784a5..0653ff62a7fed1f15d8022110f49e399a12ca848 100644 (file)
@@ -194,3 +194,45 @@ NTSTATUS async_req_simple_recv(struct async_req *req)
        }
        return NT_STATUS_OK;
 }
+
+static void async_req_timedout(struct event_context *ev,
+                              struct timed_event *te,
+                              const struct timeval *now,
+                              void *priv)
+{
+       struct async_req *req = talloc_get_type_abort(
+               priv, struct async_req);
+       TALLOC_FREE(te);
+       async_req_error(req, NT_STATUS_IO_TIMEOUT);
+}
+
+bool async_req_set_timeout(struct async_req *req, struct event_context *ev,
+                          struct timeval to)
+{
+       return (event_add_timed(ev, req,
+                               timeval_current_ofs(to.tv_sec, to.tv_usec),
+                               "async_req_timedout", async_req_timedout, req)
+               != NULL);
+}
+
+struct async_req *async_wait_send(TALLOC_CTX *mem_ctx,
+                                 struct event_context *ev,
+                                 struct timeval to)
+{
+       struct async_req *result;
+
+       result = async_req_new(mem_ctx);
+       if (result == NULL) {
+               return result;
+       }
+       if (!async_req_set_timeout(result, ev, to)) {
+               TALLOC_FREE(result);
+               return NULL;
+       }
+       return result;
+}
+
+NTSTATUS async_wait_recv(struct async_req *req)
+{
+       return NT_STATUS_OK;
+}