Changeset eda925a in mainline
- Timestamp:
- 2010-02-04T15:46:51Z (15 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- d32358f
- Parents:
- b4cbef1
- Location:
- uspace
- Files:
-
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/libc/generic/async.c
rb4cbef1 reda925a 1383 1383 } 1384 1384 1385 /** Wrapper for receiving binary data 1385 /** Wrapper for receiving binary data or strings 1386 1386 * 1387 1387 * 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. 1389 1389 * 1390 1390 * @param data Pointer to data pointer (which should be later disposed 1391 1391 * by free()). If the operation fails, the pointer is not 1392 1392 * 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. 1393 1396 * @param min_size Minimum size (in bytes) of the data to receive. 1394 1397 * @param max_size Maximum size (in bytes) of the data to receive. 0 means 1395 1398 * no limit. 1396 * @param granulariy If non-zero ,then the size of the received data has to1399 * @param granulariy If non-zero then the size of the received data has to 1397 1400 * be divisible by this value. 1398 1401 * @param received If not NULL, the size of the received data is stored here. … … 1401 1404 * 1402 1405 */ 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) 1406 int 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) 1405 1409 { 1406 1410 ipc_callid_t callid; … … 1426 1430 } 1427 1431 1428 void *_data = malloc(size); 1432 void *_data; 1433 1434 if (nullterm) 1435 _data = malloc(size + 1); 1436 else 1437 _data = malloc(size); 1438 1429 1439 if (_data == NULL) { 1430 1440 ipc_answer_0(callid, ENOMEM); … … 1438 1448 } 1439 1449 1450 if (nullterm) 1451 ((char *) _data)[size] = 0; 1452 1440 1453 *data = _data; 1441 1454 if (received != NULL) … … 1445 1458 } 1446 1459 1447 /** Wrapper for receiving strings1448 *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 disposed1453 * by free()). If the operation fails, the pointer is not1454 * touched.1455 * @param max_size Maximum size (in bytes) of the string to receive. 0 means1456 * 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 1496 1460 /** Wrapper for voiding any data that is about to be received 1497 1461 * … … 1501 1465 * 1502 1466 */ 1503 void async_data_ void(const int retval)1467 void async_data_write_void(const int retval) 1504 1468 { 1505 1469 ipc_callid_t callid; … … 1512 1476 * 1513 1477 */ 1514 int async_data_ forward_fast(int phoneid, ipcarg_t method, ipcarg_t arg1,1478 int async_data_write_forward_fast(int phoneid, ipcarg_t method, ipcarg_t arg1, 1515 1479 ipcarg_t arg2, ipcarg_t arg3, ipcarg_t arg4, ipc_call_t *dataptr) 1516 1480 { -
uspace/lib/libc/include/async.h
rb4cbef1 reda925a 310 310 extern int async_data_read_receive(ipc_callid_t *, size_t *); 311 311 extern int async_data_read_finalize(ipc_callid_t, const void *, size_t); 312 312 313 extern int async_data_read_forward_fast(int, ipcarg_t, ipcarg_t, ipcarg_t, 313 314 ipcarg_t, ipcarg_t, ipc_call_t *); 314 315 315 316 /* 316 * User-friendly wrappers for async_data_forward_fast(). 317 */ 318 #define async_data_forward_0_0(phoneid, method, answer) \ 319 async_data_forward_fast((phoneid), (method), 0, 0, 0, 0, NULL) 320 #define async_data_forward_0_1(phoneid, method, answer) \ 321 async_data_forward_fast((phoneid), (method), 0, 0, 0, 0, (answer)) 322 #define async_data_forward_1_0(phoneid, method, arg1, answer) \ 323 async_data_forward_fast((phoneid), (method), (arg1), 0, 0, 0, NULL) 324 #define async_data_forward_1_1(phoneid, method, arg1, answer) \ 325 async_data_forward_fast((phoneid), (method), (arg1), 0, 0, 0, (answer)) 326 #define async_data_forward_2_0(phoneid, method, arg1, arg2, answer) \ 327 async_data_forward_fast((phoneid), (method), (arg1), (arg2), 0, 0, NULL) 328 #define async_data_forward_2_1(phoneid, method, arg1, arg2, answer) \ 329 async_data_forward_fast((phoneid), (method), (arg1), (arg2), 0, 0, \ 317 * User-friendly wrappers for async_data_write_forward_fast(). 318 */ 319 #define async_data_write_forward_0_0(phoneid, method, answer) \ 320 async_data_write_forward_fast((phoneid), (method), 0, 0, 0, 0, NULL) 321 #define async_data_write_forward_0_1(phoneid, method, answer) \ 322 async_data_write_forward_fast((phoneid), (method), 0, 0, 0, 0, (answer)) 323 #define async_data_write_forward_1_0(phoneid, method, arg1, answer) \ 324 async_data_write_forward_fast((phoneid), (method), (arg1), 0, 0, 0, NULL) 325 #define async_data_write_forward_1_1(phoneid, method, arg1, answer) \ 326 async_data_write_forward_fast((phoneid), (method), (arg1), 0, 0, 0, \ 330 327 (answer)) 331 #define async_data_ forward_3_0(phoneid, method, arg1, arg2, arg3, answer) \332 async_data_ forward_fast((phoneid), (method), (arg1), (arg2), (arg3), 0, \333 NULL) 334 #define async_data_ forward_3_1(phoneid, method, arg1, arg2, arg3, answer) \335 async_data_ forward_fast((phoneid), (method), (arg1), (arg2), (arg3), 0, \328 #define async_data_write_forward_2_0(phoneid, method, arg1, arg2, answer) \ 329 async_data_write_forward_fast((phoneid), (method), (arg1), (arg2), 0, 0, \ 330 NULL) 331 #define async_data_write_forward_2_1(phoneid, method, arg1, arg2, answer) \ 332 async_data_write_forward_fast((phoneid), (method), (arg1), (arg2), 0, 0, \ 336 333 (answer)) 337 #define async_data_forward_4_0(phoneid, method, arg1, arg2, arg3, arg4, answer) \ 338 async_data_forward_fast((phoneid), (method), (arg1), (arg2), (arg3), \ 334 #define async_data_write_forward_3_0(phoneid, method, arg1, arg2, arg3, answer) \ 335 async_data_write_forward_fast((phoneid), (method), (arg1), (arg2), (arg3), \ 336 0, NULL) 337 #define async_data_write_forward_3_1(phoneid, method, arg1, arg2, arg3, answer) \ 338 async_data_write_forward_fast((phoneid), (method), (arg1), (arg2), (arg3), \ 339 0, (answer)) 340 #define async_data_write_forward_4_0(phoneid, method, arg1, arg2, arg3, arg4, answer) \ 341 async_data_write_forward_fast((phoneid), (method), (arg1), (arg2), (arg3), \ 339 342 (arg4), NULL) 340 #define async_data_ forward_4_1(phoneid, method, arg1, arg2, arg3, arg4, answer) \341 async_data_ forward_fast((phoneid), (method), (arg1), (arg2), (arg3), \343 #define async_data_write_forward_4_1(phoneid, method, arg1, arg2, arg3, arg4, answer) \ 344 async_data_write_forward_fast((phoneid), (method), (arg1), (arg2), (arg3), \ 342 345 (arg4), (answer)) 343 346 … … 345 348 extern int async_data_write_receive(ipc_callid_t *, size_t *); 346 349 extern int async_data_write_finalize(ipc_callid_t, void *, size_t); 347 extern int async_data_receive(void **, const size_t, const size_t, 348 const size_t, size_t *); 349 extern int async_string_receive(char **, const size_t, size_t *); 350 extern void async_data_void(const int); 351 extern int async_data_forward_fast(int, ipcarg_t, ipcarg_t, ipcarg_t, ipcarg_t, 352 ipcarg_t, ipc_call_t *); 350 351 extern int async_data_write_accept(void **, const bool, const size_t, 352 const size_t, const size_t, size_t *); 353 extern void async_data_write_void(const int); 354 355 extern int async_data_write_forward_fast(int, ipcarg_t, ipcarg_t, ipcarg_t, 356 ipcarg_t, ipcarg_t, ipc_call_t *); 353 357 354 358 #endif -
uspace/lib/libfs/libfs.c
rb4cbef1 reda925a 176 176 if ((res != EOK) || (!fn)) { 177 177 ipc_hangup(mountee_phone); 178 async_data_ void(combine_rc(res, ENOENT));178 async_data_write_void(combine_rc(res, ENOENT)); 179 179 ipc_answer_0(rid, combine_rc(res, ENOENT)); 180 180 return; … … 184 184 ipc_hangup(mountee_phone); 185 185 (void) ops->node_put(fn); 186 async_data_ void(EBUSY);186 async_data_write_void(EBUSY); 187 187 ipc_answer_0(rid, EBUSY); 188 188 return; … … 193 193 ipc_hangup(mountee_phone); 194 194 (void) ops->node_put(fn); 195 async_data_ void(rc);195 async_data_write_void(rc); 196 196 ipc_answer_0(rid, rc); 197 197 return; … … 199 199 200 200 ipc_call_t answer; 201 rc = async_data_ forward_1_1(mountee_phone, VFS_OUT_MOUNTED, mr_dev_handle,202 &answer);201 rc = async_data_write_forward_1_1(mountee_phone, VFS_OUT_MOUNTED, 202 mr_dev_handle, &answer); 203 203 204 204 if (rc == EOK) { -
uspace/srv/clip/clip.c
rb4cbef1 reda925a 65 65 break; 66 66 case CLIPBOARD_TAG_DATA: 67 rc = async_data_ receive(&data, 0, 0, 0, &size);67 rc = async_data_write_accept((char **) &data, false, 0, 0, 0, &size); 68 68 if (rc != EOK) { 69 69 ipc_answer_0(rid, rc); -
uspace/srv/devmap/devmap.c
rb4cbef1 reda925a 396 396 * Get driver name 397 397 */ 398 int rc = async_string_receive(&driver->name, DEVMAP_NAME_MAXLEN, NULL); 398 int rc = async_data_write_accept((char **) &driver->name, true, 0, 399 DEVMAP_NAME_MAXLEN, 0, NULL); 399 400 if (rc != EOK) { 400 401 free(driver); … … 510 511 /* Get fqdn */ 511 512 char *fqdn; 512 int rc = async_string_receive(&fqdn, DEVMAP_NAME_MAXLEN, NULL); 513 int rc = async_data_write_accept((char **) &fqdn, true, 0, 514 DEVMAP_NAME_MAXLEN, 0, NULL); 513 515 if (rc != EOK) { 514 516 free(device); … … 622 624 623 625 /* Get fqdn */ 624 int rc = async_string_receive(&fqdn, DEVMAP_NAME_MAXLEN, NULL); 626 int rc = async_data_write_accept((char **) &fqdn, true, 0, 627 DEVMAP_NAME_MAXLEN, 0, NULL); 625 628 if (rc != EOK) { 626 629 ipc_answer_0(iid, rc); … … 683 686 684 687 /* Get device name */ 685 int rc = async_string_receive(&name, DEVMAP_NAME_MAXLEN, NULL); 688 int rc = async_data_write_accept((char **) &name, true, 0, 689 DEVMAP_NAME_MAXLEN, 0, NULL); 686 690 if (rc != EOK) { 687 691 ipc_answer_0(iid, rc); -
uspace/srv/fs/devfs/devfs_ops.c
rb4cbef1 reda925a 419 419 420 420 /* Accept the mount options */ 421 ipcarg_t retval = async_string_receive(&opts, 0, NULL); 421 ipcarg_t retval = async_data_write_accept((char **) &opts, true, 0, 0, 422 0, NULL); 422 423 if (retval != EOK) { 423 424 ipc_answer_0(rid, retval); -
uspace/srv/fs/fat/fat_ops.c
rb4cbef1 reda925a 977 977 /* Accept the mount options */ 978 978 char *opts; 979 int rc = async_ string_receive(&opts, 0, NULL);979 int rc = async_data_write_accept((char **) &opts, true, 0, 0, 0, NULL); 980 980 981 981 if (rc != EOK) { -
uspace/srv/fs/tmpfs/tmpfs_ops.c
rb4cbef1 reda925a 442 442 /* Accept the mount options */ 443 443 char *opts; 444 int rc = async_ string_receive(&opts, 0, NULL);444 int rc = async_data_write_accept((char **) &opts, true, 0, 0, 0, NULL); 445 445 446 446 if (rc != EOK) { -
uspace/srv/hid/console/console.c
rb4cbef1 reda925a 477 477 void *buf; 478 478 size_t size; 479 int rc = async_data_ receive(&buf, 0, 0, 0, &size);479 int rc = async_data_write_accept(&buf, false, 0, 0, 0, &size); 480 480 481 481 if (rc != EOK) { -
uspace/srv/loader/main.c
rb4cbef1 reda925a 126 126 { 127 127 char *buf; 128 int rc = async_ string_receive(&buf, 0, NULL);128 int rc = async_data_write_accept((void **) &buf, true, 0, 0, 0, NULL); 129 129 130 130 if (rc == EOK) { … … 146 146 { 147 147 char *buf; 148 int rc = async_ string_receive(&buf, 0, NULL);148 int rc = async_data_write_accept((void **) &buf, true, 0, 0, 0, NULL); 149 149 150 150 if (rc == EOK) { … … 167 167 char *buf; 168 168 size_t buf_size; 169 int rc = async_ string_receive(&buf, 0, &buf_size);169 int rc = async_data_write_accept((void **) &buf, true, 0, 0, 0, &buf_size); 170 170 171 171 if (rc == EOK) { … … 232 232 fdi_node_t *buf; 233 233 size_t buf_size; 234 int rc = async_data_receive(&buf, 0, 0, sizeof(fdi_node_t), &buf_size); 234 int rc = async_data_write_accept((void **) &buf, false, 0, 0, 235 sizeof(fdi_node_t), &buf_size); 235 236 236 237 if (rc == EOK) { -
uspace/srv/vfs/vfs_ops.c
rb4cbef1 reda925a 267 267 /* We want the client to send us the mount point. */ 268 268 char *mp; 269 int rc = async_string_receive(&mp, MAX_PATH_LEN, NULL); 269 int rc = async_data_write_accept((char **) &mp, true, 0, MAX_PATH_LEN, 270 0, NULL); 270 271 if (rc != EOK) { 271 272 ipc_answer_0(rid, rc); … … 275 276 /* Now we expect to receive the mount options. */ 276 277 char *opts; 277 rc = async_string_receive(&opts, MAX_MNTOPTS_LEN, NULL); 278 rc = async_data_write_accept((char **) &opts, true, 0, MAX_MNTOPTS_LEN, 279 0, NULL); 278 280 if (rc != EOK) { 279 281 free(mp); … … 287 289 */ 288 290 char *fs_name; 289 rc = async_string_receive(&fs_name, FS_NAME_MAXLEN, NULL); 291 rc = async_data_write_accept((char **) &fs_name, true, 0, FS_NAME_MAXLEN, 292 0, NULL); 290 293 if (rc != EOK) { 291 294 free(mp); … … 357 360 * Receive the mount point path. 358 361 */ 359 rc = async_string_receive(&mp, MAX_PATH_LEN, NULL); 362 rc = async_data_write_accept((char **) &mp, true, 0, MAX_PATH_LEN, 363 0, NULL); 360 364 if (rc != EOK) 361 365 ipc_answer_0(rid, rc); … … 522 526 523 527 char *path; 524 int rc = async_ string_receive(&path, 0, NULL);528 int rc = async_data_write_accept((char **) &path, true, 0, 0, 0, NULL); 525 529 if (rc != EOK) { 526 530 ipc_answer_0(rid, rc); … … 836 840 &answer); 837 841 } else { 838 rc = async_data_ forward_3_1(fs_phone, VFS_OUT_WRITE,842 rc = async_data_write_forward_3_1(fs_phone, VFS_OUT_WRITE, 839 843 file->node->dev_handle, file->node->index, file->pos, 840 844 &answer); … … 1007 1011 { 1008 1012 char *path; 1009 int rc = async_ string_receive(&path, 0, NULL);1013 int rc = async_data_write_accept((char **) &path, true, 0, 0, 0, NULL); 1010 1014 if (rc != EOK) { 1011 1015 ipc_answer_0(rid, rc); … … 1061 1065 1062 1066 char *path; 1063 int rc = async_ string_receive(&path, 0, NULL);1067 int rc = async_data_write_accept((char **) &path, true, 0, 0, 0, NULL); 1064 1068 if (rc != EOK) { 1065 1069 ipc_answer_0(rid, rc); … … 1083 1087 1084 1088 char *path; 1085 int rc = async_ string_receive(&path, 0, NULL);1089 int rc = async_data_write_accept((char **) &path, true, 0, 0, 0, NULL); 1086 1090 if (rc != EOK) { 1087 1091 ipc_answer_0(rid, rc); … … 1118 1122 /* Retrieve the old path. */ 1119 1123 char *old; 1120 int rc = async_ string_receive(&old, 0, NULL);1124 int rc = async_data_write_accept((char **) &old, true, 0, 0, 0, NULL); 1121 1125 if (rc != EOK) { 1122 1126 ipc_answer_0(rid, rc); … … 1126 1130 /* Retrieve the new path. */ 1127 1131 char *new; 1128 rc = async_ string_receive(&new, 0, NULL);1132 rc = async_data_write_accept((char **) &new, true, 0, 0, 0, NULL); 1129 1133 if (rc != EOK) { 1130 1134 free(old); -
uspace/srv/vfs/vfs_register.c
rb4cbef1 reda925a 114 114 115 115 vfs_info_t *vfs_info; 116 int rc = async_data_ receive(&vfs_info, sizeof(vfs_info_t),117 sizeof(vfs_info_t), 0, NULL);116 int rc = async_data_write_accept((void **) &vfs_info, false, 117 sizeof(vfs_info_t), sizeof(vfs_info_t), 0, NULL); 118 118 119 119 if (rc != EOK) {
Note:
See TracChangeset
for help on using the changeset viewer.