Changeset ede63e4 in mainline for uspace/srv/net/tl/tcp/tcp.c
- Timestamp:
- 2010-01-04T23:25:48Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- eac9722
- Parents:
- 1a0fb3f8
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/net/tl/tcp/tcp.c
r1a0fb3f8 rede63e4 205 205 int tcp_connect_message( socket_cores_ref local_sockets, int socket_id, struct sockaddr * addr, socklen_t addrlen ); 206 206 int tcp_recvfrom_message( socket_cores_ref local_sockets, int socket_id, int flags, size_t * addrlen ); 207 int tcp_send_message( socket_cores_ref local_sockets, int socket_id, int fragments, size_t data_fragment_size, int flags );208 int tcp_accept_message( socket_cores_ref local_sockets, int socket_id, size_t * addrlen );207 int tcp_send_message( socket_cores_ref local_sockets, int socket_id, int fragments, size_t * data_fragment_size, int flags ); 208 int tcp_accept_message( socket_cores_ref local_sockets, int socket_id, int new_socket_id, size_t * data_fragment_size, size_t * addrlen ); 209 209 int tcp_close_message( socket_cores_ref local_sockets, int socket_id ); 210 210 … … 298 298 return tcp_release_and_return( packet, EINVAL ); 299 299 } 300 if( length < sizeof( tcp_header_t )+ offset ){300 if( length < TCP_HEADER_SIZE + offset ){ 301 301 return tcp_release_and_return( packet, NO_DATA ); 302 302 } … … 668 668 ERROR_DECLARE; 669 669 670 packet_dimension_ref packet_dimension; 671 670 672 assert( socket ); 671 673 assert( socket_data ); … … 676 678 677 679 // queue the received packet 678 if( ERROR_OCCURRED( dyn_fifo_push( & socket->received, packet_get_id( packet ), SOCKET_MAX_RECEIVED_SIZE ))){ 680 if( ERROR_OCCURRED( dyn_fifo_push( & socket->received, packet_get_id( packet ), SOCKET_MAX_RECEIVED_SIZE )) 681 || ERROR_OCCURRED( tl_get_ip_packet_dimension( tcp_globals.ip_phone, & tcp_globals.dimensions, socket_data->device_id, & packet_dimension ))){ 679 682 return tcp_release_and_return( packet, ERROR_CODE ); 680 683 } … … 684 687 685 688 // notify the destination socket 686 async_msg_5( socket->phone, NET_SOCKET_RECEIVED, ( ipcarg_t ) socket->socket_id, 0, 0, 0, ( ipcarg_t ) fragments );689 async_msg_5( socket->phone, NET_SOCKET_RECEIVED, ( ipcarg_t ) socket->socket_id, (( packet_dimension->content < socket_data->data_fragment_size ) ? packet_dimension->content : socket_data->data_fragment_size ), 0, 0, ( ipcarg_t ) fragments ); 687 690 return EOK; 688 691 } … … 783 786 // printf( "addr %p\n", socket_data->addr, socket_data->addrlen ); 784 787 // create a socket 788 socket_id = -1; 785 789 if( ERROR_OCCURRED( socket_create( socket_data->local_sockets, listening_socket->phone, socket_data, & socket_id ))){ 786 790 free( socket_data->addr ); … … 789 793 } 790 794 795 socket_id *= -1; 791 796 printf("new_sock %d\n", socket_id); 792 797 socket_data->pseudo_header = listening_socket_data->pseudo_header; … … 901 906 if( ! ERROR_OCCURRED( dyn_fifo_push( & listening_socket->accepted, socket->socket_id, listening_socket_data->backlog ))){ 902 907 // notify the destination socket 903 async_msg_5( socket->phone, NET_SOCKET_ACCEPTED, ( ipcarg_t ) listening_socket->socket_id, 0, 0, 0, ( ipcarg_t ) socket->socket_id );908 async_msg_5( socket->phone, NET_SOCKET_ACCEPTED, ( ipcarg_t ) listening_socket->socket_id, socket_data->data_fragment_size, TCP_HEADER_SIZE, 0, ( ipcarg_t ) socket->socket_id ); 904 909 fibril_rwlock_write_unlock( socket_data->local_lock ); 905 910 return EOK; … … 1035 1040 bzero( socket_data, sizeof( * socket_data )); 1036 1041 socket_data->state = TCP_SOCKET_INITIAL; 1037 socket_data->device_id = -1;1042 socket_data->device_id = DEVICE_INVALID_ID; 1038 1043 socket_data->window = NET_DEFAULT_TCP_WINDOW; 1039 1044 socket_data->treshold = socket_data->window; … … 1051 1056 fibril_mutex_initialize( & socket_data->operation.mutex ); 1052 1057 fibril_condvar_initialize( & socket_data->operation.condvar ); 1058 socket_data->data_fragment_size = MAX_TCP_FRAGMENT_SIZE; 1053 1059 } 1054 1060 … … 1065 1071 tcp_socket_data_ref socket_data; 1066 1072 socket_core_ref socket; 1073 packet_dimension_ref packet_dimension; 1067 1074 1068 1075 /* … … 1096 1103 socket_data->local_sockets = & local_sockets; 1097 1104 fibril_rwlock_write_lock( & lock ); 1105 * SOCKET_SET_SOCKET_ID( answer ) = SOCKET_GET_SOCKET_ID( call ); 1098 1106 res = socket_create( & local_sockets, app_phone, socket_data, SOCKET_SET_SOCKET_ID( answer )); 1099 1107 fibril_rwlock_write_unlock( & lock ); 1100 1108 if( res == EOK ){ 1101 * SOCKET_SET_HEADER_SIZE( answer ) = sizeof( tcp_header_t ); 1102 * SOCKET_SET_DATA_FRAGMENT_SIZE( answer ) = MAX_TCP_FRAGMENT_SIZE; 1109 if( tl_get_ip_packet_dimension( tcp_globals.ip_phone, & tcp_globals.dimensions, DEVICE_INVALID_ID, & packet_dimension ) == EOK ){ 1110 * SOCKET_SET_DATA_FRAGMENT_SIZE( answer ) = (( packet_dimension->content < socket_data->data_fragment_size ) ? packet_dimension->content : socket_data->data_fragment_size ); 1111 } 1112 // * SOCKET_SET_DATA_FRAGMENT_SIZE( answer ) = MAX_TCP_FRAGMENT_SIZE; 1113 * SOCKET_SET_HEADER_SIZE( answer ) = TCP_HEADER_SIZE; 1103 1114 answer_count = 3; 1104 1115 }else{ … … 1138 1149 res = data_receive(( void ** ) & addr, & addrlen ); 1139 1150 if( res == EOK ){ 1140 // the global lock may released in the tcp_connect_message() function1151 // the global lock may be released in the tcp_connect_message() function 1141 1152 fibril_rwlock_write_lock( & tcp_globals.lock ); 1142 1153 fibril_rwlock_write_lock( & lock ); … … 1152 1163 fibril_rwlock_read_lock( & tcp_globals.lock ); 1153 1164 fibril_rwlock_write_lock( & lock ); 1154 res = tcp_accept_message( & local_sockets, SOCKET_GET_SOCKET_ID( call ), & addrlen );1165 res = tcp_accept_message( & local_sockets, SOCKET_GET_SOCKET_ID( call ), SOCKET_GET_NEW_SOCKET_ID( call ), SOCKET_SET_DATA_FRAGMENT_SIZE( answer ), & addrlen ); 1155 1166 fibril_rwlock_write_unlock( & lock ); 1156 1167 fibril_rwlock_read_unlock( & tcp_globals.lock ); … … 1158 1169 * SOCKET_SET_SOCKET_ID( answer ) = res; 1159 1170 * SOCKET_SET_ADDRESS_LENGTH( answer ) = addrlen; 1160 answer_count = 2;1171 answer_count = 3; 1161 1172 } 1162 1173 break; … … 1164 1175 fibril_rwlock_read_lock( & tcp_globals.lock ); 1165 1176 fibril_rwlock_write_lock( & lock ); 1166 res = tcp_send_message( & local_sockets, SOCKET_GET_SOCKET_ID( call ), SOCKET_GET_DATA_FRAGMENTS( call ), SOCKET_ GET_DATA_FRAGMENT_SIZE( call), SOCKET_GET_FLAGS( call ));1177 res = tcp_send_message( & local_sockets, SOCKET_GET_SOCKET_ID( call ), SOCKET_GET_DATA_FRAGMENTS( call ), SOCKET_SET_DATA_FRAGMENT_SIZE( answer ), SOCKET_GET_FLAGS( call )); 1167 1178 if( res != EOK ){ 1168 1179 fibril_rwlock_write_unlock( & lock ); 1169 1180 fibril_rwlock_read_unlock( & tcp_globals.lock ); 1181 }else{ 1182 answer_count = 2; 1170 1183 } 1171 1184 break; … … 1175 1188 fibril_rwlock_read_lock( & tcp_globals.lock ); 1176 1189 fibril_rwlock_write_lock( & lock ); 1177 res = tcp_send_message( & local_sockets, SOCKET_GET_SOCKET_ID( call ), SOCKET_GET_DATA_FRAGMENTS( call ), SOCKET_ GET_DATA_FRAGMENT_SIZE( call), SOCKET_GET_FLAGS( call ));1190 res = tcp_send_message( & local_sockets, SOCKET_GET_SOCKET_ID( call ), SOCKET_GET_DATA_FRAGMENTS( call ), SOCKET_SET_DATA_FRAGMENT_SIZE( answer ), SOCKET_GET_FLAGS( call )); 1178 1191 if( res != EOK ){ 1179 1192 fibril_rwlock_write_unlock( & lock ); 1180 1193 fibril_rwlock_read_unlock( & tcp_globals.lock ); 1194 }else{ 1195 answer_count = 2; 1181 1196 } 1182 1197 free( addr ); … … 1204 1219 * SOCKET_SET_READ_DATA_LENGTH( answer ) = res; 1205 1220 * SOCKET_SET_ADDRESS_LENGTH( answer ) = addrlen; 1206 answer_count = 2;1221 answer_count = 3; 1207 1222 res = EOK; 1208 1223 } … … 1725 1740 } 1726 1741 1727 int tcp_send_message( socket_cores_ref local_sockets, int socket_id, int fragments, size_t data_fragment_size, int flags ){1742 int tcp_send_message( socket_cores_ref local_sockets, int socket_id, int fragments, size_t * data_fragment_size, int flags ){ 1728 1743 ERROR_DECLARE; 1729 1744 … … 1738 1753 1739 1754 assert( local_sockets ); 1755 assert( data_fragment_size ); 1740 1756 1741 1757 // find the socket … … 1753 1769 ERROR_PROPAGATE( tl_get_ip_packet_dimension( tcp_globals.ip_phone, & tcp_globals.dimensions, socket_data->device_id, & packet_dimension )); 1754 1770 1755 // TODO return the device_id + data_fragment_size if different - the client should send it again 1756 // ( two messages are better than ip fragmentation ) 1771 * data_fragment_size = (( packet_dimension->content < socket_data->data_fragment_size ) ? packet_dimension->content : socket_data->data_fragment_size ); 1757 1772 1758 1773 for( index = 0; index < fragments; ++ index ){ 1759 1774 // read the data fragment 1760 result = tl_socket_read_packet_data( tcp_globals.net_phone, & packet, sizeof( tcp_header_t ), packet_dimension, socket_data->addr, socket_data->addrlen );1775 result = tl_socket_read_packet_data( tcp_globals.net_phone, & packet, TCP_HEADER_SIZE, packet_dimension, socket_data->addr, socket_data->addrlen ); 1761 1776 if( result < 0 ) return result; 1762 1777 total_length = ( size_t ) result; … … 1844 1859 ERROR_PROPAGATE( tl_get_ip_packet_dimension( tcp_globals.ip_phone, & tcp_globals.dimensions, socket_data->device_id, & packet_dimension )); 1845 1860 // get a new packet 1846 * packet = packet_get_4( tcp_globals.net_phone, sizeof( tcp_header_t ), packet_dimension->addr_len, packet_dimension->prefix, packet_dimension->suffix );1861 * packet = packet_get_4( tcp_globals.net_phone, TCP_HEADER_SIZE, packet_dimension->addr_len, packet_dimension->prefix, packet_dimension->suffix ); 1847 1862 if( ! * packet ) return ENOMEM; 1848 1863 // allocate space in the packet … … 1856 1871 } 1857 1872 1858 int tcp_accept_message( socket_cores_ref local_sockets, int socket_id, size_t * addrlen ){1873 int tcp_accept_message( socket_cores_ref local_sockets, int socket_id, int new_socket_id, size_t * data_fragment_size, size_t * addrlen ){ 1859 1874 ERROR_DECLARE; 1860 1875 … … 1862 1877 socket_core_ref socket; 1863 1878 tcp_socket_data_ref socket_data; 1879 packet_dimension_ref packet_dimension; 1864 1880 1865 1881 assert( local_sockets ); 1882 assert( data_fragment_size ); 1866 1883 assert( addrlen ); 1867 1884 … … 1887 1904 socket_data = ( tcp_socket_data_ref ) accepted->specific_data; 1888 1905 assert( socket_data ); 1906 // TODO can it be in another state? 1889 1907 if( socket_data->state == TCP_SOCKET_ESTABLISHED ){ 1890 1908 ERROR_PROPAGATE( data_reply( socket_data->addr, socket_data->addrlen )); 1909 ERROR_PROPAGATE( tl_get_ip_packet_dimension( tcp_globals.ip_phone, & tcp_globals.dimensions, socket_data->device_id, & packet_dimension )); 1891 1910 * addrlen = socket_data->addrlen; 1911 * data_fragment_size = (( packet_dimension->content < socket_data->data_fragment_size ) ? packet_dimension->content : socket_data->data_fragment_size ); 1912 if( new_socket_id > 0 ){ 1913 ERROR_PROPAGATE( socket_cores_update( local_sockets, accepted->socket_id, new_socket_id )); 1914 accepted->socket_id = new_socket_id; 1915 } 1892 1916 } 1893 1917 dyn_fifo_pop( & socket->accepted );
Note:
See TracChangeset
for help on using the changeset viewer.