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


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

more consistent naming scheme:

async_data_blob_receive → async_data_receive
async_data_string_receive → async_string_receive
CLIPBOARD_TAG_BLOB → CLIPBOARD_TAG_DATA

async_data_receive can now check the granularity of the received data
async_string_receive can now return the raw size of the received data

replace several common patterns of async_data_write_receive/_finalize
with a single async_data_receive/_string_receive (this greatly improves
code readability)

File:
1 edited

Legend:

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

    r28be7fa r472c09d  
    13451345}
    13461346
    1347 /** Wrapper for receiving blobs via the async_data_write_*
     1347/** Wrapper for receiving binary data via the async_data_write_*
    13481348 *
    13491349 * This wrapper only makes it more comfortable to use async_data_write_*
    13501350 * functions to receive blobs.
    13511351 *
    1352  * @param blob     Pointer to data pointer (which should be later disposed
    1353  *                 by free()). If the operation fails, the pointer is not
    1354  *                 touched.
    1355  * @param max_size Maximum size (in bytes) of the blob to receive. 0 means
    1356  *                 no limit.
    1357  * @param received If not NULL, the size of the received data is stored here.
     1352 * @param data       Pointer to data pointer (which should be later disposed
     1353 *                   by free()). If the operation fails, the pointer is not
     1354 *                   touched.
     1355 * @param max_size   Maximum size (in bytes) of the data to receive. 0 means
     1356 *                   no limit.
     1357 * @param granulariy If non-zero, then the size of the received data has to
     1358 *                   be divisible by this value.
     1359 * @param received   If not NULL, the size of the received data is stored here.
    13581360 *
    13591361 * @return Zero on success or a value from @ref errno.h on failure.
    13601362 *
    13611363 */
    1362 int async_data_blob_receive(char **blob, const size_t max_size, size_t *received)
     1364int async_data_receive(void **data, const size_t max_size,
     1365    const size_t granularity, size_t *received)
    13631366{
    13641367        ipc_callid_t callid;
     
    13741377        }
    13751378       
    1376         char *data = (char *) malloc(size);
    1377         if (data == NULL) {
     1379        if ((granularity > 0) && ((size % granularity) != 0)) {
     1380                ipc_answer_0(callid, EINVAL);
     1381                return EINVAL;
     1382        }
     1383       
     1384        void *_data = malloc(size);
     1385        if (_data == NULL) {
    13781386                ipc_answer_0(callid, ENOMEM);
    13791387                return ENOMEM;
    13801388        }
    13811389       
    1382         int rc = async_data_write_finalize(callid, data, size);
     1390        int rc = async_data_write_finalize(callid, _data, size);
    13831391        if (rc != EOK) {
    1384                 free(data);
     1392                free(_data);
    13851393                return rc;
    13861394        }
    13871395       
    1388         *blob = data;
     1396        *data = _data;
    13891397        if (received != NULL)
    13901398                *received = size;
     
    14031411 * @param max_size Maximum size (in bytes) of the string to receive. 0 means
    14041412 *                 no limit.
     1413 * @param received If not NULL, the size of the received data is stored here.
    14051414 *
    14061415 * @return Zero on success or a value from @ref errno.h on failure.
    14071416 *
    14081417 */
    1409 int async_data_string_receive(char **str, const size_t max_size)
     1418int async_string_receive(char **str, const size_t max_size, size_t *received)
    14101419{
    14111420        ipc_callid_t callid;
     
    14351444        data[size] = 0;
    14361445        *str = data;
     1446        if (received != NULL)
     1447                *received = size;
     1448       
    14371449        return EOK;
    14381450}
Note: See TracChangeset for help on using the changeset viewer.