Rev 4736 | Rev 4747 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 4736 | Rev 4743 | ||
---|---|---|---|
Line 308... | Line 308... | ||
308 | 308 | ||
309 | while( true ){ |
309 | while( true ){ |
310 | 310 | ||
311 | callid = async_get_call( & call ); |
311 | callid = async_get_call( & call ); |
312 | switch( IPC_GET_METHOD( call )){ |
312 | switch( IPC_GET_METHOD( call )){ |
313 | // TODO remember the data_fragment_size |
- | |
314 | case NET_SOCKET_RECEIVED: |
313 | case NET_SOCKET_RECEIVED: |
315 | fibril_rwlock_read_lock( & socket_globals.lock ); |
314 | fibril_rwlock_read_lock( & socket_globals.lock ); |
316 | // find the socket |
315 | // find the socket |
317 | socket = sockets_find( socket_get_sockets(), SOCKET_GET_SOCKET_ID( call )); |
316 | socket = sockets_find( socket_get_sockets(), SOCKET_GET_SOCKET_ID( call )); |
318 | if( ! socket ){ |
317 | if( ! socket ){ |
Line 338... | Line 337... | ||
338 | // create a new scoket |
337 | // create a new scoket |
339 | new_socket = ( socket_ref ) malloc( sizeof( socket_t )); |
338 | new_socket = ( socket_ref ) malloc( sizeof( socket_t )); |
340 | if( ! new_socket ){ |
339 | if( ! new_socket ){ |
341 | ERROR_CODE = ENOMEM; |
340 | ERROR_CODE = ENOMEM; |
342 | }else{ |
341 | }else{ |
343 | bzero( socket, sizeof( * socket )); |
342 | bzero( new_socket, sizeof( * new_socket )); |
344 | socket_initialize( new_socket, SOCKET_GET_SOCKET_ID( call ), socket->phone, socket->service ); |
343 | socket_initialize( new_socket, SOCKET_GET_NEW_SOCKET_ID( call ), socket->phone, socket->service ); |
345 | ERROR_CODE = sockets_add( socket_get_sockets(), new_socket->socket_id, new_socket ); |
344 | ERROR_CODE = sockets_add( socket_get_sockets(), new_socket->socket_id, new_socket ); |
346 | if( ERROR_CODE < 0 ){ |
345 | if( ERROR_CODE < 0 ){ |
347 | free( new_socket ); |
346 | free( new_socket ); |
348 | }else{ |
347 | }else{ |
349 | // push the new socket identifier |
348 | // push the new socket identifier |
350 | fibril_mutex_lock( & socket->accept_lock ); |
349 | fibril_mutex_lock( & socket->accept_lock ); |
351 | if( ERROR_OCCURRED( dyn_fifo_push( & socket->accepted, new_socket->socket_id, SOCKET_MAX_ACCEPTED_SIZE ))){ |
350 | if( ERROR_OCCURRED( dyn_fifo_push( & socket->accepted, new_socket->socket_id, SOCKET_MAX_ACCEPTED_SIZE ))){ |
352 | sockets_exclude( socket_get_sockets(), new_socket->socket_id ); |
351 | sockets_exclude( socket_get_sockets(), new_socket->socket_id ); |
353 | free( new_socket ); |
- | |
354 | }else{ |
352 | }else{ |
355 | // signal the accepted socket |
353 | // signal the accepted socket |
356 | fibril_condvar_signal( & socket->accept_signal ); |
354 | fibril_condvar_signal( & socket->accept_signal ); |
357 | } |
355 | } |
358 | fibril_mutex_unlock( & socket->accept_lock ); |
356 | fibril_mutex_unlock( & socket->accept_lock ); |
Line 360... | Line 358... | ||
360 | } |
358 | } |
361 | } |
359 | } |
362 | } |
360 | } |
363 | fibril_rwlock_read_unlock( & socket_globals.lock ); |
361 | fibril_rwlock_read_unlock( & socket_globals.lock ); |
364 | break; |
362 | break; |
365 | // TODO obsolete? |
- | |
366 | case NET_SOCKET_DATA_FRAGMENT_SIZE: |
363 | case NET_SOCKET_DATA_FRAGMENT_SIZE: |
367 | fibril_rwlock_read_lock( & socket_globals.lock ); |
364 | fibril_rwlock_read_lock( & socket_globals.lock ); |
368 | // find the socket |
365 | // find the socket |
369 | socket = sockets_find( socket_get_sockets(), SOCKET_GET_SOCKET_ID( call )); |
366 | socket = sockets_find( socket_get_sockets(), SOCKET_GET_SOCKET_ID( call )); |
370 | if( ! socket ){ |
367 | if( ! socket ){ |
Line 504... | Line 501... | ||
504 | 501 | ||
505 | int accept( int socket_id, struct sockaddr * cliaddr, socklen_t * addrlen ){ |
502 | int accept( int socket_id, struct sockaddr * cliaddr, socklen_t * addrlen ){ |
506 | socket_ref socket; |
503 | socket_ref socket; |
507 | aid_t message_id; |
504 | aid_t message_id; |
508 | int result; |
505 | int result; |
- | 506 | ipc_call_t answer; |
|
509 | 507 | ||
510 | if(( ! cliaddr ) || ( ! addrlen )) return EBADMEM; |
508 | if(( ! cliaddr ) || ( ! addrlen )) return EBADMEM; |
511 | 509 | ||
512 | fibril_rwlock_read_lock( & socket_globals.lock ); |
510 | fibril_rwlock_read_lock( & socket_globals.lock ); |
513 | // find the socket |
511 | // find the socket |
Line 524... | Line 522... | ||
524 | fibril_condvar_wait( & socket->accept_signal, & socket->accept_lock ); |
522 | fibril_condvar_wait( & socket->accept_signal, & socket->accept_lock ); |
525 | fibril_rwlock_read_lock( & socket_globals.lock ); |
523 | fibril_rwlock_read_lock( & socket_globals.lock ); |
526 | } |
524 | } |
527 | -- socket->blocked; |
525 | -- socket->blocked; |
528 | // request accept |
526 | // request accept |
529 | message_id = async_send_3( socket->phone, NET_SOCKET_ACCEPT, ( ipcarg_t ) socket->socket_id, ( ipcarg_t ) dyn_fifo_value( & socket->accepted ), socket->service, NULL ); |
527 | message_id = async_send_3( socket->phone, NET_SOCKET_ACCEPT, ( ipcarg_t ) socket->socket_id, 0, socket->service, & answer ); |
530 | // read address |
528 | // read address |
531 | ipc_data_read_start( socket->phone, cliaddr, * addrlen ); |
529 | ipc_data_read_start( socket->phone, cliaddr, * addrlen ); |
532 | fibril_rwlock_read_unlock( & socket_globals.lock ); |
530 | fibril_rwlock_read_unlock( & socket_globals.lock ); |
533 | async_wait_for( message_id, ( ipcarg_t * ) & result ); |
531 | async_wait_for( message_id, ( ipcarg_t * ) & result ); |
534 | if( result > 0 ){ |
532 | if( result > 0 ){ |
535 | // dequeue the accepted apcket if successful |
533 | // dequeue the accepted socket if successful |
536 | dyn_fifo_pop( & socket->accepted ); |
534 | dyn_fifo_pop( & socket->accepted ); |
- | 535 | // set address length |
|
- | 536 | * addrlen = SOCKET_GET_ADDRESS_LENGTH( answer ); |
|
- | 537 | }else if( result == ENOTSOCK ){ |
|
- | 538 | // empty the queue if no accepted sockets |
|
- | 539 | while( dyn_fifo_pop( & socket->accepted ) > 0 ); |
|
537 | } |
540 | } |
538 | fibril_mutex_unlock( & socket->accept_lock ); |
541 | fibril_mutex_unlock( & socket->accept_lock ); |
539 | return result; |
542 | return result; |
540 | } |
543 | } |
541 | 544 |