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


Ignore:
Timestamp:
2010-03-13T12:17:02Z (14 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
6ba20a6b
Parents:
d0febca (diff), 2070570 (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/srv/net/modules.c

    rd0febca r7715994  
    4848/** The time between connect requests in microseconds.
    4949 */
    50 #define MODULE_WAIT_TIME        ( 10 * 1000 )
     50#define MODULE_WAIT_TIME        (10 * 1000)
    5151
    52 int connect_to_service( services_t need ){
    53         return connect_to_service_timeout( need, 0 );
    54 }
    55 
    56 int connect_to_service_timeout( services_t need, suseconds_t timeout ){
    57         if (timeout <= 0)
    58                 return async_connect_me_to_blocking( PHONE_NS, need, 0, 0);
    59        
    60         while( true ){
    61                 int phone;
    62 
    63                 phone = async_connect_me_to( PHONE_NS, need, 0, 0);
    64                 if( (phone >= 0) || (phone != ENOENT) )
    65                         return phone;
    66        
    67                 timeout -= MODULE_WAIT_TIME;
    68                 if( timeout <= 0 ) return ETIMEOUT;
    69 
    70                 usleep( MODULE_WAIT_TIME );
    71         }
    72 }
    73 
    74 int bind_service( services_t need, ipcarg_t arg1, ipcarg_t arg2, ipcarg_t arg3, async_client_conn_t client_receiver ){
    75         return bind_service_timeout( need, arg1, arg2, arg3, client_receiver, 0 );
    76 }
    77 
    78 int bind_service_timeout( services_t need, ipcarg_t arg1, ipcarg_t arg2, ipcarg_t arg3, async_client_conn_t client_receiver, suseconds_t timeout ){
    79         ERROR_DECLARE;
    80 
    81         int                     phone;
    82         ipcarg_t        phonehash;
    83 
    84         phone = connect_to_service_timeout( need, timeout );
    85         if( phone >= 0 ){
    86                 if( ERROR_OCCURRED( ipc_connect_to_me( phone, arg1, arg2, arg3, & phonehash ))){
    87                         ipc_hangup( phone );
    88                         return ERROR_CODE;
    89                 }
    90                 async_new_connection( phonehash, 0, NULL, client_receiver );
    91         }
    92         return phone;
    93 }
    94 
    95 void answer_call( ipc_callid_t callid, int result, ipc_call_t * answer, int answer_count ){
    96         if( answer || ( ! answer_count )){
    97                 switch( answer_count ){
     52void answer_call(ipc_callid_t callid, int result, ipc_call_t * answer, int answer_count){
     53        // choose the most efficient answer function
     54        if(answer || (! answer_count)){
     55                switch(answer_count){
    9856                        case 0:
    99                                 ipc_answer_0( callid, ( ipcarg_t ) result );
     57                                ipc_answer_0(callid, (ipcarg_t) result);
    10058                                break;
    10159                        case 1:
    102                                 ipc_answer_1( callid, ( ipcarg_t ) result, IPC_GET_ARG1( * answer ));
     60                                ipc_answer_1(callid, (ipcarg_t) result, IPC_GET_ARG1(*answer));
    10361                                break;
    10462                        case 2:
    105                                 ipc_answer_2( callid, ( ipcarg_t ) result, IPC_GET_ARG1( * answer ), IPC_GET_ARG2( * answer ));
     63                                ipc_answer_2(callid, (ipcarg_t) result, IPC_GET_ARG1(*answer), IPC_GET_ARG2(*answer));
    10664                                break;
    10765                        case 3:
    108                                 ipc_answer_3( callid, ( ipcarg_t ) result, IPC_GET_ARG1( * answer ), IPC_GET_ARG2( * answer ), IPC_GET_ARG3( * answer ));
     66                                ipc_answer_3(callid, (ipcarg_t) result, IPC_GET_ARG1(*answer), IPC_GET_ARG2(*answer), IPC_GET_ARG3(*answer));
    10967                                break;
    11068                        case 4:
    111                                 ipc_answer_4( callid, ( ipcarg_t ) result, IPC_GET_ARG1( * answer ), IPC_GET_ARG2( * answer ), IPC_GET_ARG3( * answer ), IPC_GET_ARG4( * answer ));
     69                                ipc_answer_4(callid, (ipcarg_t) result, IPC_GET_ARG1(*answer), IPC_GET_ARG2(*answer), IPC_GET_ARG3(*answer), IPC_GET_ARG4(*answer));
    11270                                break;
    11371                        case 5:
    11472                        default:
    115                                 ipc_answer_5( callid, ( ipcarg_t ) result, IPC_GET_ARG1( * answer ), IPC_GET_ARG2( * answer ), IPC_GET_ARG3( * answer ), IPC_GET_ARG4( * answer ), IPC_GET_ARG5( * answer ));
     73                                ipc_answer_5(callid, (ipcarg_t) result, IPC_GET_ARG1(*answer), IPC_GET_ARG2(*answer), IPC_GET_ARG3(*answer), IPC_GET_ARG4(*answer), IPC_GET_ARG5(*answer));
    11674                                break;
    11775                }
     
    11977}
    12078
    121 void refresh_answer( ipc_call_t * answer, int * answer_count ){
    122         if( answer_count ){
    123                 * answer_count = 0;
     79int bind_service(services_t need, ipcarg_t arg1, ipcarg_t arg2, ipcarg_t arg3, async_client_conn_t client_receiver){
     80        return bind_service_timeout(need, arg1, arg2, arg3, client_receiver, 0);
     81}
     82
     83int bind_service_timeout(services_t need, ipcarg_t arg1, ipcarg_t arg2, ipcarg_t arg3, async_client_conn_t client_receiver, suseconds_t timeout){
     84        ERROR_DECLARE;
     85
     86        int phone;
     87        ipcarg_t phonehash;
     88
     89        // connect to the needed service
     90        phone = connect_to_service_timeout(need, timeout);
     91        // if connected
     92        if(phone >= 0){
     93                // request the bidirectional connection
     94                if(ERROR_OCCURRED(ipc_connect_to_me(phone, arg1, arg2, arg3, &phonehash))){
     95                        ipc_hangup(phone);
     96                        return ERROR_CODE;
     97                }
     98                async_new_connection(phonehash, 0, NULL, client_receiver);
    12499        }
    125         if( answer ){
    126                 IPC_SET_RETVAL( * answer, 0 );
    127                 // just to be precize
    128                 IPC_SET_METHOD( * answer, 0 );
    129                 IPC_SET_ARG1( * answer, 0 );
    130                 IPC_SET_ARG2( * answer, 0 );
    131                 IPC_SET_ARG3( * answer, 0 );
    132                 IPC_SET_ARG4( * answer, 0 );
    133                 IPC_SET_ARG5( * answer, 0 );
     100        return phone;
     101}
     102
     103int connect_to_service(services_t need){
     104        return connect_to_service_timeout(need, 0);
     105}
     106
     107int connect_to_service_timeout(services_t need, suseconds_t timeout){
     108        int phone;
     109
     110        // if no timeout is set
     111        if (timeout <= 0){
     112                return async_connect_me_to_blocking(PHONE_NS, need, 0, 0);
     113        }
     114
     115        while(true){
     116                phone = async_connect_me_to(PHONE_NS, need, 0, 0);
     117                if((phone >= 0) || (phone != ENOENT)){
     118                        return phone;
     119                }
     120
     121                // end if no time is left
     122                if(timeout <= 0){
     123                        return ETIMEOUT;
     124                }
     125
     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;
    134129        }
    135130}
    136131
    137 int data_receive( void ** data, size_t * length ){
     132int data_receive(void ** data, size_t * length){
    138133        ERROR_DECLARE;
    139134
    140         ipc_callid_t    callid;
     135        ipc_callid_t callid;
    141136
    142         if( !( data && length )) return EBADMEM;
    143         if( ! async_data_write_receive( & callid, length )) return EINVAL;
    144         * data = malloc( * length );
    145         if( !( * data )) return ENOMEM;
    146         if( ERROR_OCCURRED( async_data_write_finalize( callid, * data, * length ))){
    147                 free( data );
     137        if(!(data && length)){
     138                return EBADMEM;
     139        }
     140
     141        // fetch the request
     142        if(! async_data_write_receive(&callid, length)){
     143                return EINVAL;
     144        }
     145
     146        // allocate the buffer
     147        *data = malloc(*length);
     148        if(!(*data)){
     149                return ENOMEM;
     150        }
     151
     152        // fetch the data
     153        if(ERROR_OCCURRED(async_data_write_finalize(callid, * data, * length))){
     154                free(data);
    148155                return ERROR_CODE;
    149156        }
     
    151158}
    152159
    153 int data_reply( void * data, size_t data_length ){
    154         size_t                  length;
    155         ipc_callid_t    callid;
     160int data_reply(void * data, size_t data_length){
     161        size_t length;
     162        ipc_callid_t callid;
    156163
    157         if( ! async_data_read_receive( & callid, & length )){
     164        // fetch the request
     165        if(! async_data_read_receive(&callid, &length)){
    158166                return EINVAL;
    159167        }
    160         if( length < data_length ){
    161                 async_data_read_finalize( callid, data, length );
     168
     169        // check the requested data size
     170        if(length < data_length){
     171                async_data_read_finalize(callid, data, length);
    162172                return EOVERFLOW;
    163173        }
    164         return async_data_read_finalize( callid, data, data_length );
     174
     175        // send the data
     176        return async_data_read_finalize(callid, data, data_length);
     177}
     178
     179void refresh_answer(ipc_call_t * answer, int * answer_count){
     180
     181        if(answer_count){
     182                *answer_count = 0;
     183        }
     184
     185        if(answer){
     186                IPC_SET_RETVAL(*answer, 0);
     187                // just to be precize
     188                IPC_SET_METHOD(*answer, 0);
     189                IPC_SET_ARG1(*answer, 0);
     190                IPC_SET_ARG2(*answer, 0);
     191                IPC_SET_ARG3(*answer, 0);
     192                IPC_SET_ARG4(*answer, 0);
     193                IPC_SET_ARG5(*answer, 0);
     194        }
    165195}
    166196
Note: See TracChangeset for help on using the changeset viewer.