Changeset a39cfb8 in mainline for uspace/lib/net/tl/socket_core.c
- Timestamp:
- 2011-04-14T07:54:33Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- e05d6c3
- Parents:
- 3f3afb9 (diff), 34e8bab (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. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/net/tl/socket_core.c
r3f3afb9 ra39cfb8 91 91 int packet_id; 92 92 93 / / if bound93 /* If bound */ 94 94 if (socket->port) { 95 / / release the port95 /* Release the port */ 96 96 socket_port_release(global_sockets, socket); 97 97 } 98 98 99 / / release all received packets99 /* 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 wrapper168 /* 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 wrapper174 /* 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 wrapper208 /* 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 incomming port223 /* Register the incoming 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 socket279 /* 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 port289 /* 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 used293 /* Already used */ 294 294 return EADDRINUSE; 295 295 } 296 296 297 / / if bound297 /* If bound */ 298 298 if (socket->port) { 299 / / release the port299 /* Release the port */ 300 300 socket_port_release(global_sockets, socket); 301 301 } … … 333 333 int index; 334 334 335 / / from the last used one335 /* From the last used one */ 336 336 index = last_used_port; 337 337 … … 339 339 ++index; 340 340 341 / / til the range end341 /* Till the range end */ 342 342 if (index >= free_ports_end) { 343 / / start from the range beginning343 /* Start from the range beginning */ 344 344 index = free_ports_start - 1; 345 345 do { 346 346 ++index; 347 / / til the last used one347 /* Till the last used one */ 348 348 if (index >= last_used_port) { 349 / / none found349 /* None found */ 350 350 return ENOTCONN; 351 351 } 352 352 } while (socket_ports_find(global_sockets, index)); 353 353 354 / / found, break immediately354 /* Found, break immediately */ 355 355 break; 356 356 } … … 376 376 377 377 count = 0; 378 // socket_id = socket_globals.last_id; 378 #if 0 379 socket_id = socket_globals.last_id; 380 #endif 379 381 do { 380 382 if (count < SOCKET_ID_TRIES) { … … 384 386 socket_id = 1; 385 387 ++count; 386 / / only this branch for last_id388 /* Only this branch for last_id */ 387 389 } else { 388 390 if (socket_id < INT_MAX) { 389 391 ++ socket_id; 390 /* } else if(socket_globals.last_id) { 391 * socket_globals.last_id = 0; 392 * socket_id = 1; 393 */ } else { 392 #if 0 393 } else if(socket_globals.last_id) { 394 socket_globals.last_id = 0; 395 socket_id = 1; 396 #endif 397 } else { 394 398 return ELIMIT; 395 399 } … … 425 429 return EINVAL; 426 430 427 / / store the socket431 /* Store the socket */ 428 432 if (*socket_id <= 0) { 429 433 positive = (*socket_id == 0); … … 441 445 return ENOMEM; 442 446 443 / / initialize447 /* Initialize */ 444 448 socket->phone = app_phone; 445 449 socket->port = -1; … … 493 497 int accepted_id; 494 498 495 / / find the socket499 /* Find the socket */ 496 500 socket = socket_cores_find(local_sockets, socket_id); 497 501 if (!socket) 498 502 return ENOTSOCK; 499 503 500 / / destroy all accepted sockets504 /* Destroy all accepted sockets */ 501 505 while ((accepted_id = dyn_fifo_pop(&socket->accepted)) >= 0) 502 506 socket_destroy(packet_phone, accepted_id, local_sockets, … … 535 539 next_packet = pq_next(packet); 536 540 if (!next_packet) { 537 / / write all if only one fragment541 /* Write all if only one fragment */ 538 542 rc = data_reply(packet_get_data(packet), 539 543 packet_get_data_length(packet)); 540 544 if (rc != EOK) 541 545 return rc; 542 / / store the total length546 /* Store the total length */ 543 547 *length = packet_get_data_length(packet); 544 548 } else { 545 / / count the packet fragments549 /* Count the packet fragments */ 546 550 fragments = 1; 547 551 next_packet = pq_next(packet); … … 549 553 ++fragments; 550 554 551 / / compute and store the fragment lengths555 /* Compute and store the fragment lengths */ 552 556 lengths = (size_t *) malloc(sizeof(size_t) * fragments + 553 557 sizeof(size_t)); … … 565 569 } 566 570 567 / / write the fragment lengths571 /* Write the fragment lengths */ 568 572 rc = data_reply(lengths, sizeof(int) * (fragments + 1)); 569 573 if (rc != EOK) { … … 573 577 next_packet = packet; 574 578 575 / / write the fragments579 /* Write the fragments */ 576 580 for (index = 0; index < fragments; ++index) { 577 581 rc = data_reply(packet_get_data(next_packet), … … 584 588 } 585 589 586 / / store the total length590 /* Store the total length */ 587 591 *length = lengths[fragments]; 588 592 free(lengths); … … 636 640 return; 637 641 638 / / find ports642 /* Find ports */ 639 643 socket_port = socket_ports_find(global_sockets, socket->port); 640 644 if (socket_port) { 641 / / find the socket645 /* Find the socket */ 642 646 socket_ref = socket_port_map_find(&socket_port->map, 643 647 socket->key, socket->key_length); … … 646 650 --socket_port->count; 647 651 648 / / release if empty652 /* Release if empty */ 649 653 if (socket_port->count <= 0) { 650 / / destroy the map654 /* Destroy the map */ 651 655 socket_port_map_destroy(&socket_port->map, free); 652 / / release the port656 /* Release the port */ 653 657 socket_ports_exclude(global_sockets, 654 658 socket->port, free); 655 659 } else { 656 / / remove660 /* Remove */ 657 661 socket_port_map_exclude(&socket_port->map, 658 662 socket->key, socket->key_length, free); … … 685 689 int rc; 686 690 687 / / find ports691 /* Find ports */ 688 692 socket_port = socket_ports_find(global_sockets, port); 689 693 if (!socket_port) 690 694 return ENOENT; 691 695 692 / / add the socket696 /* Add the socket */ 693 697 rc = socket_port_add_core(socket_port, socket, key, key_length); 694 698 if (rc != EOK)
Note:
See TracChangeset
for help on using the changeset viewer.