Changeset c47e1a8 in mainline for uspace/lib/c/generic/async.c


Ignore:
Timestamp:
2010-05-21T07:50:04Z (16 years ago)
Author:
Lenka Trochtova <trochtova.lenka@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
d51ee2b
Parents:
cf8cc36 (diff), 15b592b (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

merge mainline changes (rev. 451)

File:
1 moved

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/generic/async.c

    rcf8cc36 rc47e1a8  
    746746        if (!hash_table_create(&conn_hash_table, CONN_HASH_TABLE_CHAINS, 1,
    747747            &conn_hash_table_ops)) {
    748                 printf("%s: cannot create hash table\n", "async");
     748                printf("%s: Cannot create async hash table\n", "libc");
    749749                return ENOMEM;
    750750        }
     
    11011101}
    11021102
     1103/** Wrapper for making IPC_M_CONNECT_ME_TO calls using the async framework.
     1104 *
     1105 * Ask through phone for a new connection to some service.
     1106 *
     1107 * @param phoneid       Phone handle used for contacting the other side.
     1108 * @param arg1          User defined argument.
     1109 * @param arg2          User defined argument.
     1110 * @param arg3          User defined argument.
     1111 *
     1112 * @return              New phone handle on success or a negative error code.
     1113 */
     1114int
     1115async_connect_me_to(int phoneid, ipcarg_t arg1, ipcarg_t arg2, ipcarg_t arg3)
     1116{
     1117        int rc;
     1118        ipcarg_t newphid;
     1119
     1120        rc = async_req_3_5(phoneid, IPC_M_CONNECT_ME_TO, arg1, arg2, arg3, NULL,
     1121            NULL, NULL, NULL, &newphid);
     1122       
     1123        if (rc != EOK) 
     1124                return rc;
     1125
     1126        return newphid;
     1127}
     1128
     1129/** Wrapper for making IPC_M_CONNECT_ME_TO calls using the async framework.
     1130 *
     1131 * Ask through phone for a new connection to some service and block until
     1132 * success.
     1133 *
     1134 * @param phoneid       Phone handle used for contacting the other side.
     1135 * @param arg1          User defined argument.
     1136 * @param arg2          User defined argument.
     1137 * @param arg3          User defined argument.
     1138 *
     1139 * @return              New phone handle on success or a negative error code.
     1140 */
     1141int
     1142async_connect_me_to_blocking(int phoneid, ipcarg_t arg1, ipcarg_t arg2,
     1143    ipcarg_t arg3)
     1144{
     1145        int rc;
     1146        ipcarg_t newphid;
     1147
     1148        rc = async_req_4_5(phoneid, IPC_M_CONNECT_ME_TO, arg1, arg2, arg3,
     1149            IPC_FLAG_BLOCKING, NULL, NULL, NULL, NULL, &newphid);
     1150       
     1151        if (rc != EOK) 
     1152                return rc;
     1153
     1154        return newphid;
     1155}
     1156
    11031157/** Wrapper for making IPC_M_SHARE_IN calls using the async framework.
    11041158 *
     
    13101364            IPC_FF_ROUTE_FROM_ME);
    13111365        if (retval != EOK) {
     1366                async_wait_for(msg, NULL);
    13121367                ipc_answer_0(callid, retval);
    13131368                return retval;
     
    13831438}
    13841439
    1385 /** Wrapper for receiving binary data
     1440/** Wrapper for receiving binary data or strings
    13861441 *
    13871442 * This wrapper only makes it more comfortable to use async_data_write_*
    1388  * functions to receive binary data.
     1443 * functions to receive binary data or strings.
    13891444 *
    13901445 * @param data       Pointer to data pointer (which should be later disposed
    13911446 *                   by free()). If the operation fails, the pointer is not
    13921447 *                   touched.
     1448 * @param nullterm   If true then the received data is always zero terminated.
     1449 *                   This also causes to allocate one extra byte beyond the
     1450 *                   raw transmitted data.
    13931451 * @param min_size   Minimum size (in bytes) of the data to receive.
    13941452 * @param max_size   Maximum size (in bytes) of the data to receive. 0 means
    13951453 *                   no limit.
    1396  * @param granulariy If non-zero, then the size of the received data has to
     1454 * @param granulariy If non-zero then the size of the received data has to
    13971455 *                   be divisible by this value.
    13981456 * @param received   If not NULL, the size of the received data is stored here.
     
    14011459 *
    14021460 */
    1403 int async_data_receive(void **data, const size_t min_size,
    1404     const size_t max_size, const size_t granularity, size_t *received)
     1461int async_data_write_accept(void **data, const bool nullterm,
     1462    const size_t min_size, const size_t max_size, const size_t granularity,
     1463    size_t *received)
    14051464{
    14061465        ipc_callid_t callid;
     
    14261485        }
    14271486       
    1428         void *_data = malloc(size);
     1487        void *_data;
     1488       
     1489        if (nullterm)
     1490                _data = malloc(size + 1);
     1491        else
     1492                _data = malloc(size);
     1493       
    14291494        if (_data == NULL) {
    14301495                ipc_answer_0(callid, ENOMEM);
     
    14381503        }
    14391504       
     1505        if (nullterm)
     1506                ((char *) _data)[size] = 0;
     1507       
    14401508        *data = _data;
    14411509        if (received != NULL)
     
    14451513}
    14461514
    1447 /** Wrapper for receiving strings
    1448  *
    1449  * This wrapper only makes it more comfortable to use async_data_write_*
    1450  * functions to receive strings.
    1451  *
    1452  * @param str      Pointer to string pointer (which should be later disposed
    1453  *                 by free()). If the operation fails, the pointer is not
    1454  *                 touched.
    1455  * @param max_size Maximum size (in bytes) of the string to receive. 0 means
    1456  *                 no limit.
    1457  * @param received If not NULL, the size of the received data is stored here.
    1458  *
    1459  * @return Zero on success or a value from @ref errno.h on failure.
    1460  *
    1461  */
    1462 int async_string_receive(char **str, const size_t max_size, size_t *received)
    1463 {
    1464         ipc_callid_t callid;
    1465         size_t size;
    1466         if (!async_data_write_receive(&callid, &size)) {
    1467                 ipc_answer_0(callid, EINVAL);
    1468                 return EINVAL;
    1469         }
    1470        
    1471         if ((max_size > 0) && (size > max_size)) {
    1472                 ipc_answer_0(callid, EINVAL);
    1473                 return EINVAL;
    1474         }
    1475        
    1476         char *data = (char *) malloc(size + 1);
    1477         if (data == NULL) {
    1478                 ipc_answer_0(callid, ENOMEM);
    1479                 return ENOMEM;
    1480         }
    1481        
    1482         int rc = async_data_write_finalize(callid, data, size);
    1483         if (rc != EOK) {
    1484                 free(data);
    1485                 return rc;
    1486         }
    1487        
    1488         data[size] = 0;
    1489         *str = data;
    1490         if (received != NULL)
    1491                 *received = size;
    1492        
    1493         return EOK;
    1494 }
    1495 
    14961515/** Wrapper for voiding any data that is about to be received
    14971516 *
     
    15011520 *
    15021521 */
    1503 void async_data_void(const int retval)
     1522void async_data_write_void(const int retval)
    15041523{
    15051524        ipc_callid_t callid;
     
    15121531 *
    15131532 */
    1514 int async_data_forward_fast(int phoneid, ipcarg_t method, ipcarg_t arg1,
     1533int async_data_write_forward_fast(int phoneid, ipcarg_t method, ipcarg_t arg1,
    15151534    ipcarg_t arg2, ipcarg_t arg3, ipcarg_t arg4, ipc_call_t *dataptr)
    15161535{
     
    15311550            IPC_FF_ROUTE_FROM_ME);
    15321551        if (retval != EOK) {
     1552                async_wait_for(msg, NULL);
    15331553                ipc_answer_0(callid, retval);
    15341554                return retval;
Note: See TracChangeset for help on using the changeset viewer.