Index: uspace/lib/c/generic/async/server.c
===================================================================
--- uspace/lib/c/generic/async/server.c	(revision 061274f1f58e5da465bdaa7144a7d51fb2e76d07)
+++ uspace/lib/c/generic/async/server.c	(revision 63d46341182c752620dcc5a2233d205cee1075dd)
@@ -77,17 +77,18 @@
  *   }
  *
- *   port_handler(ichandle, *icall)
+ *   port_handler(ipc_call_t *icall)
  *   {
  *     if (want_refuse) {
- *       async_answer_0(ichandle, ELIMIT);
+ *       async_answer_0(icall, ELIMIT);
  *       return;
  *     }
- *     async_answer_0(ichandle, EOK);
- *
- *     chandle = async_get_call(&call);
- *     somehow_handle_the_call(chandle, call);
- *     async_answer_2(chandle, 1, 2, 3);
- *
- *     chandle = async_get_call(&call);
+ *
+ *     async_answer_0(icall, EOK);
+ *
+ *     async_get_call(&call);
+ *     somehow_handle_the_call(&call);
+ *     async_answer_2(&call, 1, 2, 3);
+ *
+ *     async_get_call(&call);
  *     ...
  *   }
@@ -133,5 +134,4 @@
 typedef struct {
 	link_t link;
-
 	ipc_call_t call;
 } msg_t;
@@ -418,6 +418,6 @@
 	 * Call the connection handler function.
 	 */
-	fibril_connection->handler(fibril_connection->call.cap_handle,
-	    &fibril_connection->call, fibril_connection->data);
+	fibril_connection->handler(&fibril_connection->call,
+	    fibril_connection->data);
 
 	/*
@@ -964,13 +964,13 @@
 /** Return new incoming message for the current (fibril-local) connection.
  *
- * @param call   Storage where the incoming call data will be stored.
- * @param usecs  Timeout in microseconds. Zero denotes no timeout.
- *
- * @return  If no timeout was specified, then a handle of the incoming call is
- *          returned. If a timeout is specified, then a handle of the incoming
- *          call is returned unless the timeout expires prior to receiving a
- *          message. In that case zero CAP_NIL is returned.
- */
-cap_call_handle_t async_get_call_timeout(ipc_call_t *call, suseconds_t usecs)
+ * @param call  Storage where the incoming call data will be stored.
+ * @param usecs Timeout in microseconds. Zero denotes no timeout.
+ *
+ * @return If no timeout was specified, then true is returned.
+ * @return If a timeout is specified, then true is returned unless
+ *         the timeout expires prior to receiving a message.
+ *
+ */
+bool async_get_call_timeout(ipc_call_t *call, suseconds_t usecs)
 {
 	assert(call);
@@ -1007,5 +1007,5 @@
 			IPC_SET_IMETHOD(*call, IPC_M_PHONE_HUNGUP);
 			futex_unlock(&async_futex);
-			return conn->close_chandle;
+			return true;
 		}
 
@@ -1027,5 +1027,5 @@
 			/* If we timed out -> exit */
 			futex_unlock(&async_futex);
-			return CAP_NIL;
+			return false;
 		}
 	}
@@ -1035,10 +1035,9 @@
 	list_remove(&msg->link);
 
-	cap_call_handle_t chandle = msg->call.cap_handle;
 	*call = msg->call;
 	free(msg);
 
 	futex_unlock(&async_futex);
-	return chandle;
+	return true;
 }
 
@@ -1251,56 +1250,62 @@
 }
 
