Rev 4729 | Rev 4743 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 4729 | Rev 4736 | ||
---|---|---|---|
Line 338... | Line 338... | ||
338 | // create a new scoket |
338 | // create a new scoket |
339 | new_socket = ( socket_ref ) malloc( sizeof( socket_t )); |
339 | new_socket = ( socket_ref ) malloc( sizeof( socket_t )); |
340 | if( ! new_socket ){ |
340 | if( ! new_socket ){ |
341 | ERROR_CODE = ENOMEM; |
341 | ERROR_CODE = ENOMEM; |
342 | }else{ |
342 | }else{ |
- | 343 | bzero( socket, sizeof( * socket )); |
|
343 | socket_initialize( new_socket, SOCKET_GET_SOCKET_ID( call ), socket->phone, socket->service ); |
344 | socket_initialize( new_socket, SOCKET_GET_SOCKET_ID( call ), socket->phone, socket->service ); |
344 | ERROR_CODE = sockets_add( socket_get_sockets(), new_socket->socket_id, new_socket ); |
345 | ERROR_CODE = sockets_add( socket_get_sockets(), new_socket->socket_id, new_socket ); |
345 | if( ERROR_CODE < 0 ){ |
346 | if( ERROR_CODE < 0 ){ |
346 | free( new_socket ); |
347 | free( new_socket ); |
347 | }else{ |
348 | }else{ |
Line 428... | Line 429... | ||
428 | return EPFNOSUPPORT; |
429 | return EPFNOSUPPORT; |
429 | } |
430 | } |
430 | // create a new socket structure |
431 | // create a new socket structure |
431 | socket = ( socket_ref ) malloc( sizeof( socket_t )); |
432 | socket = ( socket_ref ) malloc( sizeof( socket_t )); |
432 | if( ! socket ) return ENOMEM; |
433 | if( ! socket ) return ENOMEM; |
433 | if( ERROR_OCCURRED( dyn_fifo_initialize( & socket->received, SOCKET_INITIAL_RECEIVED_SIZE ))){ |
- | |
434 | free( socket ); |
- | |
435 | return ERROR_CODE; |
- | |
436 | } |
- | |
437 | if( ERROR_OCCURRED( dyn_fifo_initialize( & socket->accepted, SOCKET_INITIAL_ACCEPTED_SIZE ))){ |
- | |
438 | dyn_fifo_destroy( & socket->received ); |
434 | bzero( socket, sizeof( * socket )); |
439 | free( socket ); |
- | |
440 | return ERROR_CODE; |
- | |
441 | } |
- | |
442 | // request a new socket |
435 | // request a new socket |
443 | if( ERROR_OCCURRED(( int ) async_req_3_3( phone, NET_SOCKET, 0, 0, service, ( ipcarg_t * ) & socket_id, ( ipcarg_t * ) & socket->data_fragment_size, ( ipcarg_t * ) & socket->header_size ))){ |
436 | if( ERROR_OCCURRED(( int ) async_req_3_3( phone, NET_SOCKET, 0, 0, service, ( ipcarg_t * ) & socket_id, ( ipcarg_t * ) & socket->data_fragment_size, ( ipcarg_t * ) & socket->header_size ))){ |
444 | dyn_fifo_destroy( & socket->received ); |
- | |
445 | dyn_fifo_destroy( & socket->accepted ); |
- | |
446 | free( socket ); |
437 | free( socket ); |
447 | return ERROR_CODE; |
438 | return ERROR_CODE; |
448 | } |
439 | } |
449 | // finish the new socket initialization |
440 | // finish the new socket initialization |
450 | socket_initialize( socket, socket_id, phone, service ); |
441 | socket_initialize( socket, socket_id, phone, service ); |
Line 547... | Line 538... | ||
547 | fibril_mutex_unlock( & socket->accept_lock ); |
538 | fibril_mutex_unlock( & socket->accept_lock ); |
548 | return result; |
539 | return result; |
549 | } |
540 | } |
550 | 541 | ||
551 | int connect( int socket_id, const struct sockaddr * serv_addr, socklen_t addrlen ){ |
542 | int connect( int socket_id, const struct sockaddr * serv_addr, socklen_t addrlen ){ |
- | 543 | if( ! serv_addr ) return EDESTADDRREQ; |
|
- | 544 | if( ! addrlen ) return EDESTADDRREQ; |
|
552 | // send the address |
545 | // send the address |
553 | return socket_send_data( socket_id, NET_SOCKET_CONNECT, 0, serv_addr, addrlen ); |
546 | return socket_send_data( socket_id, NET_SOCKET_CONNECT, 0, serv_addr, addrlen ); |
554 | } |
547 | } |
555 | 548 | ||
556 | int closesocket( int socket_id ){ |
549 | int closesocket( int socket_id ){ |
Line 592... | Line 585... | ||
592 | // without the address |
585 | // without the address |
593 | return sendto_core( NET_SOCKET_SEND, socket_id, data, datalength, flags, NULL, 0 ); |
586 | return sendto_core( NET_SOCKET_SEND, socket_id, data, datalength, flags, NULL, 0 ); |
594 | } |
587 | } |
595 | 588 | ||
596 | int sendto( int socket_id, const void * data, size_t datalength, int flags, const struct sockaddr * toaddr, socklen_t addrlen ){ |
589 | int sendto( int socket_id, const void * data, size_t datalength, int flags, const struct sockaddr * toaddr, socklen_t addrlen ){ |
597 | if( ! toaddr ) return EBADMEM; |
590 | if( ! toaddr ) return EDESTADDRREQ; |
598 | if( ! addrlen ) return NO_DATA; |
591 | if( ! addrlen ) return EDESTADDRREQ; |
599 | // with the address |
592 | // with the address |
600 | return sendto_core( NET_SOCKET_SENDTO, socket_id, data, datalength, flags, toaddr, addrlen ); |
593 | return sendto_core( NET_SOCKET_SENDTO, socket_id, data, datalength, flags, toaddr, addrlen ); |
601 | } |
594 | } |
602 | 595 | ||
603 | int sendto_core( ipcarg_t message, int socket_id, const void * data, size_t datalength, int flags, const struct sockaddr * toaddr, socklen_t addrlen ){ |
596 | int sendto_core( ipcarg_t message, int socket_id, const void * data, size_t datalength, int flags, const struct sockaddr * toaddr, socklen_t addrlen ){ |