Changes in uspace/srv/net/modules.c [aadf01e:bc9da2a] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/net/modules.c
raadf01e rbc9da2a 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 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){ 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 ){ 55 98 case 0: 56 ipc_answer_0( callid, (ipcarg_t) result);99 ipc_answer_0( callid, ( ipcarg_t ) result ); 57 100 break; 58 101 case 1: 59 ipc_answer_1( callid, (ipcarg_t) result, IPC_GET_ARG1(*answer));102 ipc_answer_1( callid, ( ipcarg_t ) result, IPC_GET_ARG1( * answer )); 60 103 break; 61 104 case 2: 62 ipc_answer_2( callid, (ipcarg_t) result, IPC_GET_ARG1(*answer), IPC_GET_ARG2(*answer));105 ipc_answer_2( callid, ( ipcarg_t ) result, IPC_GET_ARG1( * answer ), IPC_GET_ARG2( * answer )); 63 106 break; 64 107 case 3: 65 ipc_answer_3( callid, (ipcarg_t) result, IPC_GET_ARG1(*answer), IPC_GET_ARG2(*answer), IPC_GET_ARG3(*answer));108 ipc_answer_3( callid, ( ipcarg_t ) result, IPC_GET_ARG1( * answer ), IPC_GET_ARG2( * answer ), IPC_GET_ARG3( * answer )); 66 109 break; 67 110 case 4: 68 ipc_answer_4( callid, (ipcarg_t) result, IPC_GET_ARG1(*answer), IPC_GET_ARG2(*answer), IPC_GET_ARG3(*answer), IPC_GET_ARG4(*answer));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 112 break; 70 113 case 5: 71 114 default: 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));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 116 break; 74 117 } … … 76 119 } 77 120 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); 121 void refresh_answer( ipc_call_t * answer, int * answer_count ){ 122 if( answer_count ){ 123 * answer_count = 0; 95 124 } 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); 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 ); 120 134 } 121 135 } 122 136 123 int data_receive( void ** data, size_t * length){137 int data_receive( void ** data, size_t * length ){ 124 138 ERROR_DECLARE; 125 139 126 ipc_callid_t 140 ipc_callid_t callid; 127 141 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); 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 ); 140 148 return ERROR_CODE; 141 149 } … … 143 151 } 144 152 145 int data_reply( void * data, size_t data_length){146 size_t 147 ipc_callid_t 153 int data_reply( void * data, size_t data_length ){ 154 size_t length; 155 ipc_callid_t callid; 148 156 149 if( ! async_data_read_receive(&callid, &length)){157 if( ! async_data_read_receive( & callid, & length )){ 150 158 return EINVAL; 151 159 } 152 if( length < data_length){153 async_data_read_finalize( callid, data, length);160 if( length < data_length ){ 161 async_data_read_finalize( callid, data, length ); 154 162 return EOVERFLOW; 155 163 } 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 } 164 return async_data_read_finalize( callid, data, data_length ); 173 165 } 174 166
Note:
See TracChangeset
for help on using the changeset viewer.