Changeset a64c64d in mainline for uspace/srv/net/modules.c


Ignore:
Timestamp:
2010-03-09T22:24:31Z (14 years ago)
Author:
Lukas Mejdrech <lukasmejdrech@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
74520daf
Parents:
9f2ea28
Message:
  • code reorganization (no functional change)
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/net/modules.c

    r9f2ea28 ra64c64d  
    5151
    5252void answer_call(ipc_callid_t callid, int result, ipc_call_t * answer, int answer_count){
     53        // choose the most efficient answer function
    5354        if(answer || (! answer_count)){
    5455                switch(answer_count){
     
    8687        ipcarg_t phonehash;
    8788
     89        // connect to the needed service
    8890        phone = connect_to_service_timeout(need, timeout);
     91        // if connected
    8992        if(phone >= 0){
     93                // request the bidirectional connection
    9094                if(ERROR_OCCURRED(ipc_connect_to_me(phone, arg1, arg2, arg3, &phonehash))){
    9195                        ipc_hangup(phone);
     
    102106
    103107int connect_to_service_timeout(services_t need, suseconds_t timeout){
    104         if (timeout <= 0)
     108        int phone;
     109
     110        // if no timeout is set
     111        if (timeout <= 0){
    105112                return async_connect_me_to_blocking(PHONE_NS, need, 0, 0);
    106        
     113        }
     114
    107115        while(true){
    108                 int phone;
     116                phone = async_connect_me_to(PHONE_NS, need, 0, 0);
     117                if((phone >= 0) || (phone != ENOENT)){
     118                        return phone;
     119                }
    109120
    110                 phone = async_connect_me_to(PHONE_NS, need, 0, 0);
    111                 if((phone >= 0) || (phone != ENOENT))
    112                         return phone;
    113        
    114                 timeout -= MODULE_WAIT_TIME;
     121                // end if no time is left
    115122                if(timeout <= 0){
    116123                        return ETIMEOUT;
    117124                }
    118125
    119                 usleep(MODULE_WAIT_TIME);
     126                // wait the minimum of the module wait time and the timeout
     127                usleep((timeout <= MODULE_WAIT_TIME) ? timeout : MODULE_WAIT_TIME);
     128                timeout -= MODULE_WAIT_TIME;
    120129        }
    121130}
     
    129138                return EBADMEM;
    130139        }
     140
     141        // fetch the request
    131142        if(! async_data_write_receive(&callid, length)){
    132143                return EINVAL;
    133144        }
     145
     146        // allocate the buffer
    134147        *data = malloc(*length);
    135148        if(!(*data)){
    136149                return ENOMEM;
    137150        }
     151
     152        // fetch the data
    138153        if(ERROR_OCCURRED(async_data_write_finalize(callid, * data, * length))){
    139154                free(data);
     
    147162        ipc_callid_t callid;
    148163
     164        // fetch the request
    149165        if(! async_data_read_receive(&callid, &length)){
    150166                return EINVAL;
    151167        }
     168
     169        // check the requested data size
    152170        if(length < data_length){
    153171                async_data_read_finalize(callid, data, length);
    154172                return EOVERFLOW;
    155173        }
     174
     175        // send the data
    156176        return async_data_read_finalize(callid, data, data_length);
    157177}
    158178
    159179void refresh_answer(ipc_call_t * answer, int * answer_count){
     180
    160181        if(answer_count){
    161182                *answer_count = 0;
    162183        }
     184
    163185        if(answer){
    164186                IPC_SET_RETVAL(*answer, 0);
Note: See TracChangeset for help on using the changeset viewer.