server: Add a separate function to set the timeout of an async I/O operation.
diff --git a/server/async.c b/server/async.c
index 8307e20..26221a3 100644
--- a/server/async.c
+++ b/server/async.c
@@ -166,8 +166,7 @@
 }
 
 /* create an async on a given queue of a fd */
-struct async *create_async( struct thread *thread, const struct timeval *timeout,
-                            struct async_queue *queue, const async_data_t *data )
+struct async *create_async( struct thread *thread, struct async_queue *queue, const async_data_t *data )
 {
     struct event *event = NULL;
     struct async *async;
@@ -184,16 +183,23 @@
     async->thread = (struct thread *)grab_object( thread );
     async->event = event;
     async->data = *data;
+    async->timeout = NULL;
 
     list_add_tail( &queue->queue, &async->queue_entry );
-
-    if (timeout) async->timeout = add_timeout_user( timeout, async_timeout, async );
-    else async->timeout = NULL;
+    grab_object( async );
 
     if (event) reset_event( event );
     return async;
 }
 
+/* set the timeout of an async operation */
+void async_set_timeout( struct async *async, const struct timeval *timeout )
+{
+    if (async->timeout) remove_timeout_user( async->timeout );
+    if (timeout) async->timeout = add_timeout_user( timeout, async_timeout, async );
+    else async->timeout = NULL;
+}
+
 /* store the result of the client-side async callback */
 void async_set_result( struct object *obj, unsigned int status )
 {