Changeset 984a9ba in mainline for uspace/srv/net/udp/service.c


Ignore:
Timestamp:
2018-07-05T09:34:09Z (6 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
63d46341
Parents:
76f566d
Message:

do not expose the call capability handler from the async framework

Keep the call capability handler encapsulated within the async framework
and do not expose it explicitly via its API. Use the pointer to
ipc_call_t as the sole object identifying an IPC call in the code that
uses the async framework.

This plugs a major leak in the abstraction and also simplifies both the
async framework (slightly) and all IPC servers.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/net/udp/service.c

    r76f566d r984a9ba  
    326326 * Handle client request to create callback session.
    327327 *
    328  * @param client        UDP client
    329  * @param icall_handle  Async request call handle
    330  * @param icall         Async request data
    331  */
    332 static void
    333 udp_callback_create_srv(udp_client_t *client, cap_call_handle_t icall_handle,
    334     ipc_call_t *icall)
     328 * @param client UDP client
     329 * @param icall  Async request data
     330 *
     331 */
     332static void udp_callback_create_srv(udp_client_t *client, ipc_call_t *icall)
    335333{
    336334        log_msg(LOG_DEFAULT, LVL_DEBUG, "udp_callback_create_srv()");
     
    338336        async_sess_t *sess = async_callback_receive(EXCHANGE_SERIALIZE);
    339337        if (sess == NULL) {
    340                 async_answer_0(icall_handle, ENOMEM);
     338                async_answer_0(icall, ENOMEM);
    341339                return;
    342340        }
    343341
    344342        client->sess = sess;
    345         async_answer_0(icall_handle, EOK);
     343        async_answer_0(icall, EOK);
    346344}
    347345
     
    350348 * Handle client request to create association.
    351349 *
    352  * @param client        UDP client
    353  * @param icall_handle  Async request call handle
    354  * @param icall         Async request data
    355  */
    356 static void
    357 udp_assoc_create_srv(udp_client_t *client, cap_call_handle_t icall_handle,
    358     ipc_call_t *icall)
    359 {
    360         cap_call_handle_t chandle;
     350 * @param client UDP client
     351 * @param icall  Async request data
     352 *
     353 */
     354static void udp_assoc_create_srv(udp_client_t *client, ipc_call_t *icall)
     355{
     356        ipc_call_t call;
    361357        size_t size;
    362358        inet_ep2_t epp;
     
    366362        log_msg(LOG_DEFAULT, LVL_DEBUG, "udp_assoc_create_srv()");
    367363
    368         if (!async_data_write_receive(&chandle, &size)) {
    369                 async_answer_0(chandle, EREFUSED);
    370                 async_answer_0(icall_handle, EREFUSED);
     364        if (!async_data_write_receive(&call, &size)) {
     365                async_answer_0(&call, EREFUSED);
     366                async_answer_0(icall, EREFUSED);
    371367                return;
    372368        }
    373369
    374370        if (size != sizeof(inet_ep2_t)) {
    375                 async_answer_0(chandle, EINVAL);
    376                 async_answer_0(icall_handle, EINVAL);
    377                 return;
    378         }
    379 
    380         rc = async_data_write_finalize(chandle, &epp, size);
    381         if (rc != EOK) {
    382                 async_answer_0(chandle, rc);
    383                 async_answer_0(icall_handle, rc);
     371                async_answer_0(&call, EINVAL);
     372                async_answer_0(icall, EINVAL);
     373                return;
     374        }
     375
     376        rc = async_data_write_finalize(&call, &epp, size);
     377        if (rc != EOK) {
     378                async_answer_0(&call, rc);
     379                async_answer_0(icall, rc);
    384380                return;
    385381        }
     
    387383        rc = udp_assoc_create_impl(client, &epp, &assoc_id);
    388384        if (rc != EOK) {
    389                 async_answer_0(icall_handle, rc);
    390                 return;
    391         }
    392 
    393         async_answer_1(icall_handle, EOK, assoc_id);
     385                async_answer_0(icall, rc);
     386                return;
     387        }
     388
     389        async_answer_1(icall, EOK, assoc_id);
    394390}
    395391
     
    398394 * Handle client request to destroy association.
    399395 *
    400  * @param client        UDP client
    401  * @param icall_handle  Async request call handle
    402  * @param icall         Async request data
    403  */
    404 static void
    405 udp_assoc_destroy_srv(udp_client_t *client, cap_call_handle_t icall_handle,
    406     ipc_call_t *icall)
     396 * @param client UDP client
     397 * @param icall  Async request data
     398 *
     399 */
     400static void udp_assoc_destroy_srv(udp_client_t *client, ipc_call_t *icall)
    407401{
    408402        sysarg_t assoc_id;
     
    413407        assoc_id = IPC_GET_ARG1(*icall);
    414408        rc = udp_assoc_destroy_impl(client, assoc_id);
    415         async_answer_0(icall_handle, rc);
     409        async_answer_0(icall, rc);
    416410}
    417411
     
    420414 * Handle client request to set no local address flag.
    421415 *
    422  * @param client        UDP client
    423  * @param icall_handle  Async request call handle
    424  * @param icall         Async request data
    425  */
    426 static void
    427 udp_assoc_set_nolocal_srv(udp_client_t *client, cap_call_handle_t icall_handle,
    428     ipc_call_t *icall)
     416 * @param client UDP client
     417 * @param icall  Async request data
     418 *
     419 */
     420static void udp_assoc_set_nolocal_srv(udp_client_t *client, ipc_call_t *icall)
    429421{
    430422        sysarg_t assoc_id;
     
    435427        assoc_id = IPC_GET_ARG1(*icall);
    436428        rc = udp_assoc_set_nolocal_impl(client, assoc_id);
    437         async_answer_0(icall_handle, rc);
     429        async_answer_0(icall, rc);
    438430}
    439431
     
    442434 * Handle client request to send message.
    443435 *
    444  * @param client        UDP client
    445  * @param icall_handle  Async request call handle
    446  * @param icall         Async request data
    447  */
    448 static void
    449 udp_assoc_send_msg_srv(udp_client_t *client, cap_call_handle_t icall_handle,
    450     ipc_call_t *icall)
    451 {
    452         cap_call_handle_t chandle;
     436 * @param client UDP client
     437 * @param icall  Async request data
     438 *
     439 */
     440static void udp_assoc_send_msg_srv(udp_client_t *client, ipc_call_t *icall)
     441{
     442        ipc_call_t call;
    453443        size_t size;
    454444        inet_ep_t dest;
     
    461451        /* Receive dest */
    462452
    463         if (!async_data_write_receive(&chandle, &size)) {
    464                 async_answer_0(chandle, EREFUSED);
    465                 async_answer_0(icall_handle, EREFUSED);
     453        if (!async_data_write_receive(&call, &size)) {
     454                async_answer_0(&call, EREFUSED);
     455                async_answer_0(icall, EREFUSED);
    466456                return;
    467457        }
    468458
    469459        if (size != sizeof(inet_ep_t)) {
    470                 async_answer_0(chandle, EINVAL);
    471                 async_answer_0(icall_handle, EINVAL);
    472                 return;
    473         }
    474 
    475         rc = async_data_write_finalize(chandle, &dest, size);
    476         if (rc != EOK) {
    477                 async_answer_0(chandle, rc);
    478                 async_answer_0(icall_handle, rc);
     460                async_answer_0(&call, EINVAL);
     461                async_answer_0(icall, EINVAL);
     462                return;
     463        }
     464
     465        rc = async_data_write_finalize(&call, &dest, size);
     466        if (rc != EOK) {
     467                async_answer_0(&call, rc);
     468                async_answer_0(icall, rc);
    479469                return;
    480470        }
     
    482472        /* Receive message data */
    483473
    484         if (!async_data_write_receive(&chandle, &size)) {
    485                 async_answer_0(chandle, EREFUSED);
    486                 async_answer_0(icall_handle, EREFUSED);
     474        if (!async_data_write_receive(&call, &size)) {
     475                async_answer_0(&call, EREFUSED);
     476                async_answer_0(icall, EREFUSED);
    487477                return;
    488478        }
    489479
    490480        if (size > MAX_MSG_SIZE) {
    491                 async_answer_0(chandle, EINVAL);
    492                 async_answer_0(icall_handle, EINVAL);
     481                async_answer_0(&call, EINVAL);
     482                async_answer_0(icall, EINVAL);
    493483                return;
    494484        }
     
    496486        data = malloc(size);
    497487        if (data == NULL) {
    498                 async_answer_0(chandle, ENOMEM);
    499                 async_answer_0(icall_handle, ENOMEM);
    500         }
    501 
    502         rc = async_data_write_finalize(chandle, data, size);
    503         if (rc != EOK) {
    504                 async_answer_0(chandle, rc);
    505                 async_answer_0(icall_handle, rc);
     488                async_answer_0(&call, ENOMEM);
     489                async_answer_0(icall, ENOMEM);
     490        }
     491
     492        rc = async_data_write_finalize(&call, data, size);
     493        if (rc != EOK) {
     494                async_answer_0(&call, rc);
     495                async_answer_0(icall, rc);
    506496                free(data);
    507497                return;
     
    512502        rc = udp_assoc_send_msg_impl(client, assoc_id, &dest, data, size);
    513503        if (rc != EOK) {
    514                 async_answer_0(icall_handle, rc);
     504                async_answer_0(icall, rc);
    515505                free(data);
    516506                return;
    517507        }
    518508
    519         async_answer_0(icall_handle, EOK);
     509        async_answer_0(icall, EOK);
    520510        free(data);
    521511}
     
    541531 * Handle client request to get information on received message.
    542532 *
    543  * @param client        UDP client
    544  * @param icall_handle  Async request call handle
    545  * @param icall         Async request data
    546  */
    547 static void
    548 udp_rmsg_info_srv(udp_client_t *client, cap_call_handle_t icall_handle,
    549     ipc_call_t *icall)
    550 {
    551         cap_call_handle_t chandle;
     533 * @param client UDP client
     534 * @param icall  Async request data
     535 *
     536 */
     537static void udp_rmsg_info_srv(udp_client_t *client, ipc_call_t *icall)
     538{
     539        ipc_call_t call;
    552540        size_t size;
    553541        udp_crcv_queue_entry_t *enext;
     
    558546        enext = udp_rmsg_get_next(client);
    559547
    560         if (!async_data_read_receive(&chandle, &size)) {
    561                 async_answer_0(chandle, EREFUSED);
    562                 async_answer_0(icall_handle, EREFUSED);
     548        if (!async_data_read_receive(&call, &size)) {
     549                async_answer_0(&call, EREFUSED);
     550                async_answer_0(icall, EREFUSED);
    563551                return;
    564552        }
    565553
    566554        if (enext == NULL) {
    567                 async_answer_0(chandle, ENOENT);
    568                 async_answer_0(icall_handle, ENOENT);
    569                 return;
    570         }
    571 
    572         rc = async_data_read_finalize(chandle, &enext->epp.remote,
     555                async_answer_0(&call, ENOENT);
     556                async_answer_0(icall, ENOENT);
     557                return;
     558        }
     559
     560        rc = async_data_read_finalize(&call, &enext->epp.remote,
    573561            max(size, (size_t)sizeof(inet_ep_t)));
    574562        if (rc != EOK) {
    575                 async_answer_0(icall_handle, rc);
     563                async_answer_0(icall, rc);
    576564                return;
    577565        }
     
    582570        log_msg(LOG_DEFAULT, LVL_DEBUG, "udp_rmsg_info_srv(): assoc_id=%zu, "
    583571            "size=%zu", assoc_id, size);
    584         async_answer_2(icall_handle, EOK, assoc_id, size);
     572        async_answer_2(icall, EOK, assoc_id, size);
    585573}
    586574
     
    589577 * Handle client request to read data from first received message.
    590578 *
    591  * @param client        UDP client
    592  * @param icall_handle  Async request call handle
    593  * @param icall         Async request data
    594  */
    595 static void
    596 udp_rmsg_read_srv(udp_client_t *client, cap_call_handle_t icall_handle,
    597     ipc_call_t *icall)
    598 {
    599         cap_call_handle_t chandle;
     579 * @param client UDP client
     580 * @param icall  Async request data
     581 *
     582 */
     583static void udp_rmsg_read_srv(udp_client_t *client, ipc_call_t *icall)
     584{
     585        ipc_call_t call;
    600586        size_t msg_size;
    601587        udp_crcv_queue_entry_t *enext;
     
    610596        enext = udp_rmsg_get_next(client);
    611597
    612         if (!async_data_read_receive(&chandle, &size)) {
    613                 async_answer_0(chandle, EREFUSED);
    614                 async_answer_0(icall_handle, EREFUSED);
     598        if (!async_data_read_receive(&call, &size)) {
     599                async_answer_0(&call, EREFUSED);
     600                async_answer_0(icall, EREFUSED);
    615601                return;
    616602        }
    617603
    618604        if (enext == NULL) {
    619                 async_answer_0(chandle, ENOENT);
    620                 async_answer_0(icall_handle, ENOENT);
     605                async_answer_0(&call, ENOENT);
     606                async_answer_0(icall, ENOENT);
    621607                return;
    622608        }
     
    626612
    627613        if (off > msg_size) {
    628                 async_answer_0(chandle, EINVAL);
    629                 async_answer_0(icall_handle, EINVAL);
    630                 return;
    631         }
    632 
    633         rc = async_data_read_finalize(chandle, data, min(msg_size - off, size));
    634         if (rc != EOK) {
    635                 async_answer_0(icall_handle, rc);
    636                 return;
    637         }
    638 
    639         async_answer_0(icall_handle, EOK);
     614                async_answer_0(&call, EINVAL);
     615                async_answer_0(icall, EINVAL);
     616                return;
     617        }
     618
     619        rc = async_data_read_finalize(&call, data, min(msg_size - off, size));
     620        if (rc != EOK) {
     621                async_answer_0(icall, rc);
     622                return;
     623        }
     624
     625        async_answer_0(icall, EOK);
    640626        log_msg(LOG_DEFAULT, LVL_DEBUG, "udp_rmsg_read_srv(): OK");
    641627}
     
    646632 * to the next one.
    647633 *
    648  * @param client        UDP client
    649  * @param icall_handle  Async request call handle
    650  * @param icall         Async request data
    651  */
    652 static void
    653 udp_rmsg_discard_srv(udp_client_t *client, cap_call_handle_t icall_handle,
    654     ipc_call_t *icall)
     634 * @param client UDP client
     635 * @param icall  Async request data
     636 *
     637 */
     638static void udp_rmsg_discard_srv(udp_client_t *client, ipc_call_t *icall)
    655639{
    656640        udp_crcv_queue_entry_t *enext;
     
    661645        if (enext == NULL) {
    662646                log_msg(LOG_DEFAULT, LVL_DEBUG, "usg_rmsg_discard_srv: enext==NULL");
    663                 async_answer_0(icall_handle, ENOENT);
     647                async_answer_0(icall, ENOENT);
    664648                return;
    665649        }
     
    668652        udp_msg_delete(enext->msg);
    669653        free(enext);
    670         async_answer_0(icall_handle, EOK);
     654        async_answer_0(icall, EOK);
    671655}
    672656
    673657/** Handle UDP client connection.
    674658 *
    675  * @param icall_handle  Connect call handle
    676  * @param icall         Connect call data
    677  * @param arg           Connection argument
    678  */
    679 static void udp_client_conn(cap_call_handle_t icall_handle, ipc_call_t *icall,
    680     void *arg)
     659 * @param icall Connect call data
     660 * @param arg   Connection argument
     661 *
     662 */
     663static void udp_client_conn(ipc_call_t *icall, void *arg)
    681664{
    682665        udp_client_t client;
     
    684667
    685668        /* Accept the connection */
    686         async_answer_0(icall_handle, EOK);
     669        async_answer_0(icall, EOK);
    687670
    688671        log_msg(LOG_DEFAULT, LVL_DEBUG, "udp_client_conn()");
     
    695678                log_msg(LOG_DEFAULT, LVL_DEBUG, "udp_client_conn: wait req");
    696679                ipc_call_t call;
    697                 cap_call_handle_t chandle = async_get_call(&call);
     680                async_get_call(&call);
    698681                sysarg_t method = IPC_GET_IMETHOD(call);
    699682
     
    702685                if (!method) {
    703686                        /* The other side has hung up */
    704                         async_answer_0(chandle, EOK);
     687                        async_answer_0(&call, EOK);
    705688                        break;
    706689                }
     
    708691                switch (method) {
    709692                case UDP_CALLBACK_CREATE:
    710                         udp_callback_create_srv(&client, chandle, &call);
     693                        udp_callback_create_srv(&client, &call);
    711694                        break;
    712695                case UDP_ASSOC_CREATE:
    713                         udp_assoc_create_srv(&client, chandle, &call);
     696                        udp_assoc_create_srv(&client, &call);
    714697                        break;
    715698                case UDP_ASSOC_DESTROY:
    716                         udp_assoc_destroy_srv(&client, chandle, &call);
     699                        udp_assoc_destroy_srv(&client, &call);
    717700                        break;
    718701                case UDP_ASSOC_SET_NOLOCAL:
    719                         udp_assoc_set_nolocal_srv(&client, chandle, &call);
     702                        udp_assoc_set_nolocal_srv(&client, &call);
    720703                        break;
    721704                case UDP_ASSOC_SEND_MSG:
    722                         udp_assoc_send_msg_srv(&client, chandle, &call);
     705                        udp_assoc_send_msg_srv(&client, &call);
    723706                        break;
    724707                case UDP_RMSG_INFO:
    725                         udp_rmsg_info_srv(&client, chandle, &call);
     708                        udp_rmsg_info_srv(&client, &call);
    726709                        break;
    727710                case UDP_RMSG_READ:
    728                         udp_rmsg_read_srv(&client, chandle, &call);
     711                        udp_rmsg_read_srv(&client, &call);
    729712                        break;
    730713                case UDP_RMSG_DISCARD:
    731                         udp_rmsg_discard_srv(&client, chandle, &call);
     714                        udp_rmsg_discard_srv(&client, &call);
    732715                        break;
    733716                default:
    734                         async_answer_0(chandle, ENOTSUP);
     717                        async_answer_0(&call, ENOTSUP);
    735718                        break;
    736719                }
Note: See TracChangeset for help on using the changeset viewer.