Changeset 984a9ba in mainline for uspace/lib/c/generic/inet/tcp.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/lib/c/generic/inet/tcp.c

    r76f566d r984a9ba  
    4141#include <stdlib.h>
    4242
    43 static void tcp_cb_conn(cap_call_handle_t, ipc_call_t *, void *);
     43static void tcp_cb_conn(ipc_call_t *, void *);
    4444static errno_t tcp_conn_fibril(void *);
    4545
     
    633633/** Connection established event.
    634634 *
    635  * @param tcp           TCP client
    636  * @param icall_handle  Call handle
    637  * @param icall         Call data
    638  */
    639 static void
    640 tcp_ev_connected(tcp_t *tcp, cap_call_handle_t icall_handle, ipc_call_t *icall)
     635 * @param tcp   TCP client
     636 * @param icall Call data
     637 *
     638 */
     639static void tcp_ev_connected(tcp_t *tcp, ipc_call_t *icall)
    641640{
    642641        tcp_conn_t *conn;
     
    648647        rc = tcp_conn_get(tcp, conn_id, &conn);
    649648        if (rc != EOK) {
    650                 async_answer_0(icall_handle, ENOENT);
     649                async_answer_0(icall, ENOENT);
    651650                return;
    652651        }
     
    657656        fibril_mutex_unlock(&conn->lock);
    658657
    659         async_answer_0(icall_handle, EOK);
     658        async_answer_0(icall, EOK);
    660659}
    661660
    662661/** Connection failed event.
    663662 *
    664  * @param tcp           TCP client
    665  * @param icall_handle  Call handle
    666  * @param icall         Call data
    667  */
    668 static void
    669 tcp_ev_conn_failed(tcp_t *tcp, cap_call_handle_t icall_handle,
    670     ipc_call_t *icall)
     663 * @param tcp   TCP client
     664 * @param icall Call data
     665 *
     666 */
     667static void tcp_ev_conn_failed(tcp_t *tcp, ipc_call_t *icall)
    671668{
    672669        tcp_conn_t *conn;
     
    678675        rc = tcp_conn_get(tcp, conn_id, &conn);
    679676        if (rc != EOK) {
    680                 async_answer_0(icall_handle, ENOENT);
     677                async_answer_0(icall, ENOENT);
    681678                return;
    682679        }
     
    687684        fibril_mutex_unlock(&conn->lock);
    688685
    689         async_answer_0(icall_handle, EOK);
     686        async_answer_0(icall, EOK);
    690687}
    691688
    692689/** Connection reset event.
    693690 *
    694  * @param tcp           TCP client
    695  * @param icall_handle  Call handle
    696  * @param icall         Call data
    697  */
    698 static void tcp_ev_conn_reset(tcp_t *tcp, cap_call_handle_t icall_handle, ipc_call_t *icall)
     691 * @param tcp   TCP client
     692 * @param icall Call data
     693 *
     694 */
     695static void tcp_ev_conn_reset(tcp_t *tcp, ipc_call_t *icall)
    699696{
    700697        tcp_conn_t *conn;
     
    706703        rc = tcp_conn_get(tcp, conn_id, &conn);
    707704        if (rc != EOK) {
    708                 async_answer_0(icall_handle, ENOENT);
     705                async_answer_0(icall, ENOENT);
    709706                return;
    710707        }
     
    715712        fibril_mutex_unlock(&conn->lock);
    716713
    717         async_answer_0(icall_handle, EOK);
     714        async_answer_0(icall, EOK);
    718715}
    719716
    720717/** Data available event.
    721718 *
    722  * @param tcp           TCP client
    723  * @param icall_handle  Call handle
    724  * @param icall         Call data
    725  */
    726 static void
    727 tcp_ev_data(tcp_t *tcp, cap_call_handle_t icall_handle, ipc_call_t *icall)
     719 * @param tcp   TCP client
     720 * @param icall Call data
     721 *
     722 */
     723static void tcp_ev_data(tcp_t *tcp, ipc_call_t *icall)
    728724{
    729725        tcp_conn_t *conn;
     
    735731        rc = tcp_conn_get(tcp, conn_id, &conn);
    736732        if (rc != EOK) {
    737                 async_answer_0(icall_handle, ENOENT);
     733                async_answer_0(icall, ENOENT);
    738734                return;
    739735        }
     
    745741                conn->cb->data_avail(conn);
    746742
    747         async_answer_0(icall_handle, EOK);
     743        async_answer_0(icall, EOK);
    748744}
    749745
    750746/** Urgent data event.
    751747 *
    752  * @param tcp           TCP client
    753  * @param icall_handle  Call handle
    754  * @param icall         Call data
    755  */
    756 static void
    757 tcp_ev_urg_data(tcp_t *tcp, cap_call_handle_t icall_handle, ipc_call_t *icall)
    758 {
    759         async_answer_0(icall_handle, ENOTSUP);
     748 * @param tcp   TCP client
     749 * @param icall Call data
     750 *
     751 */
     752static void tcp_ev_urg_data(tcp_t *tcp, ipc_call_t *icall)
     753{
     754        async_answer_0(icall, ENOTSUP);
    760755}
    761756
    762757/** New connection event.
    763758 *
    764  * @param tcp           TCP client
    765  * @param icall_handle  Call handle
    766  * @param icall         Call data
    767  */
    768 static void
    769 tcp_ev_new_conn(tcp_t *tcp, cap_call_handle_t icall_handle, ipc_call_t *icall)
     759 * @param tcp   TCP client
     760 * @param icall Call data
     761 *
     762 */
     763static void tcp_ev_new_conn(tcp_t *tcp, ipc_call_t *icall)
    770764{
    771765        tcp_listener_t *lst;
     
    782776        rc = tcp_listener_get(tcp, lst_id, &lst);
    783777        if (rc != EOK) {
    784                 async_answer_0(icall_handle, ENOENT);
     778                async_answer_0(icall, ENOENT);
    785779                return;
    786780        }
     
    788782        rc = tcp_conn_new(tcp, conn_id, lst->cb, lst->cb_arg, &conn);
    789783        if (rc != EOK) {
    790                 async_answer_0(icall_handle, ENOMEM);
     784                async_answer_0(icall, ENOMEM);
    791785                return;
    792786        }
     
    795789                cinfo = calloc(1, sizeof(tcp_in_conn_t));
    796790                if (cinfo == NULL) {
    797                         async_answer_0(icall_handle, ENOMEM);
     791                        async_answer_0(icall, ENOMEM);
    798792                        return;
    799793                }
     
    804798                fid = fibril_create(tcp_conn_fibril, cinfo);
    805799                if (fid == 0) {
    806                         async_answer_0(icall_handle, ENOMEM);
     800                        async_answer_0(icall, ENOMEM);
    807801                }
    808802
     
    810804        }
    811805
    812         async_answer_0(icall_handle, EOK);
     806        async_answer_0(icall, EOK);
    813807}
    814808
    815809/** Callback connection handler.
    816810 *
    817  * @param icall_handle  Connect call handle
    818  * @param icall         Connect call data
    819  * @param arg           Argument, TCP client
    820  */
    821 static void
    822 tcp_cb_conn(cap_call_handle_t icall_handle, ipc_call_t *icall, void *arg)
     811 * @param icall Connect call data
     812 * @param arg   Argument, TCP client
     813 *
     814 */
     815static void tcp_cb_conn(ipc_call_t *icall, void *arg)
    823816{
    824817        tcp_t *tcp = (tcp_t *)arg;
    825818
    826         async_answer_0(icall_handle, EOK);
     819        async_answer_0(icall, EOK);
    827820
    828821        while (true) {
    829822                ipc_call_t call;
    830                 cap_call_handle_t chandle = async_get_call(&call);
     823                async_get_call(&call);
    831824
    832825                if (!IPC_GET_IMETHOD(call)) {
     
    837830                switch (IPC_GET_IMETHOD(call)) {
    838831                case TCP_EV_CONNECTED:
    839                         tcp_ev_connected(tcp, chandle, &call);
     832                        tcp_ev_connected(tcp, &call);
    840833                        break;
    841834                case TCP_EV_CONN_FAILED:
    842                         tcp_ev_conn_failed(tcp, chandle, &call);
     835                        tcp_ev_conn_failed(tcp, &call);
    843836                        break;
    844837                case TCP_EV_CONN_RESET:
    845                         tcp_ev_conn_reset(tcp, chandle, &call);
     838                        tcp_ev_conn_reset(tcp, &call);
    846839                        break;
    847840                case TCP_EV_DATA:
    848                         tcp_ev_data(tcp, chandle, &call);
     841                        tcp_ev_data(tcp, &call);
    849842                        break;
    850843                case TCP_EV_URG_DATA:
    851                         tcp_ev_urg_data(tcp, chandle, &call);
     844                        tcp_ev_urg_data(tcp, &call);
    852845                        break;
    853846                case TCP_EV_NEW_CONN:
    854                         tcp_ev_new_conn(tcp, chandle, &call);
     847                        tcp_ev_new_conn(tcp, &call);
    855848                        break;
    856849                default:
    857                         async_answer_0(chandle, ENOTSUP);
     850                        async_answer_0(&call, ENOTSUP);
    858851                        break;
    859852                }
    860853        }
     854
    861855out:
    862856        fibril_mutex_lock(&tcp->lock);
Note: See TracChangeset for help on using the changeset viewer.