Changeset 16d748ee in mainline


Ignore:
Timestamp:
2020-01-05T03:04:38Z (4 years ago)
Author:
Matthieu Riolo <matthieu.riolo@…>
Children:
66b1075
Parents:
2f04bdd
git-author:
Matthieu Riolo <matthieu.riolo@…> (2019-11-30 20:47:26)
git-committer:
Matthieu Riolo <matthieu.riolo@…> (2020-01-05 03:04:38)
Message:

Removing implicit handler from async/server and taskman.
Correcting taskman methods and it's fallback handler
Simplifying connecting to taskman

Location:
uspace
Files:
5 edited

Legend:

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

    r2f04bdd r16d748ee  
    857857        if (sess == NULL) {
    858858                ipc_hangup(phone);
    859         }else {
     859        } else {
    860860                sess->iface = iface;
    861861        }
     
    915915        if (sess == NULL) {
    916916                ipc_hangup(phone);
    917         }else {
     917        } else {
    918918                sess->iface = iface;
    919919        }
  • uspace/lib/c/generic/async/server.c

    r2f04bdd r16d748ee  
    216216}
    217217
    218 static async_port_handler_t implicit_connection = NULL;
    219 
    220 /** Setter for implicit_connection function pointer.
    221  *
    222  * @param conn Function that will implement a new connection fibril for
    223  *             unrouted calls.
    224  *
    225  */
    226 void async_set_implicit_connection(async_port_handler_t conn)
    227 {
    228         assert(implicit_connection == NULL);
    229         implicit_connection = conn;
    230 }
    231 
    232218static fibril_rmutex_t client_mutex;
    233219static hash_table_t client_hash_table;
     
    407393 *                    either a callback connection that was opened by
    408394 *                    accepting the IPC_M_CONNECT_TO_ME call.
    409  *                    Alternatively, it is zero when we are opening
    410  *                    implicit connection.
    411395 * @param handler     Connection handler.
    412396 * @param data        Client argument to pass to the connection handler.
     
    979963        /* Route the call according to its request label */
    980964        errno_t rc = route_call(call);
    981         if (rc == EOK) {
     965        if (rc == EOK)
    982966                return;
    983         } else if (implicit_connection != NULL) {
    984                 connection_t *conn = calloc(1, sizeof(connection_t));
    985                 if (!conn) {
    986                         ipc_answer_0(call->cap_handle, ENOMEM);
    987                         return;
    988                 }
    989 
    990                 async_new_connection(conn, call->task_id, call, implicit_connection, NULL);
    991                 return;
    992         }
    993967
    994968        // TODO: Log the error.
    995 
    996969        if (call->cap_handle != CAP_NIL)
    997970                /* Unknown call from unknown phone - hang it up */
  • uspace/lib/c/generic/taskman.c

    r2f04bdd r16d748ee  
    6969        async_exchange_end(exch);
    7070}
    71 #include <stdio.h>
     71
    7272/** Wrap PHONE_INITIAL with session and introduce to taskman
    7373 */
     
    8585                /* Introduce ourselves and ignore answer */
    8686                async_exch_t *exch = async_exchange_begin(sess);
    87                 aid_t req = async_send_0(exch, TASKMAN_NEW_TASK, NULL);
     87                sess = async_connect_me_to(exch, INTERFACE_ANY,
     88                    TASKMAN_NEW_TASK, 0);
    8889                async_exchange_end(exch);
    89 
    90                 if (req) {
    91                         async_forget(req);
    92                 }
    9390        }
    9491
  • uspace/lib/c/include/ipc/taskman.h

    r2f04bdd r16d748ee  
    4343        TASKMAN_EVENT_CALLBACK,
    4444        TASKMAN_NEW_TASK,
    45         TASKMAN_I_AM_NS
     45        TASKMAN_I_AM_NS,
     46
     47        TASKMAN_CONNECT_TO_NS,
     48        TASKMAN_CONNECT_TO_LOADER,
     49        TASKMAN_LOADER_CALLBACK
    4650} taskman_request_t;
    4751
     
    5054} taskman_event_t;
    5155
    52 typedef enum {
    53         TASKMAN_CONNECT_TO_NS = 0,
    54         TASKMAN_CONNECT_TO_LOADER,
    55         TASKMAN_LOADER_CALLBACK
    56 } taskman_connect_t;
    57 
    5856#endif
    5957
  • uspace/srv/taskman/main.c

    r2f04bdd r16d748ee  
    3636 * @{
    3737 */
    38 
     38#include <abi/ipc/methods.h>
    3939#include <adt/prodcons.h>
    4040#include <assert.h>
     
    124124        async_exchange_end(exch);
    125125
    126         if (rc != EOK) {
    127                 async_answer_0(icall, rc);
    128                 return;
    129         }
     126        if (rc != EOK)
     127                async_answer_0(icall, rc);
    130128}
    131129
     
    133131{
    134132        errno_t rc = task_intro(icall->task_id);
    135         async_answer_0(icall, rc);
     133        if (rc == EOK) {
     134                async_accept_0(icall);
     135        } else {
     136                async_answer_0(icall, rc);
     137        }
    136138}
    137139
     
    158160finish:
    159161        fibril_mutex_unlock(&session_ns_mtx);
    160         async_answer_0(icall, rc);
     162
     163        if (rc == EOK) {
     164                async_accept_0(icall);
     165        } else {
     166                async_answer_0(icall, rc);
     167        }
    161168}
    162169
     
    240247}
    241248
    242 static bool handle_call(ipc_call_t *icall)
    243 {
    244         switch (ipc_get_imethod(icall)) {
    245         case TASKMAN_NEW_TASK:
    246                 taskman_new_task(icall);
    247                 break;
    248         case TASKMAN_I_AM_NS:
    249                 taskman_i_am_ns(icall);
    250                 break;
    251         case TASKMAN_WAIT:
    252                 taskman_ctl_wait(icall);
    253                 break;
    254         case TASKMAN_RETVAL:
    255                 taskman_ctl_retval(icall);
    256                 break;
    257         case TASKMAN_EVENT_CALLBACK:
    258                 taskman_ctl_ev_callback(icall);
    259                 break;
    260         default:
    261                 return false;
    262         }
    263         return true;
    264 }
    265 
    266 static bool handle_implicit_call(ipc_call_t *icall)
    267 {
    268         if (ipc_get_imethod(icall) < IPC_FIRST_USER_METHOD) {
    269                 switch (ipc_get_arg1(icall)) {
     249static void taskman_connection(ipc_call_t *icall, void *arg)
     250{
     251        /* handle new incoming calls */
     252        if (ipc_get_imethod(icall) == IPC_M_CONNECT_ME_TO) {
     253                switch (ipc_get_arg2(icall)) {
     254                case TASKMAN_NEW_TASK:
     255                        taskman_new_task(icall);
     256                        break;
    270257                case TASKMAN_CONNECT_TO_NS:
    271258                        connect_to_ns(icall);
    272                         break;
     259                        return;
    273260                case TASKMAN_CONNECT_TO_LOADER:
    274261                        connect_to_loader(icall);
    275                         break;
     262                        return;
     263                default:
     264                        async_answer_0(icall, ENOTSUP);
     265                        return;
     266                }
     267        } else if (ipc_get_imethod(icall) == IPC_M_CONNECT_TO_ME) {
     268                switch (ipc_get_arg2(icall)) {
    276269                case TASKMAN_LOADER_CALLBACK:
    277270                        loader_callback(icall);
    278                         break;
     271                        return;
    279272                default:
    280                         return false;
    281 
     273                        async_answer_0(icall, ENOTSUP);
     274                        return;
    282275                }
    283         } else {
    284                 return handle_call(icall);
    285         }
    286 
    287         return true;
    288 }
    289 
    290 static void implicit_connection(ipc_call_t *icall, void *arg)
    291 {
    292         if (!handle_implicit_call(icall)) {
    293                 async_answer_0(icall, ENOTSUP);
    294                 return;
    295         }
    296 
     276        }
     277
     278        /* handle accepted calls */
    297279        while (true) {
    298280                ipc_call_t call;
    299281
    300                 if (!async_get_call(&call) || !ipc_get_imethod(&call)) {
     282                if (!async_get_call(&call)) {
    301283                        /* Client disconnected */
    302                         break;
     284                        return;
    303285                }
    304286
    305                 if (!handle_implicit_call(&call)) {
    306                         async_answer_0(icall, ENOTSUP);
    307                         break;
     287                switch (ipc_get_imethod(&call)) {
     288                case TASKMAN_I_AM_NS:
     289                        taskman_i_am_ns(&call);
     290                        break;
     291                case TASKMAN_WAIT:
     292                        taskman_ctl_wait(&call);
     293                        break;
     294                case TASKMAN_RETVAL:
     295                        taskman_ctl_retval(&call);
     296                        break;
     297                case TASKMAN_EVENT_CALLBACK:
     298                        taskman_ctl_ev_callback(&call);
     299                        break;
     300                default:
     301                        async_answer_0(&call, ENOTSUP);
    308302                }
    309         }
    310 }
    311 
    312 static void taskman_connection(ipc_call_t *icall, void *arg)
    313 {
    314         /*
    315          * We don't expect (yet) clients to connect, having this function is
    316          * just to adapt to async framework that creates new connection for
    317          * each IPC_M_CONNECT_ME_TO.
    318          * In this case those are to be forwarded, so don't continue
    319          * "listening" on such connections.
    320          */
    321         if (!handle_implicit_call(icall)) {
    322                 /* If cannot handle connection request, give up trying */
    323                 async_answer_0(icall, EHANGUP);
    324                 return;
    325303        }
    326304}
     
    360338
    361339        /* Start sysman server */
    362         async_set_implicit_connection(implicit_connection);
    363340        async_set_fallback_port_handler(taskman_connection, NULL);
    364341
Note: See TracChangeset for help on using the changeset viewer.