Changeset 6a44ee4 in mainline for uspace/lib/c/generic/net/modules.c


Ignore:
Timestamp:
2011-07-20T15:26:21Z (13 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
efcebe1
Parents:
25bef0ff (diff), a701812 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge mainline changes.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/generic/net/modules.c

    r25bef0ff r6a44ee4  
    4545#include <ipc/services.h>
    4646#include <net/modules.h>
    47 
    48 /** The time between connect requests in microseconds. */
    49 #define MODULE_WAIT_TIME        (10 * 1000)
     47#include <ns.h>
    5048
    5149/** Answer a call.
     
    9593}
    9694
    97 /** Create bidirectional connection with the needed module service and registers
     95/** Create bidirectional connection with the needed module service and register
    9896 * the message receiver.
    9997 *
    100  * @param[in] need      The needed module service.
    101  * @param[in] arg1      The first parameter.
    102  * @param[in] arg2      The second parameter.
    103  * @param[in] arg3      The third parameter.
    104  * @param[in] client_receiver The message receiver.
    105  *
    106  * @return              The phone of the needed service.
    107  * @return              Other error codes as defined for the ipc_connect_to_me()
    108  *                      function.
    109  */
    110 int bind_service(services_t need, sysarg_t arg1, sysarg_t arg2, sysarg_t arg3,
    111     async_client_conn_t client_receiver)
    112 {
    113         return bind_service_timeout(need, arg1, arg2, arg3, client_receiver, 0);
    114 }
    115 
    116 /** Create bidirectional connection with the needed module service and registers
    117  * the message receiver.
    118  *
    119  * @param[in] need      The needed module service.
    120  * @param[in] arg1      The first parameter.
    121  * @param[in] arg2      The second parameter.
    122  * @param[in] arg3      The third parameter.
    123  * @param[in] client_receiver The message receiver.
    124  * @param[in] timeout   The connection timeout in microseconds. No timeout if
    125  *                      set to zero (0).
    126  *
    127  * @return              The phone of the needed service.
    128  * @return              ETIMEOUT if the connection timeouted.
    129  * @return              Other error codes as defined for the ipc_connect_to_me()
    130  *                      function.
    131  *
    132  */
    133 int bind_service_timeout(services_t need, sysarg_t arg1, sysarg_t arg2,
    134     sysarg_t arg3, async_client_conn_t client_receiver, suseconds_t timeout)
     98 * @param[in] need            Needed module service.
     99 * @param[in] arg1            First parameter.
     100 * @param[in] arg2            Second parameter.
     101 * @param[in] arg3            Third parameter.
     102 * @param[in] client_receiver Message receiver.
     103 *
     104 * @return Session to the needed service.
     105 * @return Other error codes as defined for the async_connect_to_me()
     106 *         function.
     107 *
     108 */
     109async_sess_t *bind_service(services_t need, sysarg_t arg1, sysarg_t arg2,
     110    sysarg_t arg3, async_client_conn_t client_receiver)
    135111{
    136112        /* Connect to the needed service */
    137         int phone = connect_to_service_timeout(need, timeout);
    138         if (phone >= 0) {
     113        async_sess_t *sess = connect_to_service(need);
     114        if (sess != NULL) {
    139115                /* Request the bidirectional connection */
    140                 int rc = async_connect_to_me(phone, arg1, arg2, arg3, client_receiver);
     116                async_exch_t *exch = async_exchange_begin(sess);
     117                int rc = async_connect_to_me(exch, arg1, arg2, arg3,
     118                    client_receiver, NULL);
     119                async_exchange_end(exch);
     120               
    141121                if (rc != EOK) {
    142                         async_hangup(phone);
    143                         return rc;
     122                        async_hangup(sess);
     123                        errno = rc;
     124                        return NULL;
    144125                }
    145126        }
    146127       
    147         return phone;
    148 }
    149 
    150 /** Connects to the needed module.
    151  *
    152  * @param[in] need      The needed module service.
    153  * @return              The phone of the needed service.
    154  */
    155 int connect_to_service(services_t need)
    156 {
    157         return connect_to_service_timeout(need, 0);
    158 }
    159 
    160 /** Connects to the needed module.
    161  *
    162  *  @param[in] need     The needed module service.
    163  *  @param[in] timeout  The connection timeout in microseconds. No timeout if
    164  *                      set to zero (0).
    165  *  @return             The phone of the needed service.
    166  *  @return             ETIMEOUT if the connection timeouted.
    167  */
    168 int connect_to_service_timeout(services_t need, suseconds_t timeout)
    169 {
    170         int phone;
    171 
    172         /* If no timeout is set */
    173         if (timeout <= 0)
    174                 return async_connect_me_to_blocking(PHONE_NS, need, 0, 0);
    175 
    176         while (true) {
    177                 phone = async_connect_me_to(PHONE_NS, need, 0, 0);
    178                 if ((phone >= 0) || (phone != ENOENT))
    179                         return phone;
    180 
    181                 /* Abort if no time is left */
    182                 if (timeout <= 0)
    183                         return ETIMEOUT;
    184 
    185                 /* Wait the minimum of the module wait time and the timeout */
    186                 usleep((timeout <= MODULE_WAIT_TIME) ?
    187                     timeout : MODULE_WAIT_TIME);
    188                 timeout -= MODULE_WAIT_TIME;
    189         }
    190 }
    191 
    192 /** Replies the data to the other party.
    193  *
    194  * @param[in] data      The data buffer to be sent.
     128        return sess;
     129}
     130
     131/** Connect to the needed module.
     132 *
     133 * @param[in] need Needed module service.
     134 *
     135 * @return Session to the needed service.
     136 * @return NULL if the connection timeouted.
     137 *
     138 */
     139async_sess_t *connect_to_service(services_t need)
     140{
     141        return service_connect_blocking(EXCHANGE_SERIALIZE, need, 0, 0);
     142}
     143
     144/** Reply the data to the other party.
     145 *
     146 * @param[in] data        The data buffer to be sent.
    195147 * @param[in] data_length The buffer length.
    196  * @return              EOK on success.
    197  * @return              EINVAL if the client does not expect the data.
    198  * @return              EOVERFLOW if the client does not expect all the data.
    199  *                      Only partial data are transfered.
    200  * @return              Other error codes as defined for the
    201  *                      async_data_read_finalize() function.
     148 *
     149 * @return EOK on success.
     150 * @return EINVAL if the client does not expect the data.
     151 * @return EOVERFLOW if the client does not expect all the data.
     152 *         Only partial data are transfered.
     153 * @return Other error codes as defined for the
     154 *         async_data_read_finalize() function.
     155 *
    202156 */
    203157int data_reply(void *data, size_t data_length)
     
    205159        size_t length;
    206160        ipc_callid_t callid;
    207 
     161       
    208162        /* Fetch the request */
    209163        if (!async_data_read_receive(&callid, &length))
    210164                return EINVAL;
    211 
     165       
    212166        /* Check the requested data size */
    213167        if (length < data_length) {
     
    215169                return EOVERFLOW;
    216170        }
    217 
     171       
    218172        /* Send the data */
    219173        return async_data_read_finalize(callid, data, data_length);
Note: See TracChangeset for help on using the changeset viewer.