Changeset 71b00dcc in mainline for uspace/srv/net/modules.c
- Timestamp:
- 2010-03-07T22:51:38Z (15 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 60ab6c3
- Parents:
- b5cbff4 (diff), 31c80a5 (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. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/net/modules.c
rb5cbff4 r71b00dcc 48 48 /** The time between connect requests in microseconds. 49 49 */ 50 #define MODULE_WAIT_TIME ( 10 * 1000)50 #define MODULE_WAIT_TIME (10 * 1000) 51 51 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 ){ 52 void answer_call(ipc_callid_t callid, int result, ipc_call_t * answer, int answer_count){ 53 if(answer || (! answer_count)){ 54 switch(answer_count){ 98 55 case 0: 99 ipc_answer_0( callid, ( ipcarg_t ) result);56 ipc_answer_0(callid, (ipcarg_t) result); 100 57 break; 101 58 case 1: 102 ipc_answer_1( callid, ( ipcarg_t ) result, IPC_GET_ARG1( * answer));59 ipc_answer_1(callid, (ipcarg_t) result, IPC_GET_ARG1(*answer)); 103 60 break; 104 61 case 2: 105 ipc_answer_2( callid, ( ipcarg_t ) result, IPC_GET_ARG1( * answer ), IPC_GET_ARG2( * answer));62 ipc_answer_2(callid, (ipcarg_t) result, IPC_GET_ARG1(*answer), IPC_GET_ARG2(*answer)); 106 63 break; 107 64 case 3: 108 ipc_answer_3( callid, ( ipcarg_t ) result, IPC_GET_ARG1( * answer ), IPC_GET_ARG2( * answer ), IPC_GET_ARG3( * answer));65 ipc_answer_3(callid, (ipcarg_t) result, IPC_GET_ARG1(*answer), IPC_GET_ARG2(*answer), IPC_GET_ARG3(*answer)); 109 66 break; 110 67 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));68 ipc_answer_4(callid, (ipcarg_t) result, IPC_GET_ARG1(*answer), IPC_GET_ARG2(*answer), IPC_GET_ARG3(*answer), IPC_GET_ARG4(*answer)); 112 69 break; 113 70 case 5: 114 71 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));72 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)); 116 73 break; 117 74 } … … 119 76 } 120 77 121 void refresh_answer( ipc_call_t * answer, int * answer_count ){ 122 if( answer_count ){ 123 * answer_count = 0; 78 int bind_service(services_t need, ipcarg_t arg1, ipcarg_t arg2, ipcarg_t arg3, async_client_conn_t client_receiver){ 79 return bind_service_timeout(need, arg1, arg2, arg3, client_receiver, 0); 80 } 81 82 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){ 83 ERROR_DECLARE; 84 85 int phone; 86 ipcarg_t phonehash; 87 88 phone = connect_to_service_timeout(need, timeout); 89 if(phone >= 0){ 90 if(ERROR_OCCURRED(ipc_connect_to_me(phone, arg1, arg2, arg3, &phonehash))){ 91 ipc_hangup(phone); 92 return ERROR_CODE; 93 } 94 async_new_connection(phonehash, 0, NULL, client_receiver); 124 95 } 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 ); 96 return phone; 97 } 98 99 int connect_to_service(services_t need){ 100 return connect_to_service_timeout(need, 0); 101 } 102 103 int connect_to_service_timeout(services_t need, suseconds_t timeout){ 104 if (timeout <= 0) 105 return async_connect_me_to_blocking(PHONE_NS, need, 0, 0); 106 107 while(true){ 108 int phone; 109 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; 115 if(timeout <= 0){ 116 return ETIMEOUT; 117 } 118 119 usleep(MODULE_WAIT_TIME); 134 120 } 135 121 } 136 122 137 int data_receive( void ** data, size_t * length){123 int data_receive(void ** data, size_t * length){ 138 124 ERROR_DECLARE; 139 125 140 ipc_callid_t 126 ipc_callid_t callid; 141 127 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 ); 128 if(!(data && length)){ 129 return EBADMEM; 130 } 131 if(! async_data_write_receive(&callid, length)){ 132 return EINVAL; 133 } 134 *data = malloc(*length); 135 if(!(*data)){ 136 return ENOMEM; 137 } 138 if(ERROR_OCCURRED(async_data_write_finalize(callid, * data, * length))){ 139 free(data); 148 140 return ERROR_CODE; 149 141 } … … 151 143 } 152 144 153 int data_reply( void * data, size_t data_length){154 size_t 155 ipc_callid_t 145 int data_reply(void * data, size_t data_length){ 146 size_t length; 147 ipc_callid_t callid; 156 148 157 if( ! async_data_read_receive( & callid, & length)){149 if(! async_data_read_receive(&callid, &length)){ 158 150 return EINVAL; 159 151 } 160 if( length < data_length){161 async_data_read_finalize( callid, data, length);152 if(length < data_length){ 153 async_data_read_finalize(callid, data, length); 162 154 return EOVERFLOW; 163 155 } 164 return async_data_read_finalize( callid, data, data_length ); 156 return async_data_read_finalize(callid, data, data_length); 157 } 158 159 void refresh_answer(ipc_call_t * answer, int * answer_count){ 160 if(answer_count){ 161 *answer_count = 0; 162 } 163 if(answer){ 164 IPC_SET_RETVAL(*answer, 0); 165 // just to be precize 166 IPC_SET_METHOD(*answer, 0); 167 IPC_SET_ARG1(*answer, 0); 168 IPC_SET_ARG2(*answer, 0); 169 IPC_SET_ARG3(*answer, 0); 170 IPC_SET_ARG4(*answer, 0); 171 IPC_SET_ARG5(*answer, 0); 172 } 165 173 } 166 174
Note:
See TracChangeset
for help on using the changeset viewer.