Changeset 45bb1d2 in mainline
- Timestamp:
- 2010-12-27T20:04:22Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- b35fea3, e64e40b
- Parents:
- 727f04f
- Location:
- uspace/lib/c/generic/net
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/net/icmp_api.c
r727f04f r45bb1d2 89 89 tos, (sysarg_t) dont_fragment, NULL); 90 90 91 / / send the address91 /* Send the address */ 92 92 async_data_write_start(icmp_phone, addr, (size_t) addrlen); 93 93 -
uspace/lib/c/generic/net/inet.c
r727f04f r45bb1d2 64 64 switch (family) { 65 65 case AF_INET: 66 / / check the output buffer size66 /* Check output buffer size */ 67 67 if (length < INET_ADDRSTRLEN) 68 68 return ENOMEM; 69 69 70 / / fill the buffer with the IPv4 address70 /* Fill buffer with IPv4 address */ 71 71 snprintf(address, length, "%hhu.%hhu.%hhu.%hhu", 72 72 data[0], data[1], data[2], data[3]); … … 75 75 76 76 case AF_INET6: 77 / / check the output buffer size77 /* Check output buffer size */ 78 78 if (length < INET6_ADDRSTRLEN) 79 79 return ENOMEM; 80 80 81 / / fill the buffer with the IPv6 address81 /* Fill buffer with IPv6 address */ 82 82 snprintf(address, length, 83 83 "%hhx%hhx:%hhx%hhx:%hhx%hhx:%hhx%hhx:%hhx%hhx:%hhx%hhx:" … … 124 124 return EINVAL; 125 125 126 / / set the processing parameters126 /* Set processing parameters */ 127 127 switch (family) { 128 128 case AF_INET: … … 142 142 } 143 143 144 / / erase if no address144 /* Erase if no address */ 145 145 if (!address) { 146 146 bzero(data, count); … … 148 148 } 149 149 150 / / process the string from the beginning150 /* Process string from the beginning */ 151 151 next = address; 152 152 index = 0; 153 153 do { 154 / / if the actual character is set154 /* If the actual character is set */ 155 155 if (next && *next) { 156 156 157 / / if not on the first character157 /* If not on the first character */ 158 158 if (index) { 159 / / move to the next character159 /* Move to the next character */ 160 160 ++next; 161 161 } 162 162 163 / / parse the actual integral value163 /* Parse the actual integral value */ 164 164 value = strtoul(next, &last, base); 165 // remember the last problematic character 166 // should be either '.' or ':' but is ignored to be more 167 // generic 165 /* 166 * Remember the last problematic character 167 * should be either '.' or ':' but is ignored to be 168 * more generic 169 */ 168 170 next = last; 169 171 170 / / fill the address data byte by byte172 /* Fill the address data byte by byte */ 171 173 shift = bytes - 1; 172 174 do { 173 / / like little endian175 /* like little endian */ 174 176 data[index + shift] = value; 175 177 value >>= 8; … … 178 180 index += bytes; 179 181 } else { 180 / / erase the rest of the address182 /* Erase the rest of the address */ 181 183 bzero(data + index, count - index); 182 184 return EOK; -
uspace/lib/c/generic/net/modules.c
r727f04f r45bb1d2 63 63 int answer_count) 64 64 { 65 / / choose the most efficient answer function65 /* Choose the most efficient answer function */ 66 66 if (answer || (!answer_count)) { 67 67 switch (answer_count) { … … 178 178 int phone; 179 179 180 / / if no timeout is set180 /* If no timeout is set */ 181 181 if (timeout <= 0) 182 182 return async_connect_me_to_blocking(PHONE_NS, need, 0, 0); … … 187 187 return phone; 188 188 189 / / end if no time is left189 /* Abort if no time is left */ 190 190 if (timeout <= 0) 191 191 return ETIMEOUT; 192 192 193 / / wait the minimum of the module wait time and the timeout193 /* Wait the minimum of the module wait time and the timeout */ 194 194 usleep((timeout <= MODULE_WAIT_TIME) ? 195 195 timeout : MODULE_WAIT_TIME); … … 214 214 ipc_callid_t callid; 215 215 216 / / fetch the request216 /* Fetch the request */ 217 217 if (!async_data_read_receive(&callid, &length)) 218 218 return EINVAL; 219 219 220 / / check the requested data size220 /* Check the requested data size */ 221 221 if (length < data_length) { 222 222 async_data_read_finalize(callid, data, length); … … 224 224 } 225 225 226 / / send the data226 /* Send the data */ 227 227 return async_data_read_finalize(callid, data, data_length); 228 228 } … … 242 242 if (answer) { 243 243 IPC_SET_RETVAL(*answer, 0); 244 / / just to be precize244 /* Just to be precise */ 245 245 IPC_SET_IMETHOD(*answer, 0); 246 246 IPC_SET_ARG1(*answer, 0); -
uspace/lib/c/generic/net/packet.c
r727f04f r45bb1d2 191 191 } 192 192 gpm_destroy(&pm_globals.packet_map); 193 / / leave locked193 /* leave locked */ 194 194 } 195 195 -
uspace/lib/c/generic/net/socket_client.c
r727f04f r45bb1d2 220 220 fibril_rwlock_read_lock(&socket_globals.lock); 221 221 222 / / find the socket222 /* Find the socket */ 223 223 socket = sockets_find(socket_get_sockets(), 224 224 SOCKET_GET_SOCKET_ID(call)); … … 232 232 case NET_SOCKET_RECEIVED: 233 233 fibril_mutex_lock(&socket->receive_lock); 234 / / push the number of received packet fragments234 /* Push the number of received packet fragments */ 235 235 rc = dyn_fifo_push(&socket->received, 236 236 SOCKET_GET_DATA_FRAGMENTS(call), 237 237 SOCKET_MAX_RECEIVED_SIZE); 238 238 if (rc == EOK) { 239 / / signal the received packet239 /* Signal the received packet */ 240 240 fibril_condvar_signal(&socket->receive_signal); 241 241 } … … 244 244 245 245 case NET_SOCKET_ACCEPTED: 246 / / push the new socket identifier246 /* Push the new socket identifier */ 247 247 fibril_mutex_lock(&socket->accept_lock); 248 248 rc = dyn_fifo_push(&socket->accepted, 1, 249 249 SOCKET_MAX_ACCEPTED_SIZE); 250 250 if (rc == EOK) { 251 / / signal the accepted socket251 /* Signal the accepted socket */ 252 252 fibril_condvar_signal(&socket->accept_signal); 253 253 } … … 264 264 fibril_rwlock_write_lock(&socket->sending_lock); 265 265 266 / / set the data fragment size266 /* Set the data fragment size */ 267 267 socket->data_fragment_size = 268 268 SOCKET_GET_DATA_FRAGMENT_SIZE(call); … … 342 342 socket_id = 1; 343 343 ++count; 344 / / only this branch for last_id344 /* Only this branch for last_id */ 345 345 } else { 346 346 if (socket_id < INT_MAX) { … … 408 408 int rc; 409 409 410 / / find the appropriate service410 /* Find the appropriate service */ 411 411 switch (domain) { 412 412 case PF_INET: … … 457 457 return phone; 458 458 459 / / create a new socket structure459 /* Create a new socket structure */ 460 460 socket = (socket_t *) malloc(sizeof(socket_t)); 461 461 if (!socket) … … 465 465 fibril_rwlock_write_lock(&socket_globals.lock); 466 466 467 / / request a new socket467 /* Request a new socket */ 468 468 socket_id = socket_generate_new_id(); 469 469 if (socket_id <= 0) { … … 484 484 socket->header_size = (size_t) header_size; 485 485 486 / / finish the new socket initialization486 /* Finish the new socket initialization */ 487 487 socket_initialize(socket, socket_id, phone, service); 488 / / store the new socket488 /* Store the new socket */ 489 489 rc = sockets_add(socket_get_sockets(), socket_id, socket); 490 490 … … 531 531 fibril_rwlock_read_lock(&socket_globals.lock); 532 532 533 / / find the socket533 /* Find the socket */ 534 534 socket = sockets_find(socket_get_sockets(), socket_id); 535 535 if (!socket) { … … 538 538 } 539 539 540 / / request the message540 /* Request the message */ 541 541 message_id = async_send_3(socket->phone, message, 542 542 (sysarg_t) socket->socket_id, arg2, socket->service, NULL); 543 / / send the address543 /* Send the address */ 544 544 async_data_write_start(socket->phone, data, datalength); 545 545 … … 566 566 return EINVAL; 567 567 568 / / send the address568 /* Send the address */ 569 569 return socket_send_data(socket_id, NET_SOCKET_BIND, 0, my_addr, 570 570 (size_t) addrlen); … … 591 591 fibril_rwlock_read_lock(&socket_globals.lock); 592 592 593 / / find the socket593 /* Find the socket */ 594 594 socket = sockets_find(socket_get_sockets(), socket_id); 595 595 if (!socket) { … … 598 598 } 599 599 600 / / request listen backlog change600 /* Request listen backlog change */ 601 601 result = (int) async_req_3_0(socket->phone, NET_SOCKET_LISTEN, 602 602 (sysarg_t) socket->socket_id, (sysarg_t) backlog, socket->service); … … 634 634 fibril_rwlock_write_lock(&socket_globals.lock); 635 635 636 / / find the socket636 /* Find the socket */ 637 637 socket = sockets_find(socket_get_sockets(), socket_id); 638 638 if (!socket) { … … 643 643 fibril_mutex_lock(&socket->accept_lock); 644 644 645 / / wait for an accepted socket645 /* Wait for an accepted socket */ 646 646 ++ socket->blocked; 647 647 while (dyn_fifo_value(&socket->accepted) <= 0) { 648 648 fibril_rwlock_write_unlock(&socket_globals.lock); 649 649 fibril_condvar_wait(&socket->accept_signal, &socket->accept_lock); 650 / / drop the accept lock to avoid deadlock650 /* Drop the accept lock to avoid deadlock */ 651 651 fibril_mutex_unlock(&socket->accept_lock); 652 652 fibril_rwlock_write_lock(&socket_globals.lock); … … 655 655 -- socket->blocked; 656 656 657 / / create a new scoket657 /* Create a new socket */ 658 658 new_socket = (socket_t *) malloc(sizeof(socket_t)); 659 659 if (!new_socket) { … … 681 681 } 682 682 683 / / request accept683 /* Request accept */ 684 684 message_id = async_send_5(socket->phone, NET_SOCKET_ACCEPT, 685 685 (sysarg_t) socket->socket_id, 0, socket->service, 0, 686 686 new_socket->socket_id, &answer); 687 687 688 / / read address688 /* Read address */ 689 689 ipc_data_read_start(socket->phone, cliaddr, *addrlen); 690 690 fibril_rwlock_write_unlock(&socket_globals.lock); … … 695 695 result = EINVAL; 696 696 697 / / dequeue the accepted socket if successful697 /* Dequeue the accepted socket if successful */ 698 698 dyn_fifo_pop(&socket->accepted); 699 / / set address length699 /* Set address length */ 700 700 *addrlen = SOCKET_GET_ADDRESS_LENGTH(answer); 701 701 new_socket->data_fragment_size = 702 702 SOCKET_GET_DATA_FRAGMENT_SIZE(answer); 703 703 } else if (result == ENOTSOCK) { 704 / / empty the queue if no accepted sockets704 /* Empty the queue if no accepted sockets */ 705 705 while (dyn_fifo_pop(&socket->accepted) > 0) 706 706 ; … … 731 731 return EDESTADDRREQ; 732 732 733 / / send the address733 /* Send the address */ 734 734 return socket_send_data(socket_id, NET_SOCKET_CONNECT, 0, serv_addr, 735 735 addrlen); … … 744 744 int accepted_id; 745 745 746 / / destroy all accepted sockets746 /* Destroy all accepted sockets */ 747 747 while ((accepted_id = dyn_fifo_pop(&socket->accepted)) >= 0) 748 748 socket_destroy(sockets_find(socket_get_sockets(), accepted_id)); … … 780 780 } 781 781 782 / / request close782 /* Request close */ 783 783 rc = (int) async_req_3_0(socket->phone, NET_SOCKET_CLOSE, 784 784 (sysarg_t) socket->socket_id, 0, socket->service); … … 787 787 return rc; 788 788 } 789 / / free the socket structure789 /* Free the socket structure */ 790 790 socket_destroy(socket); 791 791 … … 833 833 fibril_rwlock_read_lock(&socket_globals.lock); 834 834 835 / / find socket835 /* Find socket */ 836 836 socket = sockets_find(socket_get_sockets(), socket_id); 837 837 if (!socket) { … … 842 842 fibril_rwlock_read_lock(&socket->sending_lock); 843 843 844 / / compute data fragment count844 /* Compute data fragment count */ 845 845 if (socket->data_fragment_size > 0) { 846 846 fragments = (datalength + socket->header_size) / … … 853 853 } 854 854 855 / / request send855 /* Request send */ 856 856 message_id = async_send_5(socket->phone, message, 857 857 (sysarg_t) socket->socket_id, … … 859 859 socket->service, (sysarg_t) flags, fragments, &answer); 860 860 861 / / send the address if given861 /* Send the address if given */ 862 862 if (!toaddr || 863 863 (async_data_write_start(socket->phone, toaddr, addrlen) == EOK)) { 864 864 if (fragments == 1) { 865 / / send all if only one fragment865 /* Send all if only one fragment */ 866 866 async_data_write_start(socket->phone, data, datalength); 867 867 } else { 868 / / send the first fragment868 /* Send the first fragment */ 869 869 async_data_write_start(socket->phone, data, 870 870 socket->data_fragment_size - socket->header_size); … … 872 872 socket->data_fragment_size - socket->header_size; 873 873 874 / / send the middle fragments874 /* Send the middle fragments */ 875 875 while (--fragments > 1) { 876 876 async_data_write_start(socket->phone, data, … … 880 880 } 881 881 882 / / send the last fragment882 /* Send the last fragment */ 883 883 async_data_write_start(socket->phone, data, 884 884 (datalength + socket->header_size) % … … 892 892 (SOCKET_GET_DATA_FRAGMENT_SIZE(answer) != 893 893 socket->data_fragment_size)) { 894 / / set the data fragment size894 /* Set the data fragment size */ 895 895 socket->data_fragment_size = 896 896 SOCKET_GET_DATA_FRAGMENT_SIZE(answer); … … 917 917 int send(int socket_id, void *data, size_t datalength, int flags) 918 918 { 919 / / without the address919 /* Without the address */ 920 920 return sendto_core(NET_SOCKET_SEND, socket_id, data, datalength, flags, 921 921 NULL, 0); … … 950 950 return EDESTADDRREQ; 951 951 952 / / with the address952 /* With the address */ 953 953 return sendto_core(NET_SOCKET_SENDTO, socket_id, data, datalength, 954 954 flags, toaddr, addrlen); … … 998 998 fibril_rwlock_read_lock(&socket_globals.lock); 999 999 1000 / / find the socket1000 /* Find the socket */ 1001 1001 socket = sockets_find(socket_get_sockets(), socket_id); 1002 1002 if (!socket) { … … 1006 1006 1007 1007 fibril_mutex_lock(&socket->receive_lock); 1008 / / wait for a received packet1008 /* Wait for a received packet */ 1009 1009 ++socket->blocked; 1010 1010 while ((result = dyn_fifo_value(&socket->received)) < 0) { … … 1013 1013 &socket->receive_lock); 1014 1014 1015 / / drop the receive lock to avoid deadlock1015 /* Drop the receive lock to avoid deadlock */ 1016 1016 fibril_mutex_unlock(&socket->receive_lock); 1017 1017 fibril_rwlock_read_lock(&socket_globals.lock); … … 1026 1026 } 1027 1027 1028 / / prepare lengths if more fragments1028 /* Prepare lengths if more fragments */ 1029 1029 if (fragments > 1) { 1030 1030 lengths = (size_t *) malloc(sizeof(size_t) * fragments + … … 1036 1036 } 1037 1037 1038 / / request packet data1038 /* Request packet data */ 1039 1039 message_id = async_send_4(socket->phone, message, 1040 1040 (sysarg_t) socket->socket_id, 0, socket->service, 1041 1041 (sysarg_t) flags, &answer); 1042 1042 1043 / / read the address if desired1043 /* Read the address if desired */ 1044 1044 if(!fromaddr || 1045 1045 (async_data_read_start(socket->phone, fromaddr, 1046 1046 *addrlen) == EOK)) { 1047 / / read the fragment lengths1047 /* Read the fragment lengths */ 1048 1048 if (async_data_read_start(socket->phone, lengths, 1049 1049 sizeof(int) * (fragments + 1)) == EOK) { 1050 1050 if (lengths[fragments] <= datalength) { 1051 1051 1052 / / read all fragments if long enough1052 /* Read all fragments if long enough */ 1053 1053 for (index = 0; index < fragments; 1054 1054 ++index) { … … 1065 1065 free(lengths); 1066 1066 } else { /* fragments == 1 */ 1067 / / request packet data1067 /* Request packet data */ 1068 1068 message_id = async_send_4(socket->phone, message, 1069 1069 (sysarg_t) socket->socket_id, 0, socket->service, 1070 1070 (sysarg_t) flags, &answer); 1071 1071 1072 / / read the address if desired1072 /* Read the address if desired */ 1073 1073 if (!fromaddr || 1074 1074 (async_data_read_start(socket->phone, fromaddr, 1075 1075 *addrlen) == EOK)) { 1076 / / read all if only one fragment1076 /* Read all if only one fragment */ 1077 1077 async_data_read_start(socket->phone, data, datalength); 1078 1078 } … … 1082 1082 result = (int) ipc_result; 1083 1083 if (result == EOK) { 1084 / / dequeue the received packet1084 /* Dequeue the received packet */ 1085 1085 dyn_fifo_pop(&socket->received); 1086 / / return read data length1086 /* Return read data length */ 1087 1087 retval = SOCKET_GET_READ_DATA_LENGTH(answer); 1088 / / set address length1088 /* Set address length */ 1089 1089 if (fromaddr && addrlen) 1090 1090 *addrlen = SOCKET_GET_ADDRESS_LENGTH(answer); … … 1114 1114 ssize_t recv(int socket_id, void *data, size_t datalength, int flags) 1115 1115 { 1116 / / without the address1116 /* Without the address */ 1117 1117 return recvfrom_core(NET_SOCKET_RECV, socket_id, data, datalength, 1118 1118 flags, NULL, NULL); … … 1146 1146 return NO_DATA; 1147 1147 1148 / / with the address1148 /* With the address */ 1149 1149 return recvfrom_core(NET_SOCKET_RECVFROM, socket_id, data, datalength, 1150 1150 flags, fromaddr, addrlen); … … 1181 1181 fibril_rwlock_read_lock(&socket_globals.lock); 1182 1182 1183 / / find the socket1183 /* Find the socket */ 1184 1184 socket = sockets_find(socket_get_sockets(), socket_id); 1185 1185 if (!socket) { … … 1188 1188 } 1189 1189 1190 / / request option value1190 /* Request option value */ 1191 1191 message_id = async_send_3(socket->phone, NET_SOCKET_GETSOCKOPT, 1192 1192 (sysarg_t) socket->socket_id, (sysarg_t) optname, socket->service, 1193 1193 NULL); 1194 1194 1195 / / read the length1195 /* Read the length */ 1196 1196 if (async_data_read_start(socket->phone, optlen, 1197 1197 sizeof(*optlen)) == EOK) { 1198 / / read the value1198 /* Read the value */ 1199 1199 async_data_read_start(socket->phone, value, *optlen); 1200 1200 } … … 1223 1223 size_t optlen) 1224 1224 { 1225 / / send the value1225 /* Send the value */ 1226 1226 return socket_send_data(socket_id, NET_SOCKET_SETSOCKOPT, 1227 1227 (sysarg_t) optname, value, optlen);
Note:
See TracChangeset
for help on using the changeset viewer.