Changeset eda925a in mainline for uspace/lib/libc/generic/async.c


Ignore:
Timestamp:
2010-02-04T15:46:51Z (14 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
d32358f
Parents:
b4cbef1
Message:

improve naming conventions:
merge async_data_receive() and async_string_receive() into async_data_write_accept()
rename async_data_void() to async_data_write_void()
rename async_data_forward_fast() to async_data_write_forward_fast()
rename async_data_forward_n_m to async_data_write_forward_n_m

File:
1 edited

Legend:

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

    rb4cbef1 reda925a  
    13831383}
    13841384
    1385 /** Wrapper for receiving binary data
     1385/** Wrapper for receiving binary data or strings
    13861386 *
    13871387 * This wrapper only makes it more comfortable to use async_data_write_*
    1388  * functions to receive binary data.
     1388 * functions to receive binary data or strings.
    13891389 *
    13901390 * @param data       Pointer to data pointer (which should be later disposed
    13911391 *                   by free()). If the operation fails, the pointer is not
    13921392 *                   touched.
     1393 * @param nullterm   If true then the received data is always zero terminated.
     1394 *                   This also causes to allocate one extra byte beyond the
     1395 *                   raw transmitted data.
    13931396 * @param min_size   Minimum size (in bytes) of the data to receive.
    13941397 * @param max_size   Maximum size (in bytes) of the data to receive. 0 means
    13951398 *                   no limit.
    1396  * @param granulariy If non-zero, then the size of the received data has to
     1399 * @param granulariy If non-zero then the size of the received data has to
    13971400 *                   be divisible by this value.
    13981401 * @param received   If not NULL, the size of the received data is stored here.
     
    14011404 *
    14021405 */
    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)
     1406int async_data_write_accept(void **data, const bool nullterm,
     1407    const size_t min_size, const size_t max_size, const size_t granularity,
     1408    size_t *received)
    14051409{
    14061410        ipc_callid_t callid;
     
    14261430        }
    14271431       
    1428         void *_data = malloc(size);
     1432        void *_data;
     1433       
     1434        if (nullterm)
     1435                _data = malloc(size + 1);
     1436        else
     1437                _data = malloc(size);
     1438       
    14291439        if (_data == NULL) {
    14301440                ipc_answer_0(callid, ENOMEM);
     
    14381448        }
    14391449       
     1450        if (nullterm)
     1451                ((char *) _data)[size] = 0;
     1452       
    14401453        *data = _data;
    14411454        if (received != NULL)
     
    14451458}
    14461459
    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 
    14961460/** Wrapper for voiding any data that is about to be received
    14971461 *
     
    15011465 *
    15021466 */
    1503 void async_data_void(const int retval)
     1467void async_data_write_void(const int retval)
    15041468{
    15051469        ipc_callid_t callid;
     
    15121476 *
    15131477 */
    1514 int async_data_forward_fast(int phoneid, ipcarg_t method, ipcarg_t arg1,
     1478int async_data_write_forward_fast(int phoneid, ipcarg_t method, ipcarg_t arg1,
    15151479    ipcarg_t arg2, ipcarg_t arg3, ipcarg_t arg4, ipc_call_t *dataptr)
    15161480{
Note: See TracChangeset for help on using the changeset viewer.