Ignore:
File:
1 edited

Legend:

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

    rbf172825 r79ae36dd  
    114114    async_client_conn_t client_receiver)
    115115{
     116        return bind_service_timeout(need, arg1, arg2, arg3, client_receiver, 0);
     117}
     118
     119/** Create bidirectional connection with the needed module service and registers
     120 * the message receiver.
     121 *
     122 * @param[in] need      The needed module service.
     123 * @param[in] arg1      The first parameter.
     124 * @param[in] arg2      The second parameter.
     125 * @param[in] arg3      The third parameter.
     126 * @param[in] client_receiver The message receiver.
     127 * @param[in] timeout   The connection timeout in microseconds. No timeout if
     128 *                      set to zero (0).
     129 *
     130 * @return              The phone of the needed service.
     131 * @return              ETIMEOUT if the connection timeouted.
     132 * @return              Other error codes as defined for the ipc_connect_to_me()
     133 *                      function.
     134 *
     135 */
     136int bind_service_timeout(services_t need, sysarg_t arg1, sysarg_t arg2,
     137    sysarg_t arg3, async_client_conn_t client_receiver, suseconds_t timeout)
     138{
    116139        /* Connect to the needed service */
    117         int phone = connect_to_service(need);
     140        int phone = connect_to_service_timeout(need, timeout);
    118141        if (phone >= 0) {
    119142                /* Request the bidirectional connection */
    120                 int rc = async_obsolete_connect_to_me(phone, arg1, arg2, arg3,
    121                     client_receiver, NULL);
     143                int rc = async_obsolete_connect_to_me(phone, arg1, arg2, arg3, client_receiver);
    122144                if (rc != EOK) {
    123145                        async_obsolete_hangup(phone);
     
    136158int connect_to_service(services_t need)
    137159{
    138         return service_obsolete_connect_blocking(need, 0, 0);
     160        return connect_to_service_timeout(need, 0);
     161}
     162
     163/** Connects to the needed module.
     164 *
     165 *  @param[in] need     The needed module service.
     166 *  @param[in] timeout  The connection timeout in microseconds. No timeout if
     167 *                      set to zero (0).
     168 *  @return             The phone of the needed service.
     169 *  @return             ETIMEOUT if the connection timeouted.
     170 */
     171int connect_to_service_timeout(services_t need, suseconds_t timeout)
     172{
     173        int phone;
     174
     175        /* If no timeout is set */
     176        if (timeout <= 0)
     177                return service_obsolete_connect_blocking(need, 0, 0);
     178       
     179        while (true) {
     180                phone = service_obsolete_connect(need, 0, 0);
     181                if ((phone >= 0) || (phone != ENOENT))
     182                        return phone;
     183
     184                /* Abort if no time is left */
     185                if (timeout <= 0)
     186                        return ETIMEOUT;
     187
     188                /* Wait the minimum of the module wait time and the timeout */
     189                usleep((timeout <= MODULE_WAIT_TIME) ?
     190                    timeout : MODULE_WAIT_TIME);
     191                timeout -= MODULE_WAIT_TIME;
     192        }
    139193}
    140194
Note: See TracChangeset for help on using the changeset viewer.