Changes in uspace/srv/net/socket/socket_client.c [aadf01e:8ab2074] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/net/socket/socket_client.c
raadf01e r8ab2074 75 75 /** Default timeout for connections in microseconds. 76 76 */ 77 #define SOCKET_CONNECT_TIMEOUT ( 1 * 1000 * 1000)77 #define SOCKET_CONNECT_TIMEOUT ( 1 * 1000 * 1000 ) 78 78 79 79 /** Maximum number of random attempts to find a new socket identifier before switching to the sequence. … … 97 97 /** Socket identifier. 98 98 */ 99 int 99 int socket_id; 100 100 /** Parent module phone. 101 101 */ 102 int 102 int phone; 103 103 /** Parent module service. 104 104 */ 105 services_t 105 services_t service; 106 106 /** Underlying protocol header size. 107 107 * Sending and receiving optimalization. 108 108 */ 109 size_t 109 size_t header_size; 110 110 /** Packet data fragment size. 111 111 * Sending optimalization. 112 112 */ 113 size_t 113 size_t data_fragment_size; 114 114 /** Sending safety lock. 115 115 * Locks the header_size and data_fragment_size attributes. 116 116 */ 117 fibril_rwlock_t 117 fibril_rwlock_t sending_lock; 118 118 /** Received packets queue. 119 119 */ 120 dyn_fifo_t 120 dyn_fifo_t received; 121 121 /** Received packets safety lock. 122 122 * Used for receiving and receive notifications. 123 123 * Locks the received attribute. 124 124 */ 125 fibril_mutex_t 125 fibril_mutex_t receive_lock; 126 126 /** Received packets signaling. 127 127 * Signaled upon receive notification. 128 128 */ 129 fibril_condvar_t 129 fibril_condvar_t receive_signal; 130 130 /** Waiting sockets queue. 131 131 */ 132 dyn_fifo_t 132 dyn_fifo_t accepted; 133 133 /** Waiting sockets safety lock. 134 134 * Used for accepting and accept notifications. 135 135 * Locks the accepted attribute. 136 136 */ 137 fibril_mutex_t 137 fibril_mutex_t accept_lock; 138 138 /** Waiting sockets signaling. 139 139 * Signaled upon accept notification. 140 140 */ 141 fibril_condvar_t 141 fibril_condvar_t accept_signal; 142 142 /** The number of blocked functions called. 143 143 * Used while waiting for the received packets or accepted sockets. 144 144 */ 145 int 145 int blocked; 146 146 }; 147 147 … … 150 150 * @see int_map.h 151 151 */ 152 INT_MAP_DECLARE( sockets, socket_t);152 INT_MAP_DECLARE( sockets, socket_t ); 153 153 154 154 /** Socket client library global data. … … 157 157 /** TCP module phone. 158 158 */ 159 int 159 int tcp_phone; 160 160 /** UDP module phone. 161 161 */ 162 int 162 int udp_phone; 163 163 // /** The last socket identifier. 164 164 // */ … … 166 166 /** Active sockets. 167 167 */ 168 sockets_ref 168 sockets_ref sockets; 169 169 /** Safety lock. 170 170 * Write lock is used only for adding or removing sockets. … … 173 173 * No socket lock may be locked if this lock is unlocked. 174 174 */ 175 fibril_rwlock_t 175 fibril_rwlock_t lock; 176 176 } socket_globals = { 177 177 .tcp_phone = -1, … … 183 183 .writers = 0, 184 184 .waiters = { 185 .prev = & socket_globals.lock.waiters,186 .next = & socket_globals.lock.waiters185 .prev = & socket_globals.lock.waiters, 186 .next = & socket_globals.lock.waiters 187 187 } 188 188 } 189 189 }; 190 190 191 INT_MAP_IMPLEMENT( sockets, socket_t);191 INT_MAP_IMPLEMENT( sockets, socket_t ); 192 192 193 193 /** Returns the TCP module phone. … … 196 196 * @returns Other error codes as defined for the bind_service_timeout() function. 197 197 */ 198 static int socket_get_tcp_phone(void);198 static int socket_get_tcp_phone( void ); 199 199 200 200 /** Returns the UDP module phone. … … 203 203 * @returns Other error codes as defined for the bind_service_timeout() function. 204 204 */ 205 static int socket_get_udp_phone(void);205 static int socket_get_udp_phone( void ); 206 206 207 207 /** Returns the active sockets. 208 208 * @returns The active sockets. 209 209 */ 210 static sockets_ref socket_get_sockets(void);210 static sockets_ref socket_get_sockets( void ); 211 211 212 212 /** Tries to find a new free socket identifier. … … 214 214 * @returns ELIMIT if there is no socket identifier available. 215 215 */ 216 static int socket_generate_new_id(void);216 static int socket_generate_new_id( void ); 217 217 218 218 /** Default thread for new connections. … … 220 220 * @param[in] icall The initial message call structure. 221 221 */ 222 void socket_connection(ipc_callid_t iid, ipc_call_t * icall);222 void socket_connection( ipc_callid_t iid, ipc_call_t * icall ); 223 223 224 224 /** Sends message to the socket parent module with specified data. … … 234 234 * @returns Other error codes as defined for the spcific message. 235 235 */ 236 int socket_send_data(int socket_id, ipcarg_t message, ipcarg_t arg2, const void * data, size_t datalength);236 int socket_send_data( int socket_id, ipcarg_t message, ipcarg_t arg2, const void * data, size_t datalength ); 237 237 238 238 /** Initializes a new socket specific data. … … 242 242 * @param[in] service The parent module service. 243 243 */ 244 void socket_initialize(socket_ref socket, int socket_id, int phone, services_t service);244 void socket_initialize( socket_ref socket, int socket_id, int phone, services_t service ); 245 245 246 246 /** Clears and destroys the socket. 247 247 * @param[in] socket The socket to be destroyed. 248 248 */ 249 void socket_destroy(socket_ref socket);249 void socket_destroy( socket_ref socket ); 250 250 251 251 /** Receives data via the socket. … … 263 263 * @returns Other error codes as defined for the spcific message. 264 264 */ 265 int recvfrom_core(ipcarg_t message, int socket_id, void * data, size_t datalength, int flags, struct sockaddr * fromaddr, socklen_t * addrlen);265 int recvfrom_core( ipcarg_t message, int socket_id, void * data, size_t datalength, int flags, struct sockaddr * fromaddr, socklen_t * addrlen ); 266 266 267 267 /** Sends data via the socket to the remote address. … … 280 280 * @returns Other error codes as defined for the NET_SOCKET_SENDTO message. 281 281 */ 282 int sendto_core(ipcarg_t message, int socket_id, const void * data, size_t datalength, int flags, const struct sockaddr * toaddr, socklen_t addrlen);283 284 static int socket_get_tcp_phone( void){285 if( socket_globals.tcp_phone < 0){286 socket_globals.tcp_phone = bind_service_timeout( SERVICE_TCP, 0, 0, SERVICE_TCP, socket_connection, SOCKET_CONNECT_TIMEOUT);282 int sendto_core( ipcarg_t message, int socket_id, const void * data, size_t datalength, int flags, const struct sockaddr * toaddr, socklen_t addrlen ); 283 284 static int socket_get_tcp_phone( void ){ 285 if( socket_globals.tcp_phone < 0 ){ 286 socket_globals.tcp_phone = bind_service_timeout( SERVICE_TCP, 0, 0, SERVICE_TCP, socket_connection, SOCKET_CONNECT_TIMEOUT ); 287 287 } 288 288 return socket_globals.tcp_phone; 289 289 } 290 290 291 static int socket_get_udp_phone( void){292 if( socket_globals.udp_phone < 0){293 socket_globals.udp_phone = bind_service_timeout( SERVICE_UDP, 0, 0, SERVICE_UDP, socket_connection, SOCKET_CONNECT_TIMEOUT);291 static int socket_get_udp_phone( void ){ 292 if( socket_globals.udp_phone < 0 ){ 293 socket_globals.udp_phone = bind_service_timeout( SERVICE_UDP, 0, 0, SERVICE_UDP, socket_connection, SOCKET_CONNECT_TIMEOUT ); 294 294 } 295 295 return socket_globals.udp_phone; 296 296 } 297 297 298 static sockets_ref socket_get_sockets(void){ 299 if(! socket_globals.sockets){ 300 socket_globals.sockets = (sockets_ref) malloc(sizeof(sockets_t)); 301 if(! socket_globals.sockets){ 302 return NULL; 303 } 304 if(sockets_initialize(socket_globals.sockets) != EOK){ 305 free(socket_globals.sockets); 298 static sockets_ref socket_get_sockets( void ){ 299 if( ! socket_globals.sockets ){ 300 socket_globals.sockets = ( sockets_ref ) malloc( sizeof( sockets_t )); 301 if( ! socket_globals.sockets ) return NULL; 302 if( sockets_initialize( socket_globals.sockets ) != EOK ){ 303 free( socket_globals.sockets ); 306 304 socket_globals.sockets = NULL; 307 305 } 308 srand( task_get_id());306 srand( task_get_id()); 309 307 } 310 308 return socket_globals.sockets; 311 309 } 312 310 313 static int socket_generate_new_id( void){314 sockets_ref 315 int 316 int 311 static int socket_generate_new_id( void ){ 312 sockets_ref sockets; 313 int socket_id; 314 int count; 317 315 318 316 sockets = socket_get_sockets(); … … 320 318 // socket_id = socket_globals.last_id; 321 319 do{ 322 if( count < SOCKET_ID_TRIES){320 if( count < SOCKET_ID_TRIES ){ 323 321 socket_id = rand() % INT_MAX; 324 322 ++ count; 325 }else if( count == SOCKET_ID_TRIES){323 }else if( count == SOCKET_ID_TRIES ){ 326 324 socket_id = 1; 327 325 ++ count; 328 326 // only this branch for last_id 329 327 }else{ 330 if( socket_id < INT_MAX){328 if( socket_id < INT_MAX ){ 331 329 ++ socket_id; 332 /* }else if( socket_globals.last_id){330 /* }else if( socket_globals.last_id ){ 333 331 * socket_globals.last_id = 0; 334 332 * socket_id = 1; … … 337 335 } 338 336 } 339 }while( sockets_find(sockets, socket_id));337 }while( sockets_find( sockets, socket_id )); 340 338 // last_id = socket_id 341 339 return socket_id; 342 340 } 343 341 344 void socket_initialize( socket_ref socket, int socket_id, int phone, services_t service){342 void socket_initialize( socket_ref socket, int socket_id, int phone, services_t service ){ 345 343 socket->socket_id = socket_id; 346 344 socket->phone = phone; 347 345 socket->service = service; 348 dyn_fifo_initialize( &socket->received, SOCKET_INITIAL_RECEIVED_SIZE);349 dyn_fifo_initialize( &socket->accepted, SOCKET_INITIAL_ACCEPTED_SIZE);350 fibril_mutex_initialize( &socket->receive_lock);351 fibril_condvar_initialize( &socket->receive_signal);352 fibril_mutex_initialize( &socket->accept_lock);353 fibril_condvar_initialize( &socket->accept_signal);354 fibril_rwlock_initialize( &socket->sending_lock);355 } 356 357 void socket_connection( ipc_callid_t iid, ipc_call_t * icall){346 dyn_fifo_initialize( & socket->received, SOCKET_INITIAL_RECEIVED_SIZE ); 347 dyn_fifo_initialize( & socket->accepted, SOCKET_INITIAL_ACCEPTED_SIZE ); 348 fibril_mutex_initialize( & socket->receive_lock ); 349 fibril_condvar_initialize( & socket->receive_signal ); 350 fibril_mutex_initialize( & socket->accept_lock ); 351 fibril_condvar_initialize( & socket->accept_signal ); 352 fibril_rwlock_initialize( & socket->sending_lock ); 353 } 354 355 void socket_connection( ipc_callid_t iid, ipc_call_t * icall ){ 358 356 ERROR_DECLARE; 359 357 360 ipc_callid_t 361 ipc_call_t 362 socket_ref 363 364 while( true){365 366 callid = async_get_call( &call);367 switch( IPC_GET_METHOD(call)){358 ipc_callid_t callid; 359 ipc_call_t call; 360 socket_ref socket; 361 362 while( true ){ 363 364 callid = async_get_call( & call ); 365 switch( IPC_GET_METHOD( call )){ 368 366 case NET_SOCKET_RECEIVED: 369 367 case NET_SOCKET_ACCEPTED: 370 368 case NET_SOCKET_DATA_FRAGMENT_SIZE: 371 fibril_rwlock_read_lock( &socket_globals.lock);369 fibril_rwlock_read_lock( & socket_globals.lock ); 372 370 // find the socket 373 socket = sockets_find( socket_get_sockets(), SOCKET_GET_SOCKET_ID(call));374 if( ! socket){371 socket = sockets_find( socket_get_sockets(), SOCKET_GET_SOCKET_ID( call )); 372 if( ! socket ){ 375 373 ERROR_CODE = ENOTSOCK; 376 374 }else{ 377 switch( IPC_GET_METHOD(call)){375 switch( IPC_GET_METHOD( call )){ 378 376 case NET_SOCKET_RECEIVED: 379 fibril_mutex_lock( &socket->receive_lock);377 fibril_mutex_lock( & socket->receive_lock ); 380 378 // push the number of received packet fragments 381 if( ! ERROR_OCCURRED(dyn_fifo_push(&socket->received, SOCKET_GET_DATA_FRAGMENTS(call), SOCKET_MAX_RECEIVED_SIZE))){379 if( ! ERROR_OCCURRED( dyn_fifo_push( & socket->received, SOCKET_GET_DATA_FRAGMENTS( call ), SOCKET_MAX_RECEIVED_SIZE ))){ 382 380 // signal the received packet 383 fibril_condvar_signal( &socket->receive_signal);381 fibril_condvar_signal( & socket->receive_signal ); 384 382 } 385 fibril_mutex_unlock( &socket->receive_lock);383 fibril_mutex_unlock( & socket->receive_lock ); 386 384 break; 387 385 case NET_SOCKET_ACCEPTED: 388 386 // push the new socket identifier 389 fibril_mutex_lock( &socket->accept_lock);390 if( ! ERROR_OCCURRED(dyn_fifo_push(&socket->accepted, 1, SOCKET_MAX_ACCEPTED_SIZE))){387 fibril_mutex_lock( & socket->accept_lock ); 388 if( ! ERROR_OCCURRED( dyn_fifo_push( & socket->accepted, 1, SOCKET_MAX_ACCEPTED_SIZE ))){ 391 389 // signal the accepted socket 392 fibril_condvar_signal( &socket->accept_signal);390 fibril_condvar_signal( & socket->accept_signal ); 393 391 } 394 fibril_mutex_unlock( &socket->accept_lock);392 fibril_mutex_unlock( & socket->accept_lock ); 395 393 break; 396 394 default: 397 395 ERROR_CODE = ENOTSUP; 398 396 } 399 if(( SOCKET_GET_DATA_FRAGMENT_SIZE(call) > 0)400 && (SOCKET_GET_DATA_FRAGMENT_SIZE(call) != socket->data_fragment_size)){401 fibril_rwlock_write_lock( &socket->sending_lock);397 if(( SOCKET_GET_DATA_FRAGMENT_SIZE( call ) > 0 ) 398 && ( SOCKET_GET_DATA_FRAGMENT_SIZE( call ) != socket->data_fragment_size )){ 399 fibril_rwlock_write_lock( & socket->sending_lock ); 402 400 // set the data fragment size 403 socket->data_fragment_size = SOCKET_GET_DATA_FRAGMENT_SIZE( call);404 fibril_rwlock_write_unlock( &socket->sending_lock);401 socket->data_fragment_size = SOCKET_GET_DATA_FRAGMENT_SIZE( call ); 402 fibril_rwlock_write_unlock( & socket->sending_lock ); 405 403 } 406 404 } 407 fibril_rwlock_read_unlock( &socket_globals.lock);405 fibril_rwlock_read_unlock( & socket_globals.lock ); 408 406 break; 409 407 default: 410 408 ERROR_CODE = ENOTSUP; 411 409 } 412 ipc_answer_0( callid, (ipcarg_t) ERROR_CODE);413 } 414 } 415 416 int socket( int domain, int type, int protocol){410 ipc_answer_0( callid, ( ipcarg_t ) ERROR_CODE ); 411 } 412 } 413 414 int socket( int domain, int type, int protocol ){ 417 415 ERROR_DECLARE; 418 416 419 socket_ref 420 int 421 int 422 services_t 417 socket_ref socket; 418 int phone; 419 int socket_id; 420 services_t service; 423 421 424 422 // find the appropriate service 425 switch( domain){423 switch( domain ){ 426 424 case PF_INET: 427 switch( type){425 switch( type ){ 428 426 case SOCK_STREAM: 429 if(! protocol){ 430 protocol = IPPROTO_TCP; 431 } 432 switch(protocol){ 427 if( ! protocol ) protocol = IPPROTO_TCP; 428 switch( protocol ){ 433 429 case IPPROTO_TCP: 434 430 phone = socket_get_tcp_phone(); … … 440 436 break; 441 437 case SOCK_DGRAM: 442 if(! protocol){ 443 protocol = IPPROTO_UDP; 444 } 445 switch(protocol){ 438 if( ! protocol ) protocol = IPPROTO_UDP; 439 switch( protocol ){ 446 440 case IPPROTO_UDP: 447 441 phone = socket_get_udp_phone(); … … 461 455 return EPFNOSUPPORT; 462 456 } 463 if(phone < 0){ 464 return phone; 465 } 457 if( phone < 0 ) return phone; 466 458 // create a new socket structure 467 socket = (socket_ref) malloc(sizeof(socket_t)); 468 if(! socket){ 469 return ENOMEM; 470 } 471 bzero(socket, sizeof(*socket)); 472 fibril_rwlock_write_lock(&socket_globals.lock); 459 socket = ( socket_ref ) malloc( sizeof( socket_t )); 460 if( ! socket ) return ENOMEM; 461 bzero( socket, sizeof( * socket )); 462 fibril_rwlock_write_lock( & socket_globals.lock ); 473 463 // request a new socket 474 464 socket_id = socket_generate_new_id(); 475 if( socket_id <= 0){476 fibril_rwlock_write_unlock( &socket_globals.lock);477 free( socket);465 if( socket_id <= 0 ){ 466 fibril_rwlock_write_unlock( & socket_globals.lock ); 467 free( socket ); 478 468 return socket_id; 479 469 } 480 if( ERROR_OCCURRED((int) async_req_3_3(phone, NET_SOCKET, socket_id, 0, service, NULL, (ipcarg_t *) &socket->data_fragment_size, (ipcarg_t *) &socket->header_size))){481 fibril_rwlock_write_unlock( &socket_globals.lock);482 free( socket);470 if( ERROR_OCCURRED(( int ) async_req_3_3( phone, NET_SOCKET, socket_id, 0, service, NULL, ( ipcarg_t * ) & socket->data_fragment_size, ( ipcarg_t * ) & socket->header_size ))){ 471 fibril_rwlock_write_unlock( & socket_globals.lock ); 472 free( socket ); 483 473 return ERROR_CODE; 484 474 } 485 475 // finish the new socket initialization 486 socket_initialize( socket, socket_id, phone, service);476 socket_initialize( socket, socket_id, phone, service ); 487 477 // store the new socket 488 ERROR_CODE = sockets_add( socket_get_sockets(), socket_id, socket);489 fibril_rwlock_write_unlock( &socket_globals.lock);490 if( ERROR_CODE < 0){491 dyn_fifo_destroy( &socket->received);492 dyn_fifo_destroy( &socket->accepted);493 free( socket);494 async_msg_3( phone, NET_SOCKET_CLOSE, (ipcarg_t) socket_id, 0, service);478 ERROR_CODE = sockets_add( socket_get_sockets(), socket_id, socket ); 479 fibril_rwlock_write_unlock( & socket_globals.lock ); 480 if( ERROR_CODE < 0 ){ 481 dyn_fifo_destroy( & socket->received ); 482 dyn_fifo_destroy( & socket->accepted ); 483 free( socket ); 484 async_msg_3( phone, NET_SOCKET_CLOSE, ( ipcarg_t ) socket_id, 0, service ); 495 485 return ERROR_CODE; 496 486 } … … 499 489 } 500 490 501 int socket_send_data(int socket_id, ipcarg_t message, ipcarg_t arg2, const void * data, size_t datalength){ 502 socket_ref socket; 503 aid_t message_id; 504 ipcarg_t result; 505 506 if(! data){ 507 return EBADMEM; 508 } 509 if(! datalength){ 510 return NO_DATA; 511 } 512 513 fibril_rwlock_read_lock(&socket_globals.lock); 491 int socket_send_data( int socket_id, ipcarg_t message, ipcarg_t arg2, const void * data, size_t datalength ){ 492 socket_ref socket; 493 aid_t message_id; 494 ipcarg_t result; 495 496 if( ! data ) return EBADMEM; 497 if( ! datalength ) return NO_DATA; 498 499 fibril_rwlock_read_lock( & socket_globals.lock ); 514 500 // find the socket 515 socket = sockets_find( socket_get_sockets(), socket_id);516 if( ! socket){517 fibril_rwlock_read_unlock( &socket_globals.lock);501 socket = sockets_find( socket_get_sockets(), socket_id ); 502 if( ! socket ){ 503 fibril_rwlock_read_unlock( & socket_globals.lock ); 518 504 return ENOTSOCK; 519 505 } 520 506 // request the message 521 message_id = async_send_3( socket->phone, message, (ipcarg_t) socket->socket_id, arg2, socket->service, NULL);507 message_id = async_send_3( socket->phone, message, ( ipcarg_t ) socket->socket_id, arg2, socket->service, NULL ); 522 508 // send the address 523 async_data_write_start(socket->phone, data, datalength); 524 fibril_rwlock_read_unlock(&socket_globals.lock); 525 async_wait_for(message_id, &result); 526 return (int) result; 527 } 528 529 int bind(int socket_id, const struct sockaddr * my_addr, socklen_t addrlen){ 530 if(addrlen <= 0){ 531 return EINVAL; 532 } 509 async_data_write_start( socket->phone, data, datalength ); 510 fibril_rwlock_read_unlock( & socket_globals.lock ); 511 async_wait_for( message_id, & result ); 512 return ( int ) result; 513 } 514 515 int bind( int socket_id, const struct sockaddr * my_addr, socklen_t addrlen ){ 516 if( addrlen <= 0 ) return EINVAL; 533 517 // send the address 534 return socket_send_data(socket_id, NET_SOCKET_BIND, 0, my_addr, (size_t) addrlen); 535 } 536 537 int listen(int socket_id, int backlog){ 538 socket_ref socket; 539 int result; 540 541 if(backlog <= 0){ 542 return EINVAL; 543 } 544 fibril_rwlock_read_lock(&socket_globals.lock); 518 return socket_send_data( socket_id, NET_SOCKET_BIND, 0, my_addr, ( size_t ) addrlen ); 519 } 520 521 int listen( int socket_id, int backlog ){ 522 socket_ref socket; 523 int result; 524 525 if( backlog <= 0 ) return EINVAL; 526 fibril_rwlock_read_lock( & socket_globals.lock ); 545 527 // find the socket 546 socket = sockets_find( socket_get_sockets(), socket_id);547 if( ! socket){548 fibril_rwlock_read_unlock( &socket_globals.lock);528 socket = sockets_find( socket_get_sockets(), socket_id ); 529 if( ! socket ){ 530 fibril_rwlock_read_unlock( & socket_globals.lock ); 549 531 return ENOTSOCK; 550 532 } 551 533 // request listen backlog change 552 result = ( int) async_req_3_0(socket->phone, NET_SOCKET_LISTEN, (ipcarg_t) socket->socket_id, (ipcarg_t) backlog, socket->service);553 fibril_rwlock_read_unlock( &socket_globals.lock);534 result = ( int ) async_req_3_0( socket->phone, NET_SOCKET_LISTEN, ( ipcarg_t ) socket->socket_id, ( ipcarg_t ) backlog, socket->service ); 535 fibril_rwlock_read_unlock( & socket_globals.lock ); 554 536 return result; 555 537 } 556 538 557 int accept(int socket_id, struct sockaddr * cliaddr, socklen_t * addrlen){ 558 socket_ref socket; 559 socket_ref new_socket; 560 aid_t message_id; 561 ipcarg_t ipc_result; 562 int result; 563 ipc_call_t answer; 564 565 if((! cliaddr) || (! addrlen)){ 566 return EBADMEM; 567 } 568 569 fibril_rwlock_write_lock(&socket_globals.lock); 539 int accept( int socket_id, struct sockaddr * cliaddr, socklen_t * addrlen ){ 540 socket_ref socket; 541 socket_ref new_socket; 542 aid_t message_id; 543 ipcarg_t ipc_result; 544 int result; 545 ipc_call_t answer; 546 547 if(( ! cliaddr ) || ( ! addrlen )) return EBADMEM; 548 549 fibril_rwlock_write_lock( & socket_globals.lock ); 570 550 // find the socket 571 socket = sockets_find( socket_get_sockets(), socket_id);572 if( ! socket){573 fibril_rwlock_write_unlock( &socket_globals.lock);551 socket = sockets_find( socket_get_sockets(), socket_id ); 552 if( ! socket ){ 553 fibril_rwlock_write_unlock( & socket_globals.lock ); 574 554 return ENOTSOCK; 575 555 } 576 fibril_mutex_lock( &socket->accept_lock);556 fibril_mutex_lock( & socket->accept_lock ); 577 557 // wait for an accepted socket 578 558 ++ socket->blocked; 579 while(dyn_fifo_value(&socket->accepted) <= 0){ 580 fibril_rwlock_write_unlock(&socket_globals.lock); 581 fibril_condvar_wait(&socket->accept_signal, &socket->accept_lock); 582 fibril_rwlock_write_lock(&socket_globals.lock); 559 while( dyn_fifo_value( & socket->accepted ) <= 0 ){ 560 fibril_rwlock_write_unlock( & socket_globals.lock ); 561 fibril_condvar_wait( & socket->accept_signal, & socket->accept_lock ); 562 // drop the accept lock to avoid deadlock 563 fibril_mutex_unlock( & socket->accept_lock ); 564 fibril_rwlock_write_lock( & socket_globals.lock ); 565 fibril_mutex_lock( & socket->accept_lock ); 583 566 } 584 567 -- socket->blocked; 585 568 586 569 // create a new scoket 587 new_socket = ( socket_ref) malloc(sizeof(socket_t));588 if( ! new_socket){589 fibril_mutex_unlock( &socket->accept_lock);590 fibril_rwlock_write_unlock( &socket_globals.lock);570 new_socket = ( socket_ref ) malloc( sizeof( socket_t )); 571 if( ! new_socket ){ 572 fibril_mutex_unlock( & socket->accept_lock ); 573 fibril_rwlock_write_unlock( & socket_globals.lock ); 591 574 return ENOMEM; 592 575 } 593 bzero( new_socket, sizeof(*new_socket));576 bzero( new_socket, sizeof( * new_socket )); 594 577 socket_id = socket_generate_new_id(); 595 if( socket_id <= 0){596 fibril_mutex_unlock( &socket->accept_lock);597 fibril_rwlock_write_unlock( &socket_globals.lock);598 free( new_socket);578 if( socket_id <= 0 ){ 579 fibril_mutex_unlock( & socket->accept_lock ); 580 fibril_rwlock_write_unlock( & socket_globals.lock ); 581 free( new_socket ); 599 582 return socket_id; 600 583 } 601 socket_initialize( new_socket, socket_id, socket->phone, socket->service);602 result = sockets_add( socket_get_sockets(), new_socket->socket_id, new_socket);603 if( result < 0){604 fibril_mutex_unlock( &socket->accept_lock);605 fibril_rwlock_write_unlock( &socket_globals.lock);606 free( new_socket);584 socket_initialize( new_socket, socket_id, socket->phone, socket->service ); 585 result = sockets_add( socket_get_sockets(), new_socket->socket_id, new_socket ); 586 if( result < 0 ){ 587 fibril_mutex_unlock( & socket->accept_lock ); 588 fibril_rwlock_write_unlock( & socket_globals.lock ); 589 free( new_socket ); 607 590 return result; 608 591 } 609 592 610 593 // request accept 611 message_id = async_send_5( socket->phone, NET_SOCKET_ACCEPT, (ipcarg_t) socket->socket_id, 0, socket->service, 0, new_socket->socket_id, &answer);594 message_id = async_send_5( socket->phone, NET_SOCKET_ACCEPT, ( ipcarg_t ) socket->socket_id, 0, socket->service, 0, new_socket->socket_id, & answer ); 612 595 // read address 613 ipc_data_read_start( socket->phone, cliaddr, * addrlen);614 fibril_rwlock_write_unlock( &socket_globals.lock);615 async_wait_for( message_id, &ipc_result);596 ipc_data_read_start( socket->phone, cliaddr, * addrlen ); 597 fibril_rwlock_write_unlock( & socket_globals.lock ); 598 async_wait_for( message_id, & ipc_result ); 616 599 result = (int) ipc_result; 617 if( result > 0){618 if( result != socket_id){600 if( result > 0 ){ 601 if( result != socket_id ){ 619 602 result = EINVAL; 620 603 } 621 604 // dequeue the accepted socket if successful 622 dyn_fifo_pop( &socket->accepted);605 dyn_fifo_pop( & socket->accepted ); 623 606 // set address length 624 * addrlen = SOCKET_GET_ADDRESS_LENGTH(answer);625 new_socket->data_fragment_size = SOCKET_GET_DATA_FRAGMENT_SIZE( answer);626 }else if( result == ENOTSOCK){607 * addrlen = SOCKET_GET_ADDRESS_LENGTH( answer ); 608 new_socket->data_fragment_size = SOCKET_GET_DATA_FRAGMENT_SIZE( answer ); 609 }else if( result == ENOTSOCK ){ 627 610 // empty the queue if no accepted sockets 628 while( dyn_fifo_pop(&socket->accepted) > 0);629 } 630 fibril_mutex_unlock( &socket->accept_lock);611 while( dyn_fifo_pop( & socket->accepted ) > 0 ); 612 } 613 fibril_mutex_unlock( & socket->accept_lock ); 631 614 return result; 632 615 } 633 616 634 int connect(int socket_id, const struct sockaddr * serv_addr, socklen_t addrlen){ 635 if(! serv_addr){ 636 return EDESTADDRREQ; 637 } 638 if(! addrlen){ 639 return EDESTADDRREQ; 640 } 617 int connect( int socket_id, const struct sockaddr * serv_addr, socklen_t addrlen ){ 618 if( ! serv_addr ) return EDESTADDRREQ; 619 if( ! addrlen ) return EDESTADDRREQ; 641 620 // send the address 642 return socket_send_data( socket_id, NET_SOCKET_CONNECT, 0, serv_addr, addrlen);643 } 644 645 int closesocket( int socket_id){621 return socket_send_data( socket_id, NET_SOCKET_CONNECT, 0, serv_addr, addrlen ); 622 } 623 624 int closesocket( int socket_id ){ 646 625 ERROR_DECLARE; 647 626 648 socket_ref 649 650 fibril_rwlock_write_lock( &socket_globals.lock);651 socket = sockets_find( socket_get_sockets(), socket_id);652 if( ! socket){653 fibril_rwlock_write_unlock( &socket_globals.lock);627 socket_ref socket; 628 629 fibril_rwlock_write_lock( & socket_globals.lock ); 630 socket = sockets_find( socket_get_sockets(), socket_id ); 631 if( ! socket ){ 632 fibril_rwlock_write_unlock( & socket_globals.lock ); 654 633 return ENOTSOCK; 655 634 } 656 if( socket->blocked){657 fibril_rwlock_write_unlock( &socket_globals.lock);635 if( socket->blocked ){ 636 fibril_rwlock_write_unlock( & socket_globals.lock ); 658 637 return EINPROGRESS; 659 638 } 660 639 // request close 661 ERROR_PROPAGATE(( int) async_req_3_0(socket->phone, NET_SOCKET_CLOSE, (ipcarg_t) socket->socket_id, 0, socket->service));640 ERROR_PROPAGATE(( int ) async_req_3_0( socket->phone, NET_SOCKET_CLOSE, ( ipcarg_t ) socket->socket_id, 0, socket->service )); 662 641 // free the socket structure 663 socket_destroy( socket);664 fibril_rwlock_write_unlock( &socket_globals.lock);642 socket_destroy( socket ); 643 fibril_rwlock_write_unlock( & socket_globals.lock ); 665 644 return EOK; 666 645 } 667 646 668 void socket_destroy( socket_ref socket){669 int 647 void socket_destroy( socket_ref socket ){ 648 int accepted_id; 670 649 671 650 // destroy all accepted sockets 672 while(( accepted_id = dyn_fifo_pop(&socket->accepted)) >= 0){673 socket_destroy( sockets_find(socket_get_sockets(), accepted_id));674 } 675 dyn_fifo_destroy( &socket->received);676 dyn_fifo_destroy( &socket->accepted);677 sockets_exclude( socket_get_sockets(), socket->socket_id);678 } 679 680 int send( int socket_id, void * data, size_t datalength, int flags){651 while(( accepted_id = dyn_fifo_pop( & socket->accepted )) >= 0 ){ 652 socket_destroy( sockets_find( socket_get_sockets(), accepted_id )); 653 } 654 dyn_fifo_destroy( & socket->received ); 655 dyn_fifo_destroy( & socket->accepted ); 656 sockets_exclude( socket_get_sockets(), socket->socket_id ); 657 } 658 659 int send( int socket_id, void * data, size_t datalength, int flags ){ 681 660 // without the address 682 return sendto_core(NET_SOCKET_SEND, socket_id, data, datalength, flags, NULL, 0); 683 } 684 685 int sendto(int socket_id, const void * data, size_t datalength, int flags, const struct sockaddr * toaddr, socklen_t addrlen){ 686 if(! toaddr){ 687 return EDESTADDRREQ; 688 } 689 if(! addrlen){ 690 return EDESTADDRREQ; 691 } 661 return sendto_core( NET_SOCKET_SEND, socket_id, data, datalength, flags, NULL, 0 ); 662 } 663 664 int sendto( int socket_id, const void * data, size_t datalength, int flags, const struct sockaddr * toaddr, socklen_t addrlen ){ 665 if( ! toaddr ) return EDESTADDRREQ; 666 if( ! addrlen ) return EDESTADDRREQ; 692 667 // with the address 693 return sendto_core(NET_SOCKET_SENDTO, socket_id, data, datalength, flags, toaddr, addrlen); 694 } 695 696 int sendto_core(ipcarg_t message, int socket_id, const void * data, size_t datalength, int flags, const struct sockaddr * toaddr, socklen_t addrlen){ 697 socket_ref socket; 698 aid_t message_id; 699 ipcarg_t result; 700 size_t fragments; 701 ipc_call_t answer; 702 703 if(! data){ 704 return EBADMEM; 705 } 706 if(! datalength){ 707 return NO_DATA; 708 } 709 fibril_rwlock_read_lock(&socket_globals.lock); 668 return sendto_core( NET_SOCKET_SENDTO, socket_id, data, datalength, flags, toaddr, addrlen ); 669 } 670 671 int sendto_core( ipcarg_t message, int socket_id, const void * data, size_t datalength, int flags, const struct sockaddr * toaddr, socklen_t addrlen ){ 672 socket_ref socket; 673 aid_t message_id; 674 ipcarg_t result; 675 size_t fragments; 676 ipc_call_t answer; 677 678 if( ! data ) return EBADMEM; 679 if( ! datalength ) return NO_DATA; 680 fibril_rwlock_read_lock( & socket_globals.lock ); 710 681 // find socket 711 socket = sockets_find( socket_get_sockets(), socket_id);712 if( ! socket){713 fibril_rwlock_read_unlock( &socket_globals.lock);682 socket = sockets_find( socket_get_sockets(), socket_id ); 683 if( ! socket ){ 684 fibril_rwlock_read_unlock( & socket_globals.lock ); 714 685 return ENOTSOCK; 715 686 } 716 fibril_rwlock_read_lock( &socket->sending_lock);687 fibril_rwlock_read_lock( & socket->sending_lock ); 717 688 // compute data fragment count 718 if( socket->data_fragment_size > 0){719 fragments = ( datalength + socket->header_size) / socket->data_fragment_size;720 if(( datalength + socket->header_size) % socket->data_fragment_size) ++ fragments;689 if( socket->data_fragment_size > 0 ){ 690 fragments = ( datalength + socket->header_size ) / socket->data_fragment_size; 691 if(( datalength + socket->header_size ) % socket->data_fragment_size ) ++ fragments; 721 692 }else{ 722 693 fragments = 1; 723 694 } 724 695 // request send 725 message_id = async_send_5( socket->phone, message, (ipcarg_t) socket->socket_id, (fragments == 1 ? datalength : socket->data_fragment_size), socket->service, (ipcarg_t) flags, fragments, &answer);696 message_id = async_send_5( socket->phone, message, ( ipcarg_t ) socket->socket_id, ( fragments == 1 ? datalength : socket->data_fragment_size ), socket->service, ( ipcarg_t ) flags, fragments, & answer ); 726 697 // send the address if given 727 if(( ! toaddr) || (async_data_write_start(socket->phone, toaddr, addrlen) == EOK)){728 if( fragments == 1){698 if(( ! toaddr ) || ( async_data_write_start( socket->phone, toaddr, addrlen ) == EOK )){ 699 if( fragments == 1 ){ 729 700 // send all if only one fragment 730 async_data_write_start( socket->phone, data, datalength);701 async_data_write_start( socket->phone, data, datalength ); 731 702 }else{ 732 703 // send the first fragment 733 async_data_write_start( socket->phone, data, socket->data_fragment_size - socket->header_size);734 data = (( const uint8_t *) data) + socket->data_fragment_size - socket->header_size;704 async_data_write_start( socket->phone, data, socket->data_fragment_size - socket->header_size ); 705 data = (( const uint8_t * ) data ) + socket->data_fragment_size - socket->header_size; 735 706 // send the middle fragments 736 while(( -- fragments) > 1){737 async_data_write_start( socket->phone, data, socket->data_fragment_size);738 data = (( const uint8_t *) data) + socket->data_fragment_size;707 while(( -- fragments ) > 1 ){ 708 async_data_write_start( socket->phone, data, socket->data_fragment_size ); 709 data = (( const uint8_t * ) data ) + socket->data_fragment_size; 739 710 } 740 711 // send the last fragment 741 async_data_write_start( socket->phone, data, (datalength + socket->header_size) % socket->data_fragment_size);712 async_data_write_start( socket->phone, data, ( datalength + socket->header_size ) % socket->data_fragment_size ); 742 713 } 743 714 } 744 async_wait_for( message_id, &result);745 if(( SOCKET_GET_DATA_FRAGMENT_SIZE(answer) > 0)746 && (SOCKET_GET_DATA_FRAGMENT_SIZE(answer) != socket->data_fragment_size)){715 async_wait_for( message_id, & result ); 716 if(( SOCKET_GET_DATA_FRAGMENT_SIZE( answer ) > 0 ) 717 && ( SOCKET_GET_DATA_FRAGMENT_SIZE( answer ) != socket->data_fragment_size )){ 747 718 // set the data fragment size 748 socket->data_fragment_size = SOCKET_GET_DATA_FRAGMENT_SIZE( answer);749 } 750 fibril_rwlock_read_unlock( &socket->sending_lock);751 fibril_rwlock_read_unlock( &socket_globals.lock);752 return ( int) result;753 } 754 755 int recv( int socket_id, void * data, size_t datalength, int flags){719 socket->data_fragment_size = SOCKET_GET_DATA_FRAGMENT_SIZE( answer ); 720 } 721 fibril_rwlock_read_unlock( & socket->sending_lock ); 722 fibril_rwlock_read_unlock( & socket_globals.lock ); 723 return ( int ) result; 724 } 725 726 int recv( int socket_id, void * data, size_t datalength, int flags ){ 756 727 // without the address 757 return recvfrom_core(NET_SOCKET_RECV, socket_id, data, datalength, flags, NULL, NULL); 758 } 759 760 int recvfrom(int socket_id, void * data, size_t datalength, int flags, struct sockaddr * fromaddr, socklen_t * addrlen){ 761 if(! fromaddr){ 762 return EBADMEM; 763 } 764 if(! addrlen){ 765 return NO_DATA; 766 } 728 return recvfrom_core( NET_SOCKET_RECV, socket_id, data, datalength, flags, NULL, NULL ); 729 } 730 731 int recvfrom( int socket_id, void * data, size_t datalength, int flags, struct sockaddr * fromaddr, socklen_t * addrlen ){ 732 if( ! fromaddr ) return EBADMEM; 733 if( ! addrlen ) return NO_DATA; 767 734 // with the address 768 return recvfrom_core(NET_SOCKET_RECVFROM, socket_id, data, datalength, flags, fromaddr, addrlen); 769 } 770 771 int recvfrom_core(ipcarg_t message, int socket_id, void * data, size_t datalength, int flags, struct sockaddr * fromaddr, socklen_t * addrlen){ 772 socket_ref socket; 773 aid_t message_id; 774 ipcarg_t ipc_result; 775 int result; 776 size_t fragments; 777 size_t * lengths; 778 size_t index; 779 ipc_call_t answer; 780 781 if(! data){ 782 return EBADMEM; 783 } 784 if(! datalength){ 785 return NO_DATA; 786 } 787 if(fromaddr && (! addrlen)){ 788 return EINVAL; 789 } 790 fibril_rwlock_read_lock(&socket_globals.lock); 735 return recvfrom_core( NET_SOCKET_RECVFROM, socket_id, data, datalength, flags, fromaddr, addrlen ); 736 } 737 738 int recvfrom_core( ipcarg_t message, int socket_id, void * data, size_t datalength, int flags, struct sockaddr * fromaddr, socklen_t * addrlen ){ 739 socket_ref socket; 740 aid_t message_id; 741 ipcarg_t ipc_result; 742 int result; 743 size_t fragments; 744 size_t * lengths; 745 size_t index; 746 ipc_call_t answer; 747 748 if( ! data ) return EBADMEM; 749 if( ! datalength ) return NO_DATA; 750 if( fromaddr && ( ! addrlen )) return EINVAL; 751 fibril_rwlock_read_lock( & socket_globals.lock ); 791 752 // find the socket 792 socket = sockets_find( socket_get_sockets(), socket_id);793 if( ! socket){794 fibril_rwlock_read_unlock( &socket_globals.lock);753 socket = sockets_find( socket_get_sockets(), socket_id ); 754 if( ! socket ){ 755 fibril_rwlock_read_unlock( & socket_globals.lock ); 795 756 return ENOTSOCK; 796 757 } 797 fibril_mutex_lock( &socket->receive_lock);758 fibril_mutex_lock( & socket->receive_lock ); 798 759 // wait for a received packet 799 760 ++ socket->blocked; 800 while((result = dyn_fifo_value(&socket->received)) <= 0){ 801 fibril_rwlock_read_unlock(&socket_globals.lock); 802 fibril_condvar_wait(&socket->receive_signal, &socket->receive_lock); 803 fibril_rwlock_read_lock(&socket_globals.lock); 761 while(( result = dyn_fifo_value( & socket->received )) <= 0 ){ 762 fibril_rwlock_read_unlock( & socket_globals.lock ); 763 fibril_condvar_wait( & socket->receive_signal, & socket->receive_lock ); 764 // drop the receive lock to avoid deadlock 765 fibril_mutex_unlock( & socket->receive_lock ); 766 fibril_rwlock_read_lock( & socket_globals.lock ); 767 fibril_mutex_lock( & socket->receive_lock ); 804 768 } 805 769 -- socket->blocked; 806 fragments = ( size_t) result;770 fragments = ( size_t ) result; 807 771 // prepare lengths if more fragments 808 if( fragments > 1){809 lengths = ( size_t *) malloc(sizeof(size_t) * fragments + sizeof(size_t));810 if( ! lengths){811 fibril_mutex_unlock( &socket->receive_lock);812 fibril_rwlock_read_unlock( &socket_globals.lock);772 if( fragments > 1 ){ 773 lengths = ( size_t * ) malloc( sizeof( size_t ) * fragments + sizeof( size_t )); 774 if( ! lengths ){ 775 fibril_mutex_unlock( & socket->receive_lock ); 776 fibril_rwlock_read_unlock( & socket_globals.lock ); 813 777 return ENOMEM; 814 778 } 815 779 // request packet data 816 message_id = async_send_4( socket->phone, message, (ipcarg_t) socket->socket_id, 0, socket->service, (ipcarg_t) flags, &answer);780 message_id = async_send_4( socket->phone, message, ( ipcarg_t ) socket->socket_id, 0, socket->service, ( ipcarg_t ) flags, & answer ); 817 781 // read the address if desired 818 if(( ! fromaddr) || (async_data_read_start(socket->phone, fromaddr, * addrlen) == EOK)){782 if(( ! fromaddr ) || ( async_data_read_start( socket->phone, fromaddr, * addrlen ) == EOK )){ 819 783 // read the fragment lengths 820 if( async_data_read_start(socket->phone, lengths, sizeof(int) * (fragments + 1)) == EOK){821 if( lengths[fragments] <= datalength){784 if( async_data_read_start( socket->phone, lengths, sizeof( int ) * ( fragments + 1 )) == EOK ){ 785 if( lengths[ fragments ] <= datalength ){ 822 786 // read all fragments if long enough 823 for( index = 0; index < fragments; ++ index){824 async_data_read_start( socket->phone, data, lengths[index]);825 data = (( uint8_t *) data) + lengths[index];787 for( index = 0; index < fragments; ++ index ){ 788 async_data_read_start( socket->phone, data, lengths[ index ] ); 789 data = (( uint8_t * ) data ) + lengths[ index ]; 826 790 } 827 791 } 828 792 } 829 793 } 830 free( lengths);794 free( lengths ); 831 795 }else{ 832 796 // request packet data 833 message_id = async_send_4( socket->phone, message, (ipcarg_t) socket->socket_id, 0, socket->service, (ipcarg_t) flags, &answer);797 message_id = async_send_4( socket->phone, message, ( ipcarg_t ) socket->socket_id, 0, socket->service, ( ipcarg_t ) flags, & answer ); 834 798 // read the address if desired 835 if(( ! fromaddr) || (async_data_read_start(socket->phone, fromaddr, * addrlen) == EOK)){799 if(( ! fromaddr ) || ( async_data_read_start( socket->phone, fromaddr, * addrlen ) == EOK )){ 836 800 // read all if only one fragment 837 async_data_read_start( socket->phone, data, datalength);801 async_data_read_start( socket->phone, data, datalength ); 838 802 } 839 803 } 840 async_wait_for( message_id, &ipc_result);804 async_wait_for( message_id, & ipc_result ); 841 805 result = (int) ipc_result; 842 806 // if successful 843 if( result == EOK){807 if( result == EOK ){ 844 808 // dequeue the received packet 845 dyn_fifo_pop( &socket->received);809 dyn_fifo_pop( & socket->received ); 846 810 // return read data length 847 result = SOCKET_GET_READ_DATA_LENGTH( answer);811 result = SOCKET_GET_READ_DATA_LENGTH( answer ); 848 812 // set address length 849 if(fromaddr && addrlen){ 850 *addrlen = SOCKET_GET_ADDRESS_LENGTH(answer); 851 } 852 } 853 fibril_mutex_unlock(&socket->receive_lock); 854 fibril_rwlock_read_unlock(&socket_globals.lock); 813 if( fromaddr && addrlen ) * addrlen = SOCKET_GET_ADDRESS_LENGTH( answer ); 814 } 815 fibril_mutex_unlock( & socket->receive_lock ); 816 fibril_rwlock_read_unlock( & socket_globals.lock ); 855 817 return result; 856 818 } 857 819 858 int getsockopt(int socket_id, int level, int optname, void * value, size_t * optlen){ 859 socket_ref socket; 860 aid_t message_id; 861 ipcarg_t result; 862 863 if(!(value && optlen)){ 864 return EBADMEM; 865 } 866 if(!(*optlen)){ 867 return NO_DATA; 868 } 869 fibril_rwlock_read_lock(&socket_globals.lock); 820 int getsockopt( int socket_id, int level, int optname, void * value, size_t * optlen ){ 821 socket_ref socket; 822 aid_t message_id; 823 ipcarg_t result; 824 825 if( !( value && optlen )) return EBADMEM; 826 if( !( * optlen )) return NO_DATA; 827 fibril_rwlock_read_lock( & socket_globals.lock ); 870 828 // find the socket 871 socket = sockets_find( socket_get_sockets(), socket_id);872 if( ! socket){873 fibril_rwlock_read_unlock( &socket_globals.lock);829 socket = sockets_find( socket_get_sockets(), socket_id ); 830 if( ! socket ){ 831 fibril_rwlock_read_unlock( & socket_globals.lock ); 874 832 return ENOTSOCK; 875 833 } 876 834 // request option value 877 message_id = async_send_3( socket->phone, NET_SOCKET_GETSOCKOPT, (ipcarg_t) socket->socket_id, (ipcarg_t) optname, socket->service, NULL);835 message_id = async_send_3( socket->phone, NET_SOCKET_GETSOCKOPT, ( ipcarg_t ) socket->socket_id, ( ipcarg_t ) optname, socket->service, NULL ); 878 836 // read the length 879 if( async_data_read_start(socket->phone, optlen, sizeof(*optlen)) == EOK){837 if( async_data_read_start( socket->phone, optlen, sizeof( * optlen )) == EOK ){ 880 838 // read the value 881 async_data_read_start( socket->phone, value, * optlen);882 } 883 fibril_rwlock_read_unlock( &socket_globals.lock);884 async_wait_for( message_id, &result);885 return ( int) result;886 } 887 888 int setsockopt( int socket_id, int level, int optname, const void * value, size_t optlen){839 async_data_read_start( socket->phone, value, * optlen ); 840 } 841 fibril_rwlock_read_unlock( & socket_globals.lock ); 842 async_wait_for( message_id, & result ); 843 return ( int ) result; 844 } 845 846 int setsockopt( int socket_id, int level, int optname, const void * value, size_t optlen ){ 889 847 // send the value 890 return socket_send_data( socket_id, NET_SOCKET_SETSOCKOPT, (ipcarg_t) optname, value, optlen);848 return socket_send_data( socket_id, NET_SOCKET_SETSOCKOPT, ( ipcarg_t ) optname, value, optlen ); 891 849 892 850 }
Note:
See TracChangeset
for help on using the changeset viewer.