Changeset eaef141 in mainline
- Timestamp:
- 2010-12-28T13:10:37Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 80cd7cd
- Parents:
- 092e4f1 (diff), 097967b (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - Files:
-
- 1 added
- 1 deleted
- 15 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
boot/arch/ia64/Makefile.inc
r092e4f1 reaef141 34 34 ENDIANESS = LE 35 35 PAGE_SIZE = 16384 36 EXTRA_CFLAGS = -fno-unwind-tables -mfixed-range=f32-f127 -mno-pic 36 EXTRA_CFLAGS = -fno-unwind-tables -mfixed-range=f32-f127 -mno-pic -mno-sdata 37 37 38 38 RD_SRVS_NON_ESSENTIAL += -
uspace/app/netecho/netecho.c
r092e4f1 reaef141 32 32 33 33 /** @file 34 * Network echo application. 35 * Answers received packets. 34 * Network echo server. 35 * 36 * Sockets-based server that echoes incomming messages. If stream mode 37 * is selected, accepts incoming connections. 36 38 */ 37 39 38 #include < malloc.h>40 #include <assert.h> 39 41 #include <stdio.h> 42 #include <stdlib.h> 40 43 #include <str.h> 41 44 #include <task.h> … … 50 53 #include "print_error.h" 51 54 52 /** Network echo module name. */ 53 #define NAME "Network Echo" 55 #define NAME "netecho" 56 57 static int count = -1; 58 static int family = PF_INET; 59 static sock_type_t type = SOCK_DGRAM; 60 static uint16_t port = 7; 61 static int backlog = 3; 62 static size_t size = 1024; 63 static int verbose = 0; 64 65 static char *reply = NULL; 66 static size_t reply_length; 67 68 static char *data; 54 69 55 70 static void echo_print_help(void) 56 71 { 57 72 printf( 58 "Network Echo aplication\n" \ 59 "Usage: echo [options]\n" \ 60 "Where options are:\n" \ 61 "-b backlog | --backlog=size\n" \ 62 "\tThe size of the accepted sockets queue. Only for SOCK_STREAM. The default is 3.\n" \ 63 "\n" \ 64 "-c count | --count=count\n" \ 65 "\tThe number of received messages to handle. A negative number means infinity. The default is infinity.\n" \ 66 "\n" \ 67 "-f protocol_family | --family=protocol_family\n" \ 68 "\tThe listenning socket protocol family. Only the PF_INET and PF_INET6 are supported.\n" 69 "\n" \ 70 "-h | --help\n" \ 71 "\tShow this application help.\n" 72 "\n" \ 73 "-p port_number | --port=port_number\n" \ 74 "\tThe port number the application should listen at. The default is 7.\n" \ 75 "\n" \ 76 "-r reply_string | --reply=reply_string\n" \ 77 "\tThe constant reply string. The default is the original data received.\n" \ 78 "\n" \ 79 "-s receive_size | --size=receive_size\n" \ 80 "\tThe maximum receive data size the application should accept. The default is 1024 bytes.\n" \ 81 "\n" \ 82 "-t socket_type | --type=socket_type\n" \ 83 "\tThe listenning socket type. Only the SOCK_DGRAM and the SOCK_STREAM are supported.\n" \ 84 "\n" \ 85 "-v | --verbose\n" \ 86 "\tShow all output messages.\n" 73 "Network echo server\n" 74 "Usage: " NAME " [options]\n" 75 "Where options are:\n" 76 "-b backlog | --backlog=size\n" 77 "\tThe size of the accepted sockets queue. Only for SOCK_STREAM. " 78 "The default is 3.\n" 79 "\n" 80 "-c count | --count=count\n" 81 "\tThe number of received messages to handle. A negative number " 82 "means infinity. The default is infinity.\n" 83 "\n" 84 "-f protocol_family | --family=protocol_family\n" 85 "\tThe listenning socket protocol family. Only the PF_INET and " 86 "PF_INET6 are supported.\n" 87 "\n" 88 "-h | --help\n" 89 "\tShow this application help.\n" 90 "\n" 91 "-p port_number | --port=port_number\n" 92 "\tThe port number the application should listen at. The default " 93 "is 7.\n" 94 "\n" 95 "-r reply_string | --reply=reply_string\n" 96 "\tThe constant reply string. The default is the original data " 97 "received.\n" 98 "\n" 99 "-s receive_size | --size=receive_size\n" 100 "\tThe maximum receive data size the application should accept. " 101 "The default is 1024 bytes.\n" 102 "\n" 103 "-t socket_type | --type=socket_type\n" 104 "\tThe listenning socket type. Only the SOCK_DGRAM and the " 105 "SOCK_STREAM are supported.\n" 106 "\n" 107 "-v | --verbose\n" 108 "\tShow all output messages.\n" 87 109 ); 88 110 } 89 111 90 int main(int argc, char *argv[])112 static int netecho_parse_option(int argc, char *argv[], int *index) 91 113 { 92 size_t size = 1024;93 int verbose = 0;94 char *reply = NULL;95 sock_type_t type = SOCK_DGRAM;96 int count = -1;97 int family = PF_INET;98 uint16_t port = 7;99 int backlog = 3;100 101 socklen_t max_length = sizeof(struct sockaddr_in6);102 uint8_t address_data[max_length];103 struct sockaddr *address = (struct sockaddr *) address_data;104 struct sockaddr_in *address_in = (struct sockaddr_in *) address;105 struct sockaddr_in6 *address_in6 = (struct sockaddr_in6 *) address;106 socklen_t addrlen;107 char address_string[INET6_ADDRSTRLEN];108 uint8_t *address_start;109 int socket_id;110 int listening_id;111 char *data;112 size_t length;113 int index;114 size_t reply_length;115 114 int value; 116 115 int rc; 117 116 118 // parse the command line arguments 119 for (index = 1; index < argc; ++ index) { 120 if (argv[index][0] == '-') { 121 switch (argv[index][1]) { 122 case 'b': 123 rc = arg_parse_int(argc, argv, &index, &backlog, 0); 124 if (rc != EOK) 125 return rc; 126 break; 127 case 'c': 128 rc = arg_parse_int(argc, argv, &index, &count, 0); 129 if (rc != EOK) 130 return rc; 131 break; 132 case 'f': 133 rc = arg_parse_name_int(argc, argv, &index, &family, 0, socket_parse_protocol_family); 134 if (rc != EOK) 135 return rc; 136 break; 137 case 'h': 138 echo_print_help(); 139 return EOK; 140 break; 141 case 'p': 142 rc = arg_parse_int(argc, argv, &index, &value, 0); 143 if (rc != EOK) 144 return rc; 145 port = (uint16_t) value; 146 break; 147 case 'r': 148 rc = arg_parse_string(argc, argv, &index, &reply, 0); 149 if (rc != EOK) 150 return rc; 151 break; 152 case 's': 153 rc = arg_parse_int(argc, argv, &index, &value, 0); 154 if (rc != EOK) 155 return rc; 156 size = (value >= 0) ? (size_t) value : 0; 157 break; 158 case 't': 159 rc = arg_parse_name_int(argc, argv, &index, &value, 0, socket_parse_socket_type); 160 if (rc != EOK) 161 return rc; 162 type = (sock_type_t) value; 163 break; 164 case 'v': 165 verbose = 1; 166 break; 167 // long options with the double minus sign ('-') 168 case '-': 169 if (str_lcmp(argv[index] + 2, "backlog=", 6) == 0) { 170 rc = arg_parse_int(argc, argv, &index, &backlog, 8); 171 if (rc != EOK) 172 return rc; 173 } else if (str_lcmp(argv[index] + 2, "count=", 6) == 0) { 174 rc = arg_parse_int(argc, argv, &index, &count, 8); 175 if (rc != EOK) 176 return rc; 177 } else if (str_lcmp(argv[index] + 2, "family=", 7) == 0) { 178 rc = arg_parse_name_int(argc, argv, &index, &family, 9, socket_parse_protocol_family); 179 if (rc != EOK) 180 return rc; 181 } else if (str_lcmp(argv[index] + 2, "help", 5) == 0) { 182 echo_print_help(); 183 return EOK; 184 } else if (str_lcmp(argv[index] + 2, "port=", 5) == 0) { 185 rc = arg_parse_int(argc, argv, &index, &value, 7); 186 if (rc != EOK) 187 return rc; 188 port = (uint16_t) value; 189 } else if (str_lcmp(argv[index] + 2, "reply=", 6) == 0) { 190 rc = arg_parse_string(argc, argv, &index, &reply, 8); 191 if (rc != EOK) 192 return rc; 193 } else if (str_lcmp(argv[index] + 2, "size=", 5) == 0) { 194 rc = arg_parse_int(argc, argv, &index, &value, 7); 195 if (rc != EOK) 196 return rc; 197 size = (value >= 0) ? (size_t) value : 0; 198 } else if (str_lcmp(argv[index] + 2, "type=", 5) == 0) { 199 rc = arg_parse_name_int(argc, argv, &index, &value, 7, socket_parse_socket_type); 200 if (rc != EOK) 201 return rc; 202 type = (sock_type_t) value; 203 } else if (str_lcmp(argv[index] + 2, "verbose", 8) == 0) { 204 verbose = 1; 205 } else { 206 echo_print_help(); 207 return EINVAL; 208 } 209 break; 210 default: 211 echo_print_help(); 212 return EINVAL; 213 } 117 switch (argv[*index][1]) { 118 case 'b': 119 rc = arg_parse_int(argc, argv, index, &backlog, 0); 120 if (rc != EOK) 121 return rc; 122 break; 123 case 'c': 124 rc = arg_parse_int(argc, argv, index, &count, 0); 125 if (rc != EOK) 126 return rc; 127 break; 128 case 'f': 129 rc = arg_parse_name_int(argc, argv, index, &family, 0, 130 socket_parse_protocol_family); 131 if (rc != EOK) 132 return rc; 133 break; 134 case 'h': 135 echo_print_help(); 136 exit(0); 137 break; 138 case 'p': 139 rc = arg_parse_int(argc, argv, index, &value, 0); 140 if (rc != EOK) 141 return rc; 142 port = (uint16_t) value; 143 break; 144 case 'r': 145 rc = arg_parse_string(argc, argv, index, &reply, 0); 146 if (rc != EOK) 147 return rc; 148 break; 149 case 's': 150 rc = arg_parse_int(argc, argv, index, &value, 0); 151 if (rc != EOK) 152 return rc; 153 size = (value >= 0) ? (size_t) value : 0; 154 break; 155 case 't': 156 rc = arg_parse_name_int(argc, argv, index, &value, 0, 157 socket_parse_socket_type); 158 if (rc != EOK) 159 return rc; 160 type = (sock_type_t) value; 161 break; 162 case 'v': 163 verbose = 1; 164 break; 165 /* Long options with double dash */ 166 case '-': 167 if (str_lcmp(argv[*index] + 2, "backlog=", 6) == 0) { 168 rc = arg_parse_int(argc, argv, index, &backlog, 8); 169 if (rc != EOK) 170 return rc; 171 } else if (str_lcmp(argv[*index] + 2, "count=", 6) == 0) { 172 rc = arg_parse_int(argc, argv, index, &count, 8); 173 if (rc != EOK) 174 return rc; 175 } else if (str_lcmp(argv[*index] + 2, "family=", 7) == 0) { 176 rc = arg_parse_name_int(argc, argv, index, &family, 9, 177 socket_parse_protocol_family); 178 if (rc != EOK) 179 return rc; 180 } else if (str_lcmp(argv[*index] + 2, "help", 5) == 0) { 181 echo_print_help(); 182 return EOK; 183 } else if (str_lcmp(argv[*index] + 2, "port=", 5) == 0) { 184 rc = arg_parse_int(argc, argv, index, &value, 7); 185 if (rc != EOK) 186 return rc; 187 port = (uint16_t) value; 188 } else if (str_lcmp(argv[*index] + 2, "reply=", 6) == 0) { 189 rc = arg_parse_string(argc, argv, index, &reply, 8); 190 if (rc != EOK) 191 return rc; 192 } else if (str_lcmp(argv[*index] + 2, "size=", 5) == 0) { 193 rc = arg_parse_int(argc, argv, index, &value, 7); 194 if (rc != EOK) 195 return rc; 196 size = (value >= 0) ? (size_t) value : 0; 197 } else if (str_lcmp(argv[*index] + 2, "type=", 5) == 0) { 198 rc = arg_parse_name_int(argc, argv, index, &value, 7, 199 socket_parse_socket_type); 200 if (rc != EOK) 201 return rc; 202 type = (sock_type_t) value; 203 } else if (str_lcmp(argv[*index] + 2, "verbose", 8) == 0) { 204 verbose = 1; 214 205 } else { 215 206 echo_print_help(); 216 207 return EINVAL; 217 208 } 218 } 219 220 // check the buffer size 209 break; 210 default: 211 echo_print_help(); 212 return EINVAL; 213 } 214 215 return EOK; 216 } 217 218 /** Echo one message (accept one connection and echo message). 219 * 220 * @param listening_id Listening socket. 221 * @return EOK on success or negative error code. 222 */ 223 static int netecho_socket_process_message(int listening_id) 224 { 225 uint8_t address_buf[sizeof(struct sockaddr_in6)]; 226 227 socklen_t addrlen; 228 int socket_id; 229 ssize_t rcv_size; 230 size_t length; 231 uint8_t *address_start; 232 233 char address_string[INET6_ADDRSTRLEN]; 234 struct sockaddr_in *address_in = (struct sockaddr_in *) address_buf; 235 struct sockaddr_in6 *address_in6 = (struct sockaddr_in6 *) address_buf; 236 struct sockaddr *address = (struct sockaddr *) address_buf; 237 238 int rc; 239 240 if (type == SOCK_STREAM) { 241 /* Accept a socket if a stream socket is used */ 242 addrlen = sizeof(address_buf); 243 socket_id = accept(listening_id, (void *) address_buf, &addrlen); 244 if (socket_id <= 0) { 245 socket_print_error(stderr, socket_id, "Socket accept: ", "\n"); 246 } else { 247 if (verbose) 248 printf("Socket %d accepted\n", socket_id); 249 } 250 251 assert((size_t) addrlen <= sizeof(address_buf)); 252 } else { 253 socket_id = listening_id; 254 } 255 256 /* if the datagram socket is used or the stream socked was accepted */ 257 if (socket_id > 0) { 258 259 /* Receive a message to echo */ 260 rcv_size = recvfrom(socket_id, data, size, 0, address, 261 &addrlen); 262 if (rcv_size < 0) { 263 socket_print_error(stderr, rcv_size, "Socket receive: ", "\n"); 264 } else { 265 length = (size_t) rcv_size; 266 if (verbose) { 267 /* Print the header */ 268 269 /* Get the source port and prepare the address buffer */ 270 address_start = NULL; 271 switch (address->sa_family) { 272 case AF_INET: 273 port = ntohs(address_in->sin_port); 274 address_start = (uint8_t *) &address_in->sin_addr.s_addr; 275 break; 276 case AF_INET6: 277 port = ntohs(address_in6->sin6_port); 278 address_start = (uint8_t *) &address_in6->sin6_addr.s6_addr; 279 break; 280 default: 281 fprintf(stderr, "Address family %u (%#x) is not supported.\n", 282 address->sa_family, address->sa_family); 283 } 284 285 /* Parse source address */ 286 if (address_start) { 287 rc = inet_ntop(address->sa_family, address_start, address_string, sizeof(address_string)); 288 if (rc != EOK) { 289 fprintf(stderr, "Received address error %d\n", rc); 290 } else { 291 data[length] = '\0'; 292 printf("Socket %d received %zu bytes from %s:%d\n%s\n", 293 socket_id, length, address_string, port, data); 294 } 295 } 296 } 297 298 /* Answer the request either with the static reply or the original data */ 299 rc = sendto(socket_id, reply ? reply : data, reply ? reply_length : length, 0, address, addrlen); 300 if (rc != EOK) 301 socket_print_error(stderr, rc, "Socket send: ", "\n"); 302 } 303 304 /* Close accepted stream socket */ 305 if (type == SOCK_STREAM) { 306 rc = closesocket(socket_id); 307 if (rc != EOK) 308 socket_print_error(stderr, rc, "Close socket: ", "\n"); 309 } 310 311 } 312 313 return EOK; 314 } 315 316 317 int main(int argc, char *argv[]) 318 { 319 struct sockaddr *address;; 320 struct sockaddr_in address_in; 321 struct sockaddr_in6 address_in6; 322 socklen_t addrlen; 323 324 int listening_id; 325 int index; 326 int rc; 327 328 /* Parse command line arguments */ 329 for (index = 1; index < argc; ++index) { 330 if (argv[index][0] == '-') { 331 rc = netecho_parse_option(argc, argv, &index); 332 if (rc != EOK) 333 return rc; 334 } else { 335 echo_print_help(); 336 return EINVAL; 337 } 338 } 339 340 /* Check buffer size */ 221 341 if (size <= 0) { 222 342 fprintf(stderr, "Receive size too small (%zu). Using 1024 bytes instead.\n", size); 223 343 size = 1024; 224 344 } 225 // size plus the terminating null (\0) 345 346 /* size plus the terminating null character. */ 226 347 data = (char *) malloc(size + 1); 227 348 if (!data) { … … 230 351 } 231 352 232 / / set the reply size if set353 /* Set the reply size if set */ 233 354 reply_length = reply ? str_length(reply) : 0; 234 355 235 // prepare the address buffer 236 bzero(address_data, max_length); 356 /* Prepare the address buffer */ 237 357 switch (family) { 238 358 case PF_INET: 239 address_in->sin_family = AF_INET; 240 address_in->sin_port = htons(port); 241 addrlen = sizeof(struct sockaddr_in); 359 address_in.sin_family = AF_INET; 360 address_in.sin_port = htons(port); 361 address = (struct sockaddr *) &address_in; 362 addrlen = sizeof(address_in); 242 363 break; 243 364 case PF_INET6: 244 address_in6->sin6_family = AF_INET6; 245 address_in6->sin6_port = htons(port); 246 addrlen = sizeof(struct sockaddr_in6); 365 address_in6.sin6_family = AF_INET6; 366 address_in6.sin6_port = htons(port); 367 address = (struct sockaddr *) &address_in6; 368 addrlen = sizeof(address_in6); 247 369 break; 248 370 default: … … 251 373 } 252 374 253 / / get a listening socket375 /* Get a listening socket */ 254 376 listening_id = socket(family, type, 0); 255 377 if (listening_id < 0) { … … 258 380 } 259 381 260 / / if the stream socket is used382 /* if the stream socket is used */ 261 383 if (type == SOCK_STREAM) { 262 / / check the backlog384 /* Check backlog size */ 263 385 if (backlog <= 0) { 264 386 fprintf(stderr, "Accepted sockets queue size too small (%zu). Using 3 instead.\n", size); 265 387 backlog = 3; 266 388 } 267 // set the backlog 389 390 /* Set the backlog */ 268 391 rc = listen(listening_id, backlog); 269 392 if (rc != EOK) { … … 273 396 } 274 397 275 / / bind the listenning socket398 /* Bind the listening socket */ 276 399 rc = bind(listening_id, address, addrlen); 277 400 if (rc != EOK) { … … 283 406 printf("Socket %d listenning at %d\n", listening_id, port); 284 407 285 socket_id = listening_id;286 287 // do count times288 // or indefinitely if set to a negative value408 /* 409 * do count times 410 * or indefinitely if set to a negative value 411 */ 289 412 while (count) { 290 291 addrlen = max_length; 292 if (type == SOCK_STREAM) { 293 // acceept a socket if the stream socket is used 294 socket_id = accept(listening_id, address, &addrlen); 295 if (socket_id <= 0) { 296 socket_print_error(stderr, socket_id, "Socket accept: ", "\n"); 297 } else { 298 if (verbose) 299 printf("Socket %d accepted\n", socket_id); 300 } 301 } 302 303 // if the datagram socket is used or the stream socked was accepted 304 if (socket_id > 0) { 305 306 // receive an echo request 307 value = recvfrom(socket_id, data, size, 0, address, &addrlen); 308 if (value < 0) { 309 socket_print_error(stderr, value, "Socket receive: ", "\n"); 310 } else { 311 length = (size_t) value; 312 if (verbose) { 313 // print the header 314 315 // get the source port and prepare the address buffer 316 address_start = NULL; 317 switch (address->sa_family) { 318 case AF_INET: 319 port = ntohs(address_in->sin_port); 320 address_start = (uint8_t *) &address_in->sin_addr.s_addr; 321 break; 322 case AF_INET6: 323 port = ntohs(address_in6->sin6_port); 324 address_start = (uint8_t *) &address_in6->sin6_addr.s6_addr; 325 break; 326 default: 327 fprintf(stderr, "Address family %u (%#x) is not supported.\n", 328 address->sa_family, address->sa_family); 329 } 330 // parse the source address 331 if (address_start) { 332 rc = inet_ntop(address->sa_family, address_start, address_string, sizeof(address_string)); 333 if (rc != EOK) { 334 fprintf(stderr, "Received address error %d\n", rc); 335 } else { 336 data[length] = '\0'; 337 printf("Socket %d received %zu bytes from %s:%d\n%s\n", 338 socket_id, length, address_string, port, data); 339 } 340 } 341 } 342 343 // answer the request either with the static reply or the original data 344 rc = sendto(socket_id, reply ? reply : data, reply ? reply_length : length, 0, address, addrlen); 345 if (rc != EOK) 346 socket_print_error(stderr, rc, "Socket send: ", "\n"); 347 } 348 349 // close the accepted stream socket 350 if (type == SOCK_STREAM) { 351 rc = closesocket(socket_id); 352 if (rc != EOK) 353 socket_print_error(stderr, rc, "Close socket: ", "\n"); 354 } 355 356 } 357 358 // decrease the count if positive 413 rc = netecho_socket_process_message(listening_id); 414 if (rc != EOK) 415 break; 416 417 /* Decrease count if positive */ 359 418 if (count > 0) { 360 419 count--; 361 420 if (verbose) 362 printf("Waiting for next %d packet(s)\n", count);421 printf("Waiting for next %d message(s)\n", count); 363 422 } 364 423 } … … 367 426 printf("Closing the socket\n"); 368 427 369 / / close the listenning socket428 /* Close listenning socket */ 370 429 rc = closesocket(listening_id); 371 430 if (rc != EOK) { -
uspace/lib/c/Makefile
r092e4f1 reaef141 87 87 generic/ipc.c \ 88 88 generic/async.c \ 89 generic/async_ rel.c \89 generic/async_sess.c \ 90 90 generic/loader.c \ 91 91 generic/getopt.c \ -
uspace/lib/c/generic/async.c
r092e4f1 reaef141 749 749 return ENOMEM; 750 750 } 751 752 _async_sess_init(); 751 753 752 754 return 0; -
uspace/lib/c/generic/libc.c
r092e4f1 reaef141 50 50 #include <ipc/ipc.h> 51 51 #include <async.h> 52 #include <async_rel.h>53 52 #include <as.h> 54 53 #include <loader/pcb.h> … … 66 65 __heap_init(); 67 66 __async_init(); 68 (void) async_rel_init();69 67 fibril_t *fibril = fibril_setup(); 70 68 __tcb_set(fibril->tcb); -
uspace/lib/c/generic/net/icmp_api.c
r092e4f1 reaef141 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
r092e4f1 reaef141 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
r092e4f1 reaef141 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
r092e4f1 reaef141 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
r092e4f1 reaef141 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); … … 966 966 * read. The actual address length is set. Used only if 967 967 * fromaddr is not NULL. 968 * @return EOK on success. 968 * @return Positive received message size in bytes on success. 969 * @return Zero if no more data (other side closed the connection). 969 970 * @return ENOTSOCK if the socket is not found. 970 971 * @return EBADMEM if the data parameter is NULL. … … 972 973 * @return Other error codes as defined for the spcific message. 973 974 */ 974 static int975 static ssize_t 975 976 recvfrom_core(sysarg_t message, int socket_id, void *data, size_t datalength, 976 977 int flags, struct sockaddr *fromaddr, socklen_t *addrlen) … … 984 985 size_t index; 985 986 ipc_call_t answer; 987 ssize_t retval; 986 988 987 989 if (!data) … … 996 998 fibril_rwlock_read_lock(&socket_globals.lock); 997 999 998 / / find the socket1000 /* Find the socket */ 999 1001 socket = sockets_find(socket_get_sockets(), socket_id); 1000 1002 if (!socket) { … … 1004 1006 1005 1007 fibril_mutex_lock(&socket->receive_lock); 1006 / / wait for a received packet1008 /* Wait for a received packet */ 1007 1009 ++socket->blocked; 1008 while ((result = dyn_fifo_value(&socket->received)) < =0) {1010 while ((result = dyn_fifo_value(&socket->received)) < 0) { 1009 1011 fibril_rwlock_read_unlock(&socket_globals.lock); 1010 1012 fibril_condvar_wait(&socket->receive_signal, 1011 1013 &socket->receive_lock); 1012 1014 1013 / / drop the receive lock to avoid deadlock1015 /* Drop the receive lock to avoid deadlock */ 1014 1016 fibril_mutex_unlock(&socket->receive_lock); 1015 1017 fibril_rwlock_read_lock(&socket_globals.lock); … … 1019 1021 fragments = (size_t) result; 1020 1022 1021 // prepare lengths if more fragments 1023 if (fragments == 0) { 1024 /* No more data, other side has closed the connection. */ 1025 fibril_mutex_unlock(&socket->receive_lock); 1026 fibril_rwlock_read_unlock(&socket_globals.lock); 1027 return 0; 1028 } 1029 1030 /* Prepare lengths if more fragments */ 1022 1031 if (fragments > 1) { 1023 1032 lengths = (size_t *) malloc(sizeof(size_t) * fragments + … … 1029 1038 } 1030 1039 1031 / / request packet data1040 /* Request packet data */ 1032 1041 message_id = async_send_4(socket->phone, message, 1033 1042 (sysarg_t) socket->socket_id, 0, socket->service, 1034 1043 (sysarg_t) flags, &answer); 1035 1044 1036 / / read the address if desired1045 /* Read the address if desired */ 1037 1046 if(!fromaddr || 1038 1047 (async_data_read_start(socket->phone, fromaddr, 1039 1048 *addrlen) == EOK)) { 1040 / / read the fragment lengths1049 /* Read the fragment lengths */ 1041 1050 if (async_data_read_start(socket->phone, lengths, 1042 1051 sizeof(int) * (fragments + 1)) == EOK) { 1043 1052 if (lengths[fragments] <= datalength) { 1044 1053 1045 / / read all fragments if long enough1054 /* Read all fragments if long enough */ 1046 1055 for (index = 0; index < fragments; 1047 1056 ++index) { … … 1057 1066 1058 1067 free(lengths); 1059 } else { 1060 / / request packet data1068 } else { /* fragments == 1 */ 1069 /* Request packet data */ 1061 1070 message_id = async_send_4(socket->phone, message, 1062 1071 (sysarg_t) socket->socket_id, 0, socket->service, 1063 1072 (sysarg_t) flags, &answer); 1064 1073 1065 / / read the address if desired1074 /* Read the address if desired */ 1066 1075 if (!fromaddr || 1067 1076 (async_data_read_start(socket->phone, fromaddr, 1068 1077 *addrlen) == EOK)) { 1069 / / read all if only one fragment1078 /* Read all if only one fragment */ 1070 1079 async_data_read_start(socket->phone, data, datalength); 1071 1080 } … … 1075 1084 result = (int) ipc_result; 1076 1085 if (result == EOK) { 1077 / / dequeue the received packet1086 /* Dequeue the received packet */ 1078 1087 dyn_fifo_pop(&socket->received); 1079 / / return read data length1080 re sult= SOCKET_GET_READ_DATA_LENGTH(answer);1081 / / set address length1088 /* Return read data length */ 1089 retval = SOCKET_GET_READ_DATA_LENGTH(answer); 1090 /* Set address length */ 1082 1091 if (fromaddr && addrlen) 1083 1092 *addrlen = SOCKET_GET_ADDRESS_LENGTH(answer); 1093 } else { 1094 retval = (ssize_t) result; 1084 1095 } 1085 1096 1086 1097 fibril_mutex_unlock(&socket->receive_lock); 1087 1098 fibril_rwlock_read_unlock(&socket_globals.lock); 1088 return re sult;1099 return retval; 1089 1100 } 1090 1101 … … 1095 1106 * @param[in] datalength The data length. 1096 1107 * @param[in] flags Various receive flags. 1097 * @return EOK on success. 1108 * @return Positive received message size in bytes on success. 1109 * @return Zero if no more data (other side closed the connection). 1098 1110 * @return ENOTSOCK if the socket is not found. 1099 1111 * @return EBADMEM if the data parameter is NULL. … … 1102 1114 * message. 1103 1115 */ 1104 int recv(int socket_id, void *data, size_t datalength, int flags)1105 { 1106 / / without the address1116 ssize_t recv(int socket_id, void *data, size_t datalength, int flags) 1117 { 1118 /* Without the address */ 1107 1119 return recvfrom_core(NET_SOCKET_RECV, socket_id, data, datalength, 1108 1120 flags, NULL, NULL); … … 1118 1130 * @param[in,out] addrlen The address length. The maximum address length is 1119 1131 * read. The actual address length is set. 1120 * @return EOK on success. 1132 * @return Positive received message size in bytes on success. 1133 * @return Zero if no more data (other side closed the connection). 1121 1134 * @return ENOTSOCK if the socket is not found. 1122 1135 * @return EBADMEM if the data or fromaddr parameter is NULL. … … 1125 1138 * message. 1126 1139 */ 1127 int1140 ssize_t 1128 1141 recvfrom(int socket_id, void *data, size_t datalength, int flags, 1129 1142 struct sockaddr *fromaddr, socklen_t *addrlen) … … 1135 1148 return NO_DATA; 1136 1149 1137 / / with the address1150 /* With the address */ 1138 1151 return recvfrom_core(NET_SOCKET_RECVFROM, socket_id, data, datalength, 1139 1152 flags, fromaddr, addrlen); … … 1170 1183 fibril_rwlock_read_lock(&socket_globals.lock); 1171 1184 1172 / / find the socket1185 /* Find the socket */ 1173 1186 socket = sockets_find(socket_get_sockets(), socket_id); 1174 1187 if (!socket) { … … 1177 1190 } 1178 1191 1179 / / request option value1192 /* Request option value */ 1180 1193 message_id = async_send_3(socket->phone, NET_SOCKET_GETSOCKOPT, 1181 1194 (sysarg_t) socket->socket_id, (sysarg_t) optname, socket->service, 1182 1195 NULL); 1183 1196 1184 / / read the length1197 /* Read the length */ 1185 1198 if (async_data_read_start(socket->phone, optlen, 1186 1199 sizeof(*optlen)) == EOK) { 1187 / / read the value1200 /* Read the value */ 1188 1201 async_data_read_start(socket->phone, value, *optlen); 1189 1202 } … … 1212 1225 size_t optlen) 1213 1226 { 1214 / / send the value1227 /* Send the value */ 1215 1228 return socket_send_data(socket_id, NET_SOCKET_SETSOCKOPT, 1216 1229 (sysarg_t) optname, value, optlen); -
uspace/lib/c/include/async.h
r092e4f1 reaef141 37 37 38 38 #include <ipc/ipc.h> 39 #include <async_sess.h> 39 40 #include <fibril.h> 40 41 #include <sys/time.h> -
uspace/lib/c/include/async_sess.h
r092e4f1 reaef141 33 33 */ 34 34 35 #ifndef LIBC_ASYNC_ REL_H_36 #define LIBC_ASYNC_ REL_H_35 #ifndef LIBC_ASYNC_SESS_H_ 36 #define LIBC_ASYNC_SESS_H_ 37 37 38 extern int async_rel_init(void); 39 extern int async_relation_create(int); 40 extern void async_relation_destroy(int, int); 38 #include <adt/list.h> 39 40 typedef struct { 41 int sess_phone; /**< Phone for cloning off the connections. */ 42 link_t conn_head; /**< List of open data connections. */ 43 link_t sess_link; /**< Link in global list of open sessions. */ 44 } async_sess_t; 45 46 extern void _async_sess_init(void); 47 extern void async_session_create(async_sess_t *, int); 48 extern void async_session_destroy(async_sess_t *); 49 extern int async_exchange_begin(async_sess_t *); 50 extern void async_exchange_end(async_sess_t *, int); 41 51 42 52 #endif -
uspace/lib/c/include/net/socket.h
r092e4f1 reaef141 60 60 extern int sendto(int, const void *, size_t, int, const struct sockaddr *, 61 61 socklen_t); 62 extern int recv(int, void *, size_t, int);63 extern int recvfrom(int, void *, size_t, int, struct sockaddr *, socklen_t *);62 extern ssize_t recv(int, void *, size_t, int); 63 extern ssize_t recvfrom(int, void *, size_t, int, struct sockaddr *, socklen_t *); 64 64 extern int getsockopt(int, int, int, void *, size_t *); 65 65 extern int setsockopt(int, int, int, const void *, size_t); -
uspace/srv/net/tl/tcp/tcp.c
r092e4f1 reaef141 205 205 static int tcp_queue_received_packet(socket_core_t *, tcp_socket_data_t *, 206 206 packet_t *, int, size_t); 207 static void tcp_queue_received_end_of_data(socket_core_t *socket); 207 208 208 209 static int tcp_received_msg(device_id_t, packet_t *, services_t, services_t); … … 504 505 size_t offset; 505 506 uint32_t new_sequence_number; 507 bool forced_ack; 506 508 int rc; 507 509 … … 512 514 assert(packet); 513 515 516 forced_ack = false; 517 514 518 new_sequence_number = ntohl(header->sequence_number); 515 519 old_incoming = socket_data->next_incoming; 516 520 517 if (header->finalize) 518 socket_data->fin_incoming = new_sequence_number; 521 if (header->finalize) { 522 socket_data->fin_incoming = new_sequence_number + 523 total_length - TCP_HEADER_LENGTH(header); 524 } 519 525 520 526 /* Trim begining if containing expected data */ … … 760 766 /* Release duplicite or restricted */ 761 767 pq_release_remote(tcp_globals.net_phone, packet_get_id(packet)); 762 } 763 764 /* Change state according to the acknowledging incoming fin */ 765 if (IS_IN_INTERVAL_OVERFLOW(old_incoming, socket_data->fin_incoming, 766 socket_data->next_incoming)) { 768 forced_ack = true; 769 } 770 771 /* If next in sequence is an incoming FIN */ 772 if (socket_data->next_incoming == socket_data->fin_incoming) { 773 /* Advance sequence number */ 774 socket_data->next_incoming += 1; 775 776 /* Handle FIN */ 767 777 switch (socket_data->state) { 768 778 case TCP_SOCKET_FIN_WAIT_1: … … 771 781 socket_data->state = TCP_SOCKET_CLOSING; 772 782 break; 773 /*case TCP_ESTABLISHED:*/ 783 case TCP_SOCKET_ESTABLISHED: 784 /* Queue end-of-data marker on the socket. */ 785 tcp_queue_received_end_of_data(socket); 786 socket_data->state = TCP_SOCKET_CLOSE_WAIT; 787 break; 774 788 default: 775 789 socket_data->state = TCP_SOCKET_CLOSE_WAIT; … … 779 793 780 794 packet = tcp_get_packets_to_send(socket, socket_data); 781 if (!packet ) {795 if (!packet && (socket_data->next_incoming != old_incoming || forced_ack)) { 782 796 /* Create the notification packet */ 783 797 rc = tcp_create_notification_packet(&packet, socket, … … 835 849 836 850 return EOK; 851 } 852 853 /** Queue end-of-data marker on the socket. 854 * 855 * Next element in the sequence space is FIN. Queue end-of-data marker 856 * on the socket. 857 * 858 * @param socket Socket 859 */ 860 static void tcp_queue_received_end_of_data(socket_core_t *socket) 861 { 862 assert(socket != NULL); 863 864 /* Notify the destination socket */ 865 async_msg_5(socket->phone, NET_SOCKET_RECEIVED, 866 (sysarg_t) socket->socket_id, 867 0, 0, 0, 868 (sysarg_t) 0 /* 0 fragments == no more data */); 837 869 } 838 870 … … 2212 2244 2213 2245 tcp_prepare_operation_header(socket, socket_data, header, 0, 0); 2214 rc = tcp_queue_packet(socket, socket_data, packet, 0);2246 rc = tcp_queue_packet(socket, socket_data, packet, total_length); 2215 2247 if (rc != EOK) 2216 2248 return rc; -
uspace/srv/vfs/vfs.h
r092e4f1 reaef141 34 34 #define VFS_VFS_H_ 35 35 36 #include <async.h> 36 37 #include <ipc/ipc.h> 37 38 #include <adt/list.h> … … 53 54 vfs_info_t vfs_info; 54 55 fs_handle_t fs_handle; 55 fibril_mutex_t phone_lock; 56 sysarg_t phone; 56 async_sess_t session; 57 57 } fs_info_t; 58 58 -
uspace/srv/vfs/vfs_register.c
r092e4f1 reaef141 39 39 #include <ipc/services.h> 40 40 #include <async.h> 41 #include <async_rel.h>42 41 #include <fibril.h> 43 42 #include <fibril_synch.h> … … 111 110 void vfs_register(ipc_callid_t rid, ipc_call_t *request) 112 111 { 112 int phone; 113 113 114 dprintf("Processing VFS_REGISTER request received from %p.\n", 114 115 request->in_phone_hash); … … 136 137 137 138 link_initialize(&fs_info->fs_link); 138 fibril_mutex_initialize(&fs_info->phone_lock);139 139 fs_info->vfs_info = *vfs_info; 140 140 free(vfs_info); … … 186 186 return; 187 187 } 188 fs_info->phone = IPC_GET_ARG5(call); 188 189 phone = IPC_GET_ARG5(call); 190 async_session_create(&fs_info->session, phone); 189 191 ipc_answer_0(callid, EOK); 190 192 … … 200 202 list_remove(&fs_info->fs_link); 201 203 fibril_mutex_unlock(&fs_head_lock); 202 ipc_hangup(fs_info->phone); 204 async_session_destroy(&fs_info->session); 205 ipc_hangup(phone); 203 206 free(fs_info); 204 207 ipc_answer_0(callid, EINVAL); … … 214 217 list_remove(&fs_info->fs_link); 215 218 fibril_mutex_unlock(&fs_head_lock); 216 ipc_hangup(fs_info->phone); 219 async_session_destroy(&fs_info->session); 220 ipc_hangup(phone); 217 221 free(fs_info); 218 222 ipc_answer_0(callid, EINVAL); … … 269 273 if (fs->fs_handle == handle) { 270 274 fibril_mutex_unlock(&fs_head_lock); 271 fibril_mutex_lock(&fs->phone_lock); 272 phone = async_relation_create(fs->phone); 273 fibril_mutex_unlock(&fs->phone_lock); 275 phone = async_exchange_begin(&fs->session); 274 276 275 277 assert(phone > 0); … … 295 297 if (fs->fs_handle == handle) { 296 298 fibril_mutex_unlock(&fs_head_lock); 297 fibril_mutex_lock(&fs->phone_lock); 298 async_relation_destroy(fs->phone, phone); 299 fibril_mutex_unlock(&fs->phone_lock); 299 async_exchange_end(&fs->session, phone); 300 300 return; 301 301 }
Note:
See TracChangeset
for help on using the changeset viewer.