Changes in uspace/lib/net/tl/socket_core.c [ccca251:5fe7692] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/net/tl/socket_core.c
rccca251 r5fe7692 91 91 int packet_id; 92 92 93 / * If bound */93 // if bound 94 94 if (socket->port) { 95 / * Release the port */95 // release the port 96 96 socket_port_release(global_sockets, socket); 97 97 } 98 98 99 / * Release all received packets */99 // release all received packets 100 100 while ((packet_id = dyn_fifo_pop(&socket->received)) >= 0) 101 101 pq_release_remote(packet_phone, packet_id); … … 166 166 int rc; 167 167 168 / * Create a wrapper */168 // create a wrapper 169 169 socket_ref = malloc(sizeof(*socket_ref)); 170 170 if (!socket_ref) … … 172 172 173 173 *socket_ref = socket; 174 / * Add the wrapper */174 // add the wrapper 175 175 rc = socket_port_map_add(&socket_port->map, key, key_length, 176 176 socket_ref); … … 206 206 int rc; 207 207 208 / * Create a wrapper */208 // create a wrapper 209 209 socket_port = malloc(sizeof(*socket_port)); 210 210 if (!socket_port) … … 221 221 goto fail; 222 222 223 / * Register the incoming port */223 // register the incomming port 224 224 rc = socket_ports_add(global_sockets, port, socket_port); 225 225 if (rc < 0) … … 277 277 278 278 address_in = (struct sockaddr_in *) addr; 279 / * Find the socket */279 // find the socket 280 280 socket = socket_cores_find(local_sockets, socket_id); 281 281 if (!socket) 282 282 return ENOTSOCK; 283 283 284 / * Bind a free port? */284 // bind a free port? 285 285 if (address_in->sin_port <= 0) 286 286 return socket_bind_free_port(global_sockets, socket, 287 287 free_ports_start, free_ports_end, last_used_port); 288 288 289 / * Try to find the port */289 // try to find the port 290 290 socket_port = socket_ports_find(global_sockets, 291 291 ntohs(address_in->sin_port)); 292 292 if (socket_port) { 293 / * Already used */293 // already used 294 294 return EADDRINUSE; 295 295 } 296 296 297 / * If bound */297 // if bound 298 298 if (socket->port) { 299 / * Release the port */299 // release the port 300 300 socket_port_release(global_sockets, socket); 301 301 } … … 333 333 int index; 334 334 335 / * From the last used one */335 // from the last used one 336 336 index = last_used_port; 337 337 … … 339 339 ++index; 340 340 341 / * Till the range end */341 // til the range end 342 342 if (index >= free_ports_end) { 343 / * Start from the range beginning */343 // start from the range beginning 344 344 index = free_ports_start - 1; 345 345 do { 346 346 ++index; 347 / * Till the last used one */347 // til the last used one 348 348 if (index >= last_used_port) { 349 / * None found */349 // none found 350 350 return ENOTCONN; 351 351 } 352 352 } while (socket_ports_find(global_sockets, index)); 353 353 354 / * Found, break immediately */354 // found, break immediately 355 355 break; 356 356 } … … 376 376 377 377 count = 0; 378 #if 0 379 socket_id = socket_globals.last_id; 380 #endif 378 // socket_id = socket_globals.last_id; 381 379 do { 382 380 if (count < SOCKET_ID_TRIES) { … … 386 384 socket_id = 1; 387 385 ++count; 388 / * Only this branch for last_id */386 // only this branch for last_id 389 387 } else { 390 388 if (socket_id < INT_MAX) { 391 389 ++ socket_id; 392 #if 0 393 } else if(socket_globals.last_id) { 394 socket_globals.last_id = 0; 395 socket_id = 1; 396 #endif 397 } else { 390 /* } else if(socket_globals.last_id) { 391 * socket_globals.last_id = 0; 392 * socket_id = 1; 393 */ } else { 398 394 return ELIMIT; 399 395 } … … 429 425 return EINVAL; 430 426 431 / * Store the socket */427 // store the socket 432 428 if (*socket_id <= 0) { 433 429 positive = (*socket_id == 0); … … 445 441 return ENOMEM; 446 442 447 / * Initialize */443 // initialize 448 444 socket->phone = app_phone; 449 445 socket->port = -1; … … 497 493 int accepted_id; 498 494 499 / * Find the socket */495 // find the socket 500 496 socket = socket_cores_find(local_sockets, socket_id); 501 497 if (!socket) 502 498 return ENOTSOCK; 503 499 504 / * Destroy all accepted sockets */500 // destroy all accepted sockets 505 501 while ((accepted_id = dyn_fifo_pop(&socket->accepted)) >= 0) 506 502 socket_destroy(packet_phone, accepted_id, local_sockets, … … 539 535 next_packet = pq_next(packet); 540 536 if (!next_packet) { 541 / * Write all if only one fragment */537 // write all if only one fragment 542 538 rc = data_reply(packet_get_data(packet), 543 539 packet_get_data_length(packet)); 544 540 if (rc != EOK) 545 541 return rc; 546 / * Store the total length */542 // store the total length 547 543 *length = packet_get_data_length(packet); 548 544 } else { 549 / * Count the packet fragments */545 // count the packet fragments 550 546 fragments = 1; 551 547 next_packet = pq_next(packet); … … 553 549 ++fragments; 554 550 555 / * Compute and store the fragment lengths */551 // compute and store the fragment lengths 556 552 lengths = (size_t *) malloc(sizeof(size_t) * fragments + 557 553 sizeof(size_t)); … … 569 565 } 570 566 571 / * Write the fragment lengths */567 // write the fragment lengths 572 568 rc = data_reply(lengths, sizeof(int) * (fragments + 1)); 573 569 if (rc != EOK) { … … 577 573 next_packet = packet; 578 574 579 / * Write the fragments */575 // write the fragments 580 576 for (index = 0; index < fragments; ++index) { 581 577 rc = data_reply(packet_get_data(next_packet), … … 588 584 } 589 585 590 / * Store the total length */586 // store the total length 591 587 *length = lengths[fragments]; 592 588 free(lengths); … … 640 636 return; 641 637 642 / * Find ports */638 // find ports 643 639 socket_port = socket_ports_find(global_sockets, socket->port); 644 640 if (socket_port) { 645 / * Find the socket */641 // find the socket 646 642 socket_ref = socket_port_map_find(&socket_port->map, 647 643 socket->key, socket->key_length); … … 650 646 --socket_port->count; 651 647 652 / * Release if empty */648 // release if empty 653 649 if (socket_port->count <= 0) { 654 / * Destroy the map */650 // destroy the map 655 651 socket_port_map_destroy(&socket_port->map, free); 656 / * Release the port */652 // release the port 657 653 socket_ports_exclude(global_sockets, 658 654 socket->port, free); 659 655 } else { 660 / * Remove */656 // remove 661 657 socket_port_map_exclude(&socket_port->map, 662 658 socket->key, socket->key_length, free); … … 689 685 int rc; 690 686 691 / * Find ports */687 // find ports 692 688 socket_port = socket_ports_find(global_sockets, port); 693 689 if (!socket_port) 694 690 return ENOENT; 695 691 696 / * Add the socket */692 // add the socket 697 693 rc = socket_port_add_core(socket_port, socket, key, key_length); 698 694 if (rc != EOK)
Note:
See TracChangeset
for help on using the changeset viewer.