-errno_t async_answer_0(cap_call_handle_t chandle, errno_t retval)
-{
-	return ipc_answer_0(chandle, retval);
-}
-
-errno_t async_answer_1(cap_call_handle_t chandle, errno_t retval, sysarg_t arg1)
-{
-	return ipc_answer_1(chandle, retval, arg1);
-}
-
-errno_t async_answer_2(cap_call_handle_t chandle, errno_t retval, sysarg_t arg1,
+errno_t async_answer_0(ipc_call_t *call, errno_t retval)
+{
+	return ipc_answer_0(call->cap_handle, retval);
+}
+
+errno_t async_answer_1(ipc_call_t *call, errno_t retval, sysarg_t arg1)
+{
+	return ipc_answer_1(call->cap_handle, retval, arg1);
+}
+
+errno_t async_answer_2(ipc_call_t *call, errno_t retval, sysarg_t arg1,
     sysarg_t arg2)
 {
-	return ipc_answer_2(chandle, retval, arg1, arg2);
-}
-
-errno_t async_answer_3(cap_call_handle_t chandle, errno_t retval, sysarg_t arg1,
+	return ipc_answer_2(call->cap_handle, retval, arg1, arg2);
+}
+
+errno_t async_answer_3(ipc_call_t *call, errno_t retval, sysarg_t arg1,
     sysarg_t arg2, sysarg_t arg3)
 {
-	return ipc_answer_3(chandle, retval, arg1, arg2, arg3);
-}
-
-errno_t async_answer_4(cap_call_handle_t chandle, errno_t retval, sysarg_t arg1,
+	return ipc_answer_3(call->cap_handle, retval, arg1, arg2, arg3);
+}
+
+errno_t async_answer_4(ipc_call_t *call, errno_t retval, sysarg_t arg1,
     sysarg_t arg2, sysarg_t arg3, sysarg_t arg4)
 {
-	return ipc_answer_4(chandle, retval, arg1, arg2, arg3, arg4);
-}
-
-errno_t async_answer_5(cap_call_handle_t chandle, errno_t retval, sysarg_t arg1,
+	return ipc_answer_4(call->cap_handle, retval, arg1, arg2, arg3, arg4);
+}
+
+errno_t async_answer_5(ipc_call_t *call, errno_t retval, sysarg_t arg1,
     sysarg_t arg2, sysarg_t arg3, sysarg_t arg4, sysarg_t arg5)
 {
-	return ipc_answer_5(chandle, retval, arg1, arg2, arg3, arg4, arg5);
-}
-
-errno_t async_forward_fast(cap_call_handle_t chandle, async_exch_t *exch,
+	return ipc_answer_5(call->cap_handle, retval, arg1, arg2, arg3, arg4,
+	    arg5);
+}
+
+errno_t async_forward_fast(ipc_call_t *call, async_exch_t *exch,
     sysarg_t imethod, sysarg_t arg1, sysarg_t arg2, unsigned int mode)
 {
+	assert(call);
+
 	if (exch == NULL)
 		return ENOENT;
 
-	return ipc_forward_fast(chandle, exch->phone, imethod, arg1, arg2, mode);
-}
-
-errno_t async_forward_slow(cap_call_handle_t chandle, async_exch_t *exch,
+	return ipc_forward_fast(call->cap_handle, exch->phone, imethod, arg1,
+	    arg2, mode);
+}
+
+errno_t async_forward_slow(ipc_call_t *call, async_exch_t *exch,
     sysarg_t imethod, sysarg_t arg1, sysarg_t arg2, sysarg_t arg3,
     sysarg_t arg4, sysarg_t arg5, unsigned int mode)
 {
+	assert(call);
+
 	if (exch == NULL)
 		return ENOENT;
 
-	return ipc_forward_slow(chandle, exch->phone, imethod, arg1, arg2, arg3,
-	    arg4, arg5, mode);
+	return ipc_forward_slow(call->cap_handle, exch->phone, imethod, arg1,
+	    arg2, arg3, arg4, arg5, mode);
 }
 
@@ -1309,8 +1314,8 @@
  * Ask through phone for a new connection to some service.
  *
- * @param exch            Exchange for sending the message.
- * @param arg1            User defined argument.
- * @param arg2            User defined argument.
- * @param arg3            User defined argument.
+ * @param exch Exchange for sending the message.
+ * @param arg1 User defined argument.
+ * @param arg2 User defined argument.
+ * @param arg3 User defined argument.
  *
  * @return Zero on success or an error code.
@@ -1350,22 +1355,21 @@
  * So far, this wrapper is to be used from within a connection fibril.
  *
- * @param chandle  Storage for the handle of the IPC_M_SHARE_IN call.
- * @param size     Destination address space area size.
+ * @param call Storage for the data of the IPC_M_SHARE_IN call.
+ * @param size Destination address space area size.
  *
  * @return True on success, false on failure.
  *
  */
-bool async_share_in_receive(cap_call_handle_t *chandle, size_t *size)
-{
-	assert(chandle);
+bool async_share_in_receive(ipc_call_t *call, size_t *size)
+{
+	assert(call);
 	assert(size);
 
-	ipc_call_t data;
-	*chandle = async_get_call(&data);
-
-	if (IPC_GET_IMETHOD(data) != IPC_M_SHARE_IN)
+	async_get_call(call);
+
+	if (IPC_GET_IMETHOD(*call) != IPC_M_SHARE_IN)
 		return false;
 
-	*size = (size_t) IPC_GET_ARG1(data);
+	*size = (size_t) IPC_GET_ARG1(*call);
 	return true;
 }
@@ -1377,16 +1381,17 @@
  * argument.
  *
- * @param chandle  Handle of the IPC_M_DATA_READ call to answer.
- * @param src      Source address space base.
- * @param flags    Flags to be used for sharing. Bits can be only cleared.
+ * @param call  IPC_M_DATA_READ call to answer.
+ * @param src   Source address space base.
+ * @param flags Flags to be used for sharing. Bits can be only cleared.
  *
  * @return Zero on success or a value from @ref errno.h on failure.
  *
  */
-errno_t async_share_in_finalize(cap_call_handle_t chandle, void *src,
-    unsigned int flags)
-{
+errno_t async_share_in_finalize(ipc_call_t *call, void *src, unsigned int flags)
+{
+	assert(call);
+
 	// FIXME: The source has no business deciding destination address.
-	return ipc_answer_3(chandle, EOK, (sysarg_t) src, (sysarg_t) flags,
+	return ipc_answer_3(call->cap_handle, EOK, (sysarg_t) src, (sysarg_t) flags,
 	    (sysarg_t) _end);
 }
@@ -1400,26 +1405,25 @@
  * So far, this wrapper is to be used from within a connection fibril.
  *
- * @param chandle  Storage for the hash of the IPC_M_SHARE_OUT call.
- * @param size     Storage for the source address space area size.
- * @param flags    Storage for the sharing flags.
+ * @param call  Storage for the data of the IPC_M_SHARE_OUT call.
+ * @param size  Storage for the source address space area size.
+ * @param flags Storage for the sharing flags.
  *
  * @return True on success, false on failure.
  *
  */
-bool async_share_out_receive(cap_call_handle_t *chandle, size_t *size,
+bool async_share_out_receive(ipc_call_t *call, size_t *size,
     unsigned int *flags)
 {
-	assert(chandle);
+	assert(call);
 	assert(size);
 	assert(flags);
 
-	ipc_call_t data;
-	*chandle = async_get_call(&data);
-
-	if (IPC_GET_IMETHOD(data) != IPC_M_SHARE_OUT)
+	async_get_call(call);
+
+	if (IPC_GET_IMETHOD(*call) != IPC_M_SHARE_OUT)
 		return false;
 
-	*size = (size_t) IPC_GET_ARG2(data);
-	*flags = (unsigned int) IPC_GET_ARG3(data);
+	*size = (size_t) IPC_GET_ARG2(*call);
+	*flags = (unsigned int) IPC_GET_ARG3(*call);
 	return true;
 }
@@ -1431,14 +1435,17 @@
  * argument.
  *
- * @param chandle  Handle of the IPC_M_DATA_WRITE call to answer.
- * @param dst      Address of the storage for the destination address space area
- *                 base address.
+ * @param call IPC_M_DATA_WRITE call to answer.
+ * @param dst  Address of the storage for the destination address space area
+ *             base address.
  *
  * @return  Zero on success or a value from @ref errno.h on failure.
  *
  */
-errno_t async_share_out_finalize(cap_call_handle_t chandle, void **dst)
-{
-	return ipc_answer_2(chandle, EOK, (sysarg_t) _end, (sysarg_t) dst);
+errno_t async_share_out_finalize(ipc_call_t *call, void **dst)
+{
+	assert(call);
+
+	return ipc_answer_2(call->cap_handle, EOK, (sysarg_t) _end,
+	    (sysarg_t) dst);
 }
 
@@ -1451,43 +1458,21 @@
  * So far, this wrapper is to be used from within a connection fibril.
  *
- * @param chandle  Storage for the handle of the IPC_M_DATA_READ.
- * @param size     Storage for the maximum size. Can be NULL.
+ * @param call Storage for the data of the IPC_M_DATA_READ.
+ * @param size Storage for the maximum size. Can be NULL.
  *
  * @return True on success, false on failure.
  *
  */
-bool async_data_read_receive(cap_call_handle_t *chandle, size_t *size)
-{
-	ipc_call_t data;
-	return async_data_read_receive_call(chandle, &data, size);
-}
-
-/** Wrapper for receiving the IPC_M_DATA_READ calls using the async framework.
- *
- * This wrapper only makes it more comfortable to receive IPC_M_DATA_READ
- * calls so that the user doesn't have to remember the meaning of each IPC
- * argument.
- *
- * So far, this wrapper is to be used from within a connection fibril.
- *
- * @param chandle  Storage for the handle of the IPC_M_DATA_READ.
- * @param size     Storage for the maximum size. Can be NULL.
- *
- * @return True on success, false on failure.
- *
- */
-bool async_data_read_receive_call(cap_call_handle_t *chandle, ipc_call_t *data,
-    size_t *size)
-{
-	assert(chandle);
-	assert(data);
-
-	*chandle = async_get_call(data);
-
-	if (IPC_GET_IMETHOD(*data) != IPC_M_DATA_READ)
+bool async_data_read_receive(ipc_call_t *call, size_t *size)
+{
+	assert(call);
+
+	async_get_call(call);
+
+	if (IPC_GET_IMETHOD(*call) != IPC_M_DATA_READ)
 		return false;
 
 	if (size)
-		*size = (size_t) IPC_GET_ARG2(*data);
+		*size = (size_t) IPC_GET_ARG2(*call);
 
 	return true;
@@ -1500,16 +1485,18 @@
  * argument.
  *
- * @param chandle  Handle of the IPC_M_DATA_READ call to answer.
- * @param src      Source address for the IPC_M_DATA_READ call.
- * @param size     Size for the IPC_M_DATA_READ call. Can be smaller than
- *                 the maximum size announced by the sender.
+ * @param call IPC_M_DATA_READ call to answer.
+ * @param src  Source address for the IPC_M_DATA_READ call.
+ * @param size Size for the IPC_M_DATA_READ call. Can be smaller than
+ *             the maximum size announced by the sender.
  *
  * @return  Zero on success or a value from @ref errno.h on failure.
  *
  */
-errno_t async_data_read_finalize(cap_call_handle_t chandle, const void *src,
-    size_t size)
-{
-	return ipc_answer_2(chandle, EOK, (sysarg_t) src, (sysarg_t) size);
+errno_t async_data_read_finalize(ipc_call_t *call, const void *src, size_t size)
+{
+	assert(call);
+
+	return ipc_answer_2(call->cap_handle, EOK, (sysarg_t) src,
+	    (sysarg_t) size);
 }
 
@@ -1524,7 +1511,7 @@
 		return ENOENT;
 
-	cap_call_handle_t chandle;
-	if (!async_data_read_receive(&chandle, NULL)) {
-		ipc_answer_0(chandle, EINVAL);
+	ipc_call_t call;
+	if (!async_data_read_receive(&call, NULL)) {
+		async_answer_0(&call, EINVAL);
 		return EINVAL;
 	}
@@ -1533,13 +1520,13 @@
 	    dataptr);
 	if (msg == 0) {
-		ipc_answer_0(chandle, EINVAL);
+		async_answer_0(&call, EINVAL);
 		return EINVAL;
 	}
 
-	errno_t retval = ipc_forward_fast(chandle, exch->phone, 0, 0, 0,
+	errno_t retval = ipc_forward_fast(call.cap_handle, exch->phone, 0, 0, 0,
 	    IPC_FF_ROUTE_FROM_ME);
 	if (retval != EOK) {
 		async_forget(msg);
-		ipc_answer_0(chandle, retval);
+		async_answer_0(&call, retval);
 		return retval;
 	}
@@ -1559,44 +1546,21 @@
  * So far, this wrapper is to be used from within a connection fibril.
  *
- * @param chandle  Storage for the handle of the IPC_M_DATA_WRITE.
- * @param size     Storage for the suggested size. May be NULL.
- *
- * @return  True on success, false on failure.
- *
- */
-bool async_data_write_receive(cap_call_handle_t *chandle, size_t *size)
-{
-	ipc_call_t data;
-	return async_data_write_receive_call(chandle, &data, size);
-}
-
-/** Wrapper for receiving the IPC_M_DATA_WRITE calls using the async framework.
- *
- * This wrapper only makes it more comfortable to receive IPC_M_DATA_WRITE
- * calls so that the user doesn't have to remember the meaning of each IPC
- * argument.
- *
- * So far, this wrapper is to be used from within a connection fibril.
- *
- * @param chandle  Storage for the handle of the IPC_M_DATA_WRITE.
- * @param data     Storage for the ipc call data.
- * @param size     Storage for the suggested size. May be NULL.
+ * @param call Storage for the data of the IPC_M_DATA_WRITE.
+ * @param size Storage for the suggested size. May be NULL.
  *
  * @return True on success, false on failure.
  *
  */
-bool async_data_write_receive_call(cap_call_handle_t *chandle, ipc_call_t *data,
-    size_t *size)
-{
-	assert(chandle);
-	assert(data);
-
-	*chandle = async_get_call(data);
-
-	if (IPC_GET_IMETHOD(*data) != IPC_M_DATA_WRITE)
+bool async_data_write_receive(ipc_call_t *call, size_t *size)
+{
+	assert(call);
+
+	async_get_call(call);
+
+	if (IPC_GET_IMETHOD(*call) != IPC_M_DATA_WRITE)
 		return false;
 
 	if (size)
-		*size = (size_t) IPC_GET_ARG2(*data);
+		*size = (size_t) IPC_GET_ARG2(*call);
 
 	return true;
@@ -1609,15 +1573,16 @@
  * argument.
  *
- * @param chandle  Handle of the IPC_M_DATA_WRITE call to answer.
- * @param dst      Final destination address for the IPC_M_DATA_WRITE call.
- * @param size     Final size for the IPC_M_DATA_WRITE call.
+ * @param call IPC_M_DATA_WRITE call to answer.
+ * @param dst  Final destination address for the IPC_M_DATA_WRITE call.
+ * @param size Final size for the IPC_M_DATA_WRITE call.
  *
  * @return  Zero on success or a value from @ref errno.h on failure.
  *
  */
-errno_t async_data_write_finalize(cap_call_handle_t chandle, void *dst,
-    size_t size)
-{
-	return ipc_answer_2(chandle, EOK, (sysarg_t) dst, (sysarg_t) size);
+errno_t async_data_write_finalize(ipc_call_t *call, void *dst, size_t size)
+{
+	assert(call);
+
+	return async_answer_2(call, EOK, (sysarg_t) dst, (sysarg_t) size);
 }
 
@@ -1649,23 +1614,23 @@
 	assert(data);
 
-	cap_call_handle_t chandle;
+	ipc_call_t call;
 	size_t size;
-	if (!async_data_write_receive(&chandle, &size)) {
-		ipc_answer_0(chandle, EINVAL);
+	if (!async_data_write_receive(&call, &size)) {
+		async_answer_0(&call, EINVAL);
 		return EINVAL;
 	}
 
 	if (size < min_size) {
-		ipc_answer_0(chandle, EINVAL);
+		async_answer_0(&call, EINVAL);
 		return EINVAL;
 	}
 
 	if ((max_size > 0) && (size > max_size)) {
-		ipc_answer_0(chandle, EINVAL);
+		async_answer_0(&call, EINVAL);
 		return EINVAL;
 	}
 
 	if ((granularity > 0) && ((size % granularity) != 0)) {
-		ipc_answer_0(chandle, EINVAL);
+		async_answer_0(&call, EINVAL);
 		return EINVAL;
 	}
@@ -1679,9 +1644,9 @@
 
 	if (arg_data == NULL) {
-		ipc_answer_0(chandle, ENOMEM);
+		async_answer_0(&call, ENOMEM);
 		return ENOMEM;
 	}
 
-	errno_t rc = async_data_write_finalize(chandle, arg_data, size);
+	errno_t rc = async_data_write_finalize(&call, arg_data, size);
 	if (rc != EOK) {
 		free(arg_data);
@@ -1708,7 +1673,7 @@
 void async_data_write_void(errno_t retval)
 {
-	cap_call_handle_t chandle;
-	async_data_write_receive(&chandle, NULL);
-	ipc_answer_0(chandle, retval);
+	ipc_call_t call;
+	async_data_write_receive(&call, NULL);
+	async_answer_0(&call, retval);
 }
 
@@ -1723,7 +1688,7 @@
 		return ENOENT;
 
-	cap_call_handle_t chandle;
-	if (!async_data_write_receive(&chandle, NULL)) {
-		ipc_answer_0(chandle, EINVAL);
+	ipc_call_t call;
+	if (!async_data_write_receive(&call, NULL)) {
+		async_answer_0(&call, EINVAL);
 		return EINVAL;
 	}
@@ -1732,13 +1697,13 @@
 	    dataptr);
 	if (msg == 0) {
-		ipc_answer_0(chandle, EINVAL);
+		async_answer_0(&call, EINVAL);
 		return EINVAL;
 	}
 
-	errno_t retval = ipc_forward_fast(chandle, exch->phone, 0, 0, 0,
+	errno_t retval = ipc_forward_fast(call.cap_handle, exch->phone, 0, 0, 0,
 	    IPC_FF_ROUTE_FROM_ME);
 	if (retval != EOK) {
 		async_forget(msg);
-		ipc_answer_0(chandle, retval);
+		async_answer_0(&call, retval);
 		return retval;
 	}
@@ -1765,10 +1730,11 @@
 	/* Accept the phone */
 	ipc_call_t call;
-	cap_call_handle_t chandle = async_get_call(&call);
+	async_get_call(&call);
+
 	cap_phone_handle_t phandle = (cap_handle_t) IPC_GET_ARG5(call);
 
 	if ((IPC_GET_IMETHOD(call) != IPC_M_CONNECT_TO_ME) ||
 	    !CAP_HANDLE_VALID((phandle))) {
-		async_answer_0(chandle, EINVAL);
+		async_answer_0(&call, EINVAL);
 		return NULL;
 	}
@@ -1776,5 +1742,5 @@
 	async_sess_t *sess = (async_sess_t *) malloc(sizeof(async_sess_t));
 	if (sess == NULL) {
-		async_answer_0(chandle, ENOMEM);
+		async_answer_0(&call, ENOMEM);
 		return NULL;
 	}
@@ -1795,5 +1761,5 @@
 
 	/* Acknowledge the connected phone */
-	async_answer_0(chandle, EOK);
+	async_answer_0(&call, EOK);
 
 	return sess;
@@ -1843,29 +1809,21 @@
 }
 
-bool async_state_change_receive(cap_call_handle_t *chandle, sysarg_t *arg1,
-    sysarg_t *arg2, sysarg_t *arg3)
-{
-	assert(chandle);
-
-	ipc_call_t call;
-	*chandle = async_get_call(&call);
-
-	if (IPC_GET_IMETHOD(call) != IPC_M_STATE_CHANGE_AUTHORIZE)
+bool async_state_change_receive(ipc_call_t *call)
+{
+	assert(call);
+
+	async_get_call(call);
+
+	if (IPC_GET_IMETHOD(*call) != IPC_M_STATE_CHANGE_AUTHORIZE)
 		return false;
 
-	if (arg1)
-		*arg1 = IPC_GET_ARG1(call);
-	if (arg2)
-		*arg2 = IPC_GET_ARG2(call);
-	if (arg3)
-		*arg3 = IPC_GET_ARG3(call);
-
 	return true;
 }
 
-errno_t async_state_change_finalize(cap_call_handle_t chandle,
-    async_exch_t *other_exch)
-{
-	return ipc_answer_1(chandle, EOK, CAP_HANDLE_RAW(other_exch->phone));
+errno_t async_state_change_finalize(ipc_call_t *call, async_exch_t *other_exch)
+{
+	assert(call);
+
+	return async_answer_1(call, EOK, CAP_HANDLE_RAW(other_exch->phone));
 }
 
