Changes in uspace/srv/net/tl/tcp/tcp.c [472020fc:0578271] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/net/tl/tcp/tcp.c
r472020fc r0578271 28 28 29 29 /** @addtogroup tcp 30 * 30 * @{ 31 31 */ 32 32 33 33 /** @file 34 * 35 * 34 * TCP module implementation. 35 * @see tcp.h 36 36 */ 37 38 #include "tcp.h" 39 #include "tcp_header.h" 40 #include "tcp_module.h" 37 41 38 42 #include <assert.h> … … 43 47 #include <stdio.h> 44 48 #include <errno.h> 45 #include <err.h>46 49 47 50 #include <ipc/ipc.h> … … 72 75 #include <tl_interface.h> 73 76 74 #include "tcp.h"75 #include "tcp_header.h"76 #include "tcp_module.h"77 78 77 /** TCP module name. */ 79 78 #define NAME "TCP protocol" … … 110 109 111 110 /** Returns a value indicating whether the value is in the interval respecting 112 * 111 * the possible overflow. 113 112 * 114 * The high end and/or the value may overflow, be lower than the low value. 115 * @param[in] lower The last value before the interval. 116 * @param[in] value The value to be checked. 117 * @param[in] higher_equal The last value in the interval. 113 * The high end and/or the value may overflow, be lower than the low value. 114 * 115 * @param[in] lower The last value before the interval. 116 * @param[in] value The value to be checked. 117 * @param[in] higher_equal The last value in the interval. 118 118 */ 119 119 #define IS_IN_INTERVAL_OVERFLOW(lower, value, higher_equal) \ … … 165 165 }; 166 166 167 /** Releases the packet and returns the result. 168 * @param[in] packet The packet queue to be released. 169 * @param[in] result The result to be returned. 170 * @return The result parameter. 171 */ 172 int tcp_release_and_return(packet_t packet, int result); 173 174 void tcp_prepare_operation_header(socket_core_ref socket, 175 tcp_socket_data_ref socket_data, tcp_header_ref header, int synchronize, 176 int finalize); 177 int tcp_prepare_timeout(int (*timeout_function)(void *tcp_timeout_t), 178 socket_core_ref socket, tcp_socket_data_ref socket_data, 179 size_t sequence_number, tcp_socket_state_t state, suseconds_t timeout, 180 int globals_read_only); 181 void tcp_free_socket_data(socket_core_ref socket); 182 183 int tcp_timeout(void *data); 184 185 int tcp_release_after_timeout(void *data); 186 187 int tcp_process_packet(device_id_t device_id, packet_t packet, 188 services_t error); 189 int tcp_connect_core(socket_core_ref socket, socket_cores_ref local_sockets, 190 struct sockaddr *addr, socklen_t addrlen); 191 int tcp_queue_prepare_packet(socket_core_ref socket, 192 tcp_socket_data_ref socket_data, packet_t packet, size_t data_length); 193 int tcp_queue_packet(socket_core_ref socket, tcp_socket_data_ref socket_data, 194 packet_t packet, size_t data_length); 195 packet_t tcp_get_packets_to_send(socket_core_ref socket, 196 tcp_socket_data_ref socket_data); 197 void tcp_send_packets(device_id_t device_id, packet_t packet); 198 199 void tcp_process_acknowledgement(socket_core_ref socket, 200 tcp_socket_data_ref socket_data, tcp_header_ref header); 201 packet_t tcp_send_prepare_packet(socket_core_ref socket, 202 tcp_socket_data_ref socket_data, packet_t packet, size_t data_length, 203 size_t sequence_number); 204 packet_t tcp_prepare_copy(socket_core_ref socket, 205 tcp_socket_data_ref socket_data, packet_t packet, size_t data_length, 206 size_t sequence_number); 207 void tcp_retransmit_packet(socket_core_ref socket, 208 tcp_socket_data_ref socket_data, size_t sequence_number); 209 int tcp_create_notification_packet(packet_t * packet, socket_core_ref socket, 210 tcp_socket_data_ref socket_data, int synchronize, int finalize); 211 void tcp_refresh_socket_data(tcp_socket_data_ref socket_data); 212 213 void tcp_initialize_socket_data(tcp_socket_data_ref socket_data); 214 215 int tcp_process_listen(socket_core_ref listening_socket, 216 tcp_socket_data_ref listening_socket_data, tcp_header_ref header, 217 packet_t packet, struct sockaddr *src, struct sockaddr *dest, 218 size_t addrlen); 219 int tcp_process_syn_sent(socket_core_ref socket, 220 tcp_socket_data_ref socket_data, tcp_header_ref header, packet_t packet); 221 int tcp_process_syn_received(socket_core_ref socket, 222 tcp_socket_data_ref socket_data, tcp_header_ref header, packet_t packet); 223 int tcp_process_established(socket_core_ref socket, 224 tcp_socket_data_ref socket_data, tcp_header_ref header, packet_t packet, 225 int fragments, size_t total_length); 226 int tcp_queue_received_packet(socket_core_ref socket, 227 tcp_socket_data_ref socket_data, packet_t packet, int fragments, 228 size_t total_length); 229 230 int tcp_received_msg(device_id_t device_id, packet_t packet, 231 services_t receiver, services_t error); 232 int tcp_process_client_messages(ipc_callid_t callid, ipc_call_t call); 233 234 int tcp_listen_message(socket_cores_ref local_sockets, int socket_id, 235 int backlog); 236 int tcp_connect_message(socket_cores_ref local_sockets, int socket_id, 237 struct sockaddr *addr, socklen_t addrlen); 238 int tcp_recvfrom_message(socket_cores_ref local_sockets, int socket_id, 239 int flags, size_t * addrlen); 240 int tcp_send_message(socket_cores_ref local_sockets, int socket_id, 241 int fragments, size_t * data_fragment_size, int flags); 242 int tcp_accept_message(socket_cores_ref local_sockets, int socket_id, 243 int new_socket_id, size_t * data_fragment_size, size_t * addrlen); 244 int tcp_close_message(socket_cores_ref local_sockets, int socket_id); 167 static int tcp_release_and_return(packet_t, int); 168 static void tcp_prepare_operation_header(socket_core_ref, tcp_socket_data_ref, 169 tcp_header_ref, int synchronize, int); 170 static int tcp_prepare_timeout(int (*)(void *), socket_core_ref, 171 tcp_socket_data_ref, size_t, tcp_socket_state_t, suseconds_t, int); 172 static void tcp_free_socket_data(socket_core_ref); 173 174 static int tcp_timeout(void *); 175 176 static int tcp_release_after_timeout(void *); 177 178 static int tcp_process_packet(device_id_t, packet_t, services_t); 179 static int tcp_connect_core(socket_core_ref, socket_cores_ref, 180 struct sockaddr *, socklen_t); 181 static int tcp_queue_prepare_packet(socket_core_ref, tcp_socket_data_ref, 182 packet_t, size_t); 183 static int tcp_queue_packet(socket_core_ref, tcp_socket_data_ref, packet_t, 184 size_t); 185 static packet_t tcp_get_packets_to_send(socket_core_ref, tcp_socket_data_ref); 186 static void tcp_send_packets(device_id_t, packet_t); 187 188 static void tcp_process_acknowledgement(socket_core_ref, tcp_socket_data_ref, 189 tcp_header_ref); 190 static packet_t tcp_send_prepare_packet(socket_core_ref, tcp_socket_data_ref, 191 packet_t, size_t, size_t); 192 static packet_t tcp_prepare_copy(socket_core_ref, tcp_socket_data_ref, packet_t, 193 size_t, size_t); 194 /* static */ void tcp_retransmit_packet(socket_core_ref, tcp_socket_data_ref, 195 size_t); 196 static int tcp_create_notification_packet(packet_t *, socket_core_ref, 197 tcp_socket_data_ref, int, int); 198 static void tcp_refresh_socket_data(tcp_socket_data_ref); 199 200 static void tcp_initialize_socket_data(tcp_socket_data_ref); 201 202 static int tcp_process_listen(socket_core_ref, tcp_socket_data_ref, 203 tcp_header_ref, packet_t, struct sockaddr *, struct sockaddr *, size_t); 204 static int tcp_process_syn_sent(socket_core_ref, tcp_socket_data_ref, 205 tcp_header_ref, packet_t); 206 static int tcp_process_syn_received(socket_core_ref, tcp_socket_data_ref, 207 tcp_header_ref, packet_t); 208 static int tcp_process_established(socket_core_ref, tcp_socket_data_ref, 209 tcp_header_ref, packet_t, int, size_t); 210 static int tcp_queue_received_packet(socket_core_ref, tcp_socket_data_ref, 211 packet_t, int, size_t); 212 213 static int tcp_received_msg(device_id_t, packet_t, services_t, services_t); 214 static int tcp_process_client_messages(ipc_callid_t, ipc_call_t); 215 216 static int tcp_listen_message(socket_cores_ref, int, int); 217 static int tcp_connect_message(socket_cores_ref, int, struct sockaddr *, 218 socklen_t); 219 static int tcp_recvfrom_message(socket_cores_ref, int, int, size_t *); 220 static int tcp_send_message(socket_cores_ref, int, int, size_t *, int); 221 static int tcp_accept_message(socket_cores_ref, int, int, size_t *, size_t *); 222 static int tcp_close_message(socket_cores_ref, int); 245 223 246 224 /** TCP global data. */ 247 225 tcp_globals_t tcp_globals; 248 226 227 /** Initializes the TCP module. 228 * 229 * @param[in] client_connection The client connection processing function. The 230 * module skeleton propagates its own one. 231 * @returns EOK on success. 232 * @returns ENOMEM if there is not enough memory left. 233 */ 249 234 int tcp_initialize(async_client_conn_t client_connection) 250 235 { 251 ERROR_DECLARE;236 int rc; 252 237 253 238 assert(client_connection); … … 260 245 tcp_globals.ip_phone = ip_bind_service(SERVICE_IP, IPPROTO_TCP, 261 246 SERVICE_TCP, client_connection); 262 if (tcp_globals.ip_phone < 0) 247 if (tcp_globals.ip_phone < 0) { 248 fibril_rwlock_write_unlock(&tcp_globals.lock); 263 249 return tcp_globals.ip_phone; 250 } 264 251 265 ERROR_PROPAGATE(socket_ports_initialize(&tcp_globals.sockets)); 266 if (ERROR_OCCURRED(packet_dimensions_initialize( 267 &tcp_globals.dimensions))) { 252 rc = socket_ports_initialize(&tcp_globals.sockets); 253 if (rc != EOK) 254 goto out; 255 256 rc = packet_dimensions_initialize(&tcp_globals.dimensions); 257 if (rc != EOK) { 268 258 socket_ports_destroy(&tcp_globals.sockets); 269 return ERROR_CODE;259 goto out; 270 260 } 271 261 272 262 tcp_globals.last_used_port = TCP_FREE_PORTS_START - 1; 263 264 out: 273 265 fibril_rwlock_write_unlock(&tcp_globals.lock); 274 275 return EOK; 266 return rc; 276 267 } 277 268 … … 280 271 services_t error) 281 272 { 282 ERROR_DECLARE;273 int rc; 283 274 284 275 if (receiver != SERVICE_TCP) … … 286 277 287 278 fibril_rwlock_write_lock(&tcp_globals.lock); 288 if (ERROR_OCCURRED(tcp_process_packet(device_id, packet, error))) 279 rc = tcp_process_packet(device_id, packet, error); 280 if (rc != EOK) 289 281 fibril_rwlock_write_unlock(&tcp_globals.lock); 290 282 291 printf("receive %d \n", ERROR_CODE);292 293 return ERROR_CODE;283 printf("receive %d \n", rc); 284 285 return rc; 294 286 } 295 287 296 288 int tcp_process_packet(device_id_t device_id, packet_t packet, services_t error) 297 289 { 298 ERROR_DECLARE;299 300 290 size_t length; 301 291 size_t offset; … … 313 303 struct sockaddr *dest; 314 304 size_t addrlen; 315 316 if (error) { 317 switch (error) { 318 case SERVICE_ICMP: 319 // process error 320 result = icmp_client_process_packet(packet, &type, 321 &code, NULL, NULL); 322 if (result < 0) 323 return tcp_release_and_return(packet, result); 324 325 length = (size_t) result; 326 if (ERROR_OCCURRED(packet_trim(packet, length, 0))) { 327 return tcp_release_and_return(packet, 328 ERROR_CODE); 329 } 330 break; 331 332 default: 333 return tcp_release_and_return(packet, ENOTSUP); 334 } 305 int rc; 306 307 switch (error) { 308 case SERVICE_NONE: 309 break; 310 case SERVICE_ICMP: 311 // process error 312 result = icmp_client_process_packet(packet, &type, &code, NULL, 313 NULL); 314 if (result < 0) 315 return tcp_release_and_return(packet, result); 316 317 length = (size_t) result; 318 rc = packet_trim(packet, length, 0); 319 if (rc != EOK) 320 return tcp_release_and_return(packet, rc); 321 break; 322 default: 323 return tcp_release_and_return(packet, ENOTSUP); 335 324 } 336 325 … … 350 339 351 340 // trim all but TCP header 352 if (ERROR_OCCURRED(packet_trim(packet, offset, 0))) 353 return tcp_release_and_return(packet, ERROR_CODE); 341 rc = packet_trim(packet, offset, 0); 342 if (rc != EOK) 343 return tcp_release_and_return(packet, rc); 354 344 355 345 // get tcp header … … 367 357 addrlen = (size_t) result; 368 358 369 if (ERROR_OCCURRED(tl_set_address_port(src, addrlen,370 ntohs(header->source_port))))371 return tcp_release_and_return(packet, ERROR_CODE);359 rc = tl_set_address_port(src, addrlen, ntohs(header->source_port)); 360 if (rc != EOK) 361 return tcp_release_and_return(packet, rc); 372 362 373 363 // find the destination socket … … 379 369 ntohs(header->destination_port), SOCKET_MAP_KEY_LISTENING, 380 370 0); 381 if (!socket) {382 if (tl_prepare_icmp_packet(tcp_globals.net_phone,383 tcp_globals.icmp_phone, packet, error) == EOK) {384 icmp_destination_unreachable_msg(385 tcp_globals.icmp_phone, ICMP_PORT_UNREACH,386 387 388 389 390 } 371 } 372 if (!socket) { 373 if (tl_prepare_icmp_packet(tcp_globals.net_phone, 374 tcp_globals.icmp_phone, packet, error) == EOK) { 375 icmp_destination_unreachable_msg(tcp_globals.icmp_phone, 376 ICMP_PORT_UNREACH, 0, packet); 377 } 378 return EADDRNOTAVAIL; 379 } 380 391 381 printf("socket id %d\n", socket->socket_id); 392 382 socket_data = (tcp_socket_data_ref) socket->specific_data; … … 402 392 total_length = 0; 403 393 do { 404 ++fragments;394 fragments++; 405 395 length = packet_get_data_length(next_packet); 406 396 if (length <= 0) … … 421 411 422 412 if (error) 423 goto error;413 goto has_error_service; 424 414 425 415 if (socket_data->state == TCP_SOCKET_LISTEN) { 426 427 416 if (socket_data->pseudo_header) { 428 417 free(socket_data->pseudo_header); … … 431 420 } 432 421 433 if (ERROR_OCCURRED(ip_client_get_pseudo_header(IPPROTO_TCP, src, 434 addrlen, dest, addrlen, total_length, 435 &socket_data->pseudo_header, &socket_data->headerlen))) { 422 rc = ip_client_get_pseudo_header(IPPROTO_TCP, src, addrlen, 423 dest, addrlen, total_length, &socket_data->pseudo_header, 424 &socket_data->headerlen); 425 if (rc != EOK) { 436 426 fibril_rwlock_write_unlock(socket_data->local_lock); 437 return tcp_release_and_return(packet, ERROR_CODE); 438 } 439 440 } else if (ERROR_OCCURRED(ip_client_set_pseudo_header_data_length( 441 socket_data->pseudo_header, socket_data->headerlen, 442 total_length))) { 443 fibril_rwlock_write_unlock(socket_data->local_lock); 444 return tcp_release_and_return(packet, ERROR_CODE); 427 return tcp_release_and_return(packet, rc); 428 } 429 } else { 430 rc = ip_client_set_pseudo_header_data_length( 431 socket_data->pseudo_header, socket_data->headerlen, 432 total_length); 433 if (rc != EOK) { 434 fibril_rwlock_write_unlock(socket_data->local_lock); 435 return tcp_release_and_return(packet, rc); 436 } 445 437 } 446 438 … … 452 444 fibril_rwlock_write_unlock(socket_data->local_lock); 453 445 454 if (ERROR_NONE(tl_prepare_icmp_packet(tcp_globals.net_phone, 455 tcp_globals.icmp_phone, packet, error))) { 446 rc = tl_prepare_icmp_packet(tcp_globals.net_phone, 447 tcp_globals.icmp_phone, packet, error); 448 if (rc == EOK) { 456 449 // checksum error ICMP 457 450 icmp_parameter_problem_msg(tcp_globals.icmp_phone, … … 464 457 } 465 458 466 error:459 has_error_service: 467 460 fibril_rwlock_read_unlock(&tcp_globals.lock); 468 461 … … 470 463 switch (socket_data->state) { 471 464 case TCP_SOCKET_LISTEN: 472 ERROR_CODE = tcp_process_listen(socket, socket_data, header,473 packet,src, dest, addrlen);465 rc = tcp_process_listen(socket, socket_data, header, packet, 466 src, dest, addrlen); 474 467 break; 475 468 case TCP_SOCKET_SYN_RECEIVED: 476 ERROR_CODE = tcp_process_syn_received(socket, socket_data,477 header,packet);469 rc = tcp_process_syn_received(socket, socket_data, header, 470 packet); 478 471 break; 479 472 case TCP_SOCKET_SYN_SENT: 480 ERROR_CODE = tcp_process_syn_sent(socket, socket_data, header, 481 packet); 473 rc = tcp_process_syn_sent(socket, socket_data, header, packet); 482 474 break; 483 475 case TCP_SOCKET_FIN_WAIT_1: … … 490 482 // ack releasing the socket gets processed later 491 483 case TCP_SOCKET_ESTABLISHED: 492 ERROR_CODE = tcp_process_established(socket, socket_data,493 header,packet, fragments, total_length);484 rc = tcp_process_established(socket, socket_data, header, 485 packet, fragments, total_length); 494 486 break; 495 487 default: … … 497 489 } 498 490 499 if (ERROR_CODE != EOK) { 500 printf("process %d\n", ERROR_CODE); 491 if (rc != EOK) { 501 492 fibril_rwlock_write_unlock(socket_data->local_lock); 493 printf("process %d\n", rc); 502 494 } 503 495 … … 507 499 int 508 500 tcp_process_established(socket_core_ref socket, tcp_socket_data_ref socket_data, 509 tcp_header_ref header, packet_t packet, int fragments, 510 size_t total_length) 511 { 512 ERROR_DECLARE; 513 501 tcp_header_ref header, packet_t packet, int fragments, size_t total_length) 502 { 514 503 packet_t next_packet; 515 504 packet_t tmp_packet; … … 520 509 size_t offset; 521 510 uint32_t new_sequence_number; 511 int rc; 522 512 523 513 assert(socket); … … 560 550 } 561 551 562 if ((offset > 0) && (ERROR_OCCURRED(packet_trim(packet, 563 offset, 0)))) 564 return tcp_release_and_return(packet, ERROR_CODE); 552 if (offset > 0) { 553 rc = packet_trim(packet, offset, 0); 554 if (rc != EOK) 555 return tcp_release_and_return(packet, rc); 556 } 565 557 566 558 assert(new_sequence_number == socket_data->next_incoming); … … 594 586 if (length <= offset) 595 587 next_packet = pq_next(next_packet); 596 else if (ERROR_OCCURRED(packet_trim(next_packet, 0, 597 length - offset))) 598 return tcp_release_and_return(packet, 599 ERROR_CODE); 588 else { 589 rc = packet_trim(next_packet, 0, 590 length - offset)); 591 if (rc != EOK) 592 return tcp_release_and_return(packet, 593 rc); 594 } 600 595 offset -= length; 601 596 total_length -= length - offset; … … 622 617 // remove the header 623 618 total_length -= TCP_HEADER_LENGTH(header); 624 if (ERROR_OCCURRED(packet_trim(packet,625 TCP_HEADER_LENGTH(header), 0)))626 return tcp_release_and_return(packet, ERROR_CODE);619 rc = packet_trim(packet, TCP_HEADER_LENGTH(header), 0); 620 if (rc != EOK) 621 return tcp_release_and_return(packet, rc); 627 622 628 623 if (total_length) { 629 ERROR_PROPAGATE(tcp_queue_received_packet(socket, 630 socket_data, packet, fragments, total_length)); 624 rc = tcp_queue_received_packet(socket, socket_data, 625 packet, fragments, total_length); 626 if (rc != EOK) 627 return rc; 631 628 } else { 632 629 total_length = 1; … … 636 633 packet = socket_data->incoming; 637 634 while (packet) { 638 639 if (ERROR_OCCURRED(pq_get_order(socket_data->incoming, 640 &order, NULL))) { 635 rc = pq_get_order(socket_data->incoming, &order, NULL); 636 if (rc != EOK) { 641 637 // remove the corrupted packet 642 638 next_packet = pq_detach(packet); … … 675 671 socket_data->next_incoming) { 676 672 // queue received data 677 ERROR_PROPAGATE( 678 tcp_queue_received_packet(socket, 673 rc = tcp_queue_received_packet(socket, 679 674 socket_data, packet, 1, 680 packet_get_data_length(packet))); 675 packet_get_data_length(packet)); 676 if (rc != EOK) 677 return rc; 681 678 socket_data->next_incoming = 682 679 new_sequence_number; … … 684 681 continue; 685 682 // at least partly following data? 686 } else if (IS_IN_INTERVAL_OVERFLOW(687 sequence_number, socket_data->next_incoming,688 new_sequence_number)) {683 } 684 if (IS_IN_INTERVAL_OVERFLOW(sequence_number, 685 socket_data->next_incoming, new_sequence_number)) { 689 686 if (socket_data->next_incoming < 690 687 new_sequence_number) { … … 696 693 new_sequence_number; 697 694 } 698 if (ERROR_NONE(packet_trim(packet,699 length, 0))) {695 rc = packet_trim(packet,length, 0); 696 if (rc == EOK) { 700 697 // queue received data 701 ERROR_PROPAGATE( 702 tcp_queue_received_packet( 698 rc = tcp_queue_received_packet( 703 699 socket, socket_data, packet, 704 700 1, packet_get_data_length( 705 packet))); 701 packet)); 702 if (rc != EOK) 703 return rc; 706 704 socket_data->next_incoming = 707 705 new_sequence_number; … … 728 726 // remove the header 729 727 total_length -= TCP_HEADER_LENGTH(header); 730 if (ERROR_OCCURRED(packet_trim(packet,731 TCP_HEADER_LENGTH(header), 0)))732 return tcp_release_and_return(packet, ERROR_CODE);728 rc = packet_trim(packet, TCP_HEADER_LENGTH(header), 0); 729 if (rc != EOK) 730 return tcp_release_and_return(packet, rc); 733 731 734 732 next_packet = pq_detach(packet); 735 733 length = packet_get_data_length(packet); 736 if (ERROR_OCCURRED(pq_add(&socket_data->incoming, packet, 737 new_sequence_number, length))) { 734 rc = pq_add(&socket_data->incoming, packet, new_sequence_number, 735 length); 736 if (rc != EOK) { 738 737 // remove the corrupted packets 739 738 pq_release_remote(tcp_globals.net_phone, … … 746 745 tmp_packet = pq_detach(next_packet); 747 746 length = packet_get_data_length(next_packet); 748 if (ERROR_OCCURRED(pq_set_order(next_packet, 749 new_sequence_number, length)) || 750 ERROR_OCCURRED(pq_insert_after(packet, 751 next_packet))) { 747 748 rc = pq_set_order(next_packet, 749 new_sequence_number, length); 750 if (rc != EOK) { 751 pq_release_remote(tcp_globals.net_phone, 752 packet_get_id(next_packet)); 753 } 754 rc = pq_insert_after(packet, next_packet); 755 if (rc != EOK) { 752 756 pq_release_remote(tcp_globals.net_phone, 753 757 packet_get_id(next_packet)); … … 781 785 if (!packet) { 782 786 // create the notification packet 783 ERROR_PROPAGATE(tcp_create_notification_packet(&packet, socket, 784 socket_data, 0, 0)); 785 ERROR_PROPAGATE(tcp_queue_prepare_packet(socket, socket_data, 786 packet, 1)); 787 rc = tcp_create_notification_packet(&packet, socket, 788 socket_data, 0, 0); 789 if (rc != EOK) 790 return rc; 791 rc = tcp_queue_prepare_packet(socket, socket_data, packet, 1); 792 if (rc != EOK) 793 return rc; 787 794 packet = tcp_send_prepare_packet(socket, socket_data, packet, 1, 788 795 socket_data->last_outgoing + 1); … … 802 809 size_t total_length) 803 810 { 804 ERROR_DECLARE;805 806 811 packet_dimension_ref packet_dimension; 812 int rc; 807 813 808 814 assert(socket); … … 814 820 815 821 // queue the received packet 816 if (ERROR_OCCURRED(dyn_fifo_push(&socket->received, 817 packet_get_id(packet), SOCKET_MAX_RECEIVED_SIZE)) || 818 ERROR_OCCURRED(tl_get_ip_packet_dimension(tcp_globals.ip_phone, 819 &tcp_globals.dimensions, socket_data->device_id, 820 &packet_dimension))) { 821 return tcp_release_and_return(packet, ERROR_CODE); 822 } 822 rc = dyn_fifo_push(&socket->received, packet_get_id(packet), 823 SOCKET_MAX_RECEIVED_SIZE); 824 if (rc != EOK) 825 return tcp_release_and_return(packet, rc); 826 rc = tl_get_ip_packet_dimension(tcp_globals.ip_phone, 827 &tcp_globals.dimensions, socket_data->device_id, &packet_dimension); 828 if (rc != EOK) 829 return tcp_release_and_return(packet, rc); 823 830 824 831 // decrease the window size … … 839 846 tcp_header_ref header, packet_t packet) 840 847 { 841 ERROR_DECLARE;842 843 848 packet_t next_packet; 849 int rc; 844 850 845 851 assert(socket); … … 863 869 } 864 870 // trim if longer than the header 865 if ((packet_get_data_length(packet) > sizeof(*header)) && 866 ERROR_OCCURRED(packet_trim(packet, 0, 867 packet_get_data_length(packet) - sizeof(*header)))) { 868 return tcp_release_and_return(packet, ERROR_CODE); 871 if (packet_get_data_length(packet) > sizeof(*header)) { 872 rc = packet_trim(packet, 0, 873 packet_get_data_length(packet) - sizeof(*header)); 874 if (rc != EOK) 875 return tcp_release_and_return(packet, rc); 869 876 } 870 877 tcp_prepare_operation_header(socket, socket_data, header, 0, 0); … … 895 902 size_t addrlen) 896 903 { 897 ERROR_DECLARE;898 899 904 packet_t next_packet; 900 905 socket_core_ref socket; … … 903 908 int listening_socket_id = listening_socket->socket_id; 904 909 int listening_port = listening_socket->port; 910 int rc; 905 911 906 912 assert(listening_socket); … … 932 938 memcpy(socket_data->addr, src, socket_data->addrlen); 933 939 socket_data->dest_port = ntohs(header->source_port); 934 if (ERROR_OCCURRED(tl_set_address_port(socket_data->addr, 935 socket_data->addrlen, socket_data->dest_port))) { 940 rc = tl_set_address_port(socket_data->addr, socket_data->addrlen, 941 socket_data->dest_port); 942 if (rc != EOK) { 936 943 free(socket_data->addr); 937 944 free(socket_data); 938 pq_release_remote(tcp_globals.net_phone, packet_get_id(packet)); 939 return ERROR_CODE; 945 return tcp_release_and_return(packet, rc); 940 946 } 941 947 942 948 // create a socket 943 949 socket_id = -1; 944 if (ERROR_OCCURRED(socket_create(socket_data->local_sockets, 945 listening_socket->phone, socket_data, &socket_id))) { 950 rc = socket_create(socket_data->local_sockets, listening_socket->phone, 951 socket_data, &socket_id); 952 if (rc != EOK) { 946 953 free(socket_data->addr); 947 954 free(socket_data); 948 return tcp_release_and_return(packet, ERROR_CODE);955 return tcp_release_and_return(packet, rc); 949 956 } 950 957 … … 961 968 listening_socket = socket_port_find(&tcp_globals.sockets, 962 969 listening_port, SOCKET_MAP_KEY_LISTENING, 0); 963 if ( (!listening_socket)||970 if (!listening_socket || 964 971 (listening_socket->socket_id != listening_socket_id)) { 965 972 fibril_rwlock_write_unlock(&tcp_globals.lock); … … 983 990 assert(socket_data); 984 991 985 ERROR_CODE = socket_port_add(&tcp_globals.sockets, listening_port,986 socket,(const char *) socket_data->addr, socket_data->addrlen);992 rc = socket_port_add(&tcp_globals.sockets, listening_port, socket, 993 (const char *) socket_data->addr, socket_data->addrlen); 987 994 assert(socket == socket_port_find(&tcp_globals.sockets, listening_port, 988 995 (const char *) socket_data->addr, socket_data->addrlen)); 989 996 990 // ERROR_CODE= socket_bind_free_port(&tcp_globals.sockets, socket,997 // rc = socket_bind_free_port(&tcp_globals.sockets, socket, 991 998 // TCP_FREE_PORTS_START, TCP_FREE_PORTS_END, 992 999 // tcp_globals.last_used_port); 993 1000 // tcp_globals.last_used_port = socket->port; 994 1001 fibril_rwlock_write_unlock(&tcp_globals.lock); 995 if ( ERROR_CODE!= EOK) {1002 if (rc != EOK) { 996 1003 socket_destroy(tcp_globals.net_phone, socket->socket_id, 997 1004 socket_data->local_sockets, &tcp_globals.sockets, 998 1005 tcp_free_socket_data); 999 return tcp_release_and_return(packet, ERROR_CODE);1006 return tcp_release_and_return(packet, rc); 1000 1007 } 1001 1008 … … 1011 1018 1012 1019 // trim if longer than the header 1013 if ((packet_get_data_length(packet) > sizeof(*header)) && 1014 ERROR_OCCURRED(packet_trim(packet, 0, 1015 packet_get_data_length(packet) - sizeof(*header)))) { 1020 if (packet_get_data_length(packet) > sizeof(*header)) { 1021 rc = packet_trim(packet, 0, 1022 packet_get_data_length(packet) - sizeof(*header)); 1023 if (rc != EOK) { 1024 socket_destroy(tcp_globals.net_phone, socket->socket_id, 1025 socket_data->local_sockets, &tcp_globals.sockets, 1026 tcp_free_socket_data); 1027 return tcp_release_and_return(packet, rc); 1028 } 1029 } 1030 1031 tcp_prepare_operation_header(socket, socket_data, header, 1, 0); 1032 1033 rc = tcp_queue_packet(socket, socket_data, packet, 1); 1034 if (rc != EOK) { 1016 1035 socket_destroy(tcp_globals.net_phone, socket->socket_id, 1017 1036 socket_data->local_sockets, &tcp_globals.sockets, 1018 1037 tcp_free_socket_data); 1019 return tcp_release_and_return(packet, ERROR_CODE); 1020 } 1021 1022 tcp_prepare_operation_header(socket, socket_data, header, 1, 0); 1023 1024 if (ERROR_OCCURRED(tcp_queue_packet(socket, socket_data, packet, 1))) { 1025 socket_destroy(tcp_globals.net_phone, socket->socket_id, 1026 socket_data->local_sockets, &tcp_globals.sockets, 1027 tcp_free_socket_data); 1028 return ERROR_CODE; 1038 return rc; 1029 1039 } 1030 1040 … … 1050 1060 tcp_socket_data_ref socket_data, tcp_header_ref header, packet_t packet) 1051 1061 { 1052 ERROR_DECLARE;1053 1054 1062 socket_core_ref listening_socket; 1055 1063 tcp_socket_data_ref listening_socket_data; 1064 int rc; 1056 1065 1057 1066 assert(socket); … … 1078 1087 1079 1088 // queue the received packet 1080 if (ERROR_NONE(dyn_fifo_push(&listening_socket->accepted, 1081 (-1 * socket->socket_id), 1082 listening_socket_data->backlog))) { 1083 1089 rc = dyn_fifo_push(&listening_socket->accepted, 1090 (-1 * socket->socket_id), listening_socket_data->backlog); 1091 if (rc == EOK) { 1084 1092 // notify the destination socket 1085 1093 async_msg_5(socket->phone, NET_SOCKET_ACCEPTED, … … 1096 1104 1097 1105 // create the notification packet 1098 ERROR_PROPAGATE(tcp_create_notification_packet(&packet, socket, 1099 socket_data, 0, 1)); 1106 rc = tcp_create_notification_packet(&packet, socket, socket_data, 0, 1); 1107 if (rc != EOK) 1108 return rc; 1100 1109 1101 1110 // send the packet 1102 ERROR_PROPAGATE(tcp_queue_packet(socket, socket_data, packet, 1)); 1111 rc = tcp_queue_packet(socket, socket_data, packet, 1); 1112 if (rc != EOK) 1113 return rc; 1103 1114 1104 1115 // flush packets … … 1191 1202 if (number == socket_data->expected) { 1192 1203 // increase the counter 1193 ++socket_data->expected_count;1204 socket_data->expected_count++; 1194 1205 if (socket_data->expected_count == TCP_FAST_RETRANSMIT_COUNT) { 1195 1206 socket_data->expected_count = 1; … … 1200 1211 } 1201 1212 1202 int tcp_message_standalone(ipc_callid_t callid, ipc_call_t * call, 1203 ipc_call_t * answer, int *answer_count) 1204 { 1205 ERROR_DECLARE; 1206 1213 /** Processes the TCP message. 1214 * 1215 * @param[in] callid The message identifier. 1216 * @param[in] call The message parameters. 1217 * @param[out] answer The message answer parameters. 1218 * @param[out] answer_count The last parameter for the actual answer in the 1219 * answer parameter. 1220 * @returns EOK on success. 1221 * @returns ENOTSUP if the message is not known. 1222 * 1223 * @see tcp_interface.h 1224 * @see IS_NET_TCP_MESSAGE() 1225 */ 1226 int 1227 tcp_message_standalone(ipc_callid_t callid, ipc_call_t *call, 1228 ipc_call_t *answer, int *answer_count) 1229 { 1207 1230 packet_t packet; 1231 int rc; 1208 1232 1209 1233 assert(call); … … 1214 1238 switch (IPC_GET_METHOD(*call)) { 1215 1239 case NET_TL_RECEIVED: 1216 //fibril_rwlock_read_lock(&tcp_globals.lock); 1217 if (ERROR_NONE(packet_translate_remote(tcp_globals.net_phone, 1218 &packet, IPC_GET_PACKET(call)))) { 1219 ERROR_CODE = tcp_received_msg(IPC_GET_DEVICE(call), 1220 packet, SERVICE_TCP, IPC_GET_ERROR(call)); 1221 } 1222 //fibril_rwlock_read_unlock(&tcp_globals.lock); 1223 return ERROR_CODE; 1224 1240 // fibril_rwlock_read_lock(&tcp_globals.lock); 1241 rc = packet_translate_remote(tcp_globals.net_phone, &packet, 1242 IPC_GET_PACKET(call)); 1243 if (rc != EOK) { 1244 // fibril_rwlock_read_unlock(&tcp_globals.lock); 1245 return rc; 1246 } 1247 rc = tcp_received_msg(IPC_GET_DEVICE(call), packet, SERVICE_TCP, 1248 IPC_GET_ERROR(call)); 1249 // fibril_rwlock_read_unlock(&tcp_globals.lock); 1250 return rc; 1225 1251 case IPC_M_CONNECT_TO_ME: 1226 1252 return tcp_process_client_messages(callid, *call); … … 1521 1547 socket = socket_port_find(&tcp_globals.sockets, timeout->port, 1522 1548 timeout->key, timeout->key_length); 1523 if (! (socket && (socket->socket_id == timeout->socket_id)))1549 if (!socket || (socket->socket_id != timeout->socket_id)) 1524 1550 goto out; 1525 1551 … … 1532 1558 if (timeout->sequence_number) { 1533 1559 // increase the timeout counter; 1534 ++socket_data->timeout_count;1560 socket_data->timeout_count++; 1535 1561 if (socket_data->timeout_count == TCP_MAX_TIMEOUTS) { 1536 1562 // TODO release as connection lost … … 1667 1693 struct sockaddr *addr, socklen_t addrlen) 1668 1694 { 1669 ERROR_DECLARE;1670 1671 1695 socket_core_ref socket; 1696 int rc; 1672 1697 1673 1698 assert(local_sockets); … … 1680 1705 return ENOTSOCK; 1681 1706 1682 if (ERROR_OCCURRED(tcp_connect_core(socket, local_sockets, addr,1683 addrlen))) {1707 rc = tcp_connect_core(socket, local_sockets, addr, addrlen); 1708 if (rc != EOK) { 1684 1709 tcp_free_socket_data(socket); 1685 1710 // unbind if bound … … 1690 1715 } 1691 1716 } 1692 return ERROR_CODE;1717 return rc; 1693 1718 } 1694 1719 … … 1697 1722 struct sockaddr *addr, socklen_t addrlen) 1698 1723 { 1699 ERROR_DECLARE;1700 1701 1724 tcp_socket_data_ref socket_data; 1702 1725 packet_t packet; 1726 int rc; 1703 1727 1704 1728 assert(socket); … … 1716 1740 1717 1741 // get the destination port 1718 ERROR_PROPAGATE(tl_get_address_port(addr, addrlen, 1719 &socket_data->dest_port)); 1742 rc = tl_get_address_port(addr, addrlen, &socket_data->dest_port); 1743 if (rc != EOK) 1744 return rc; 1745 1720 1746 if (socket->port <= 0) { 1721 1747 // try to find a free port 1722 ERROR_PROPAGATE(socket_bind_free_port(&tcp_globals.sockets, 1723 socket, TCP_FREE_PORTS_START, TCP_FREE_PORTS_END, 1724 tcp_globals.last_used_port)); 1748 rc = socket_bind_free_port(&tcp_globals.sockets, socket, 1749 TCP_FREE_PORTS_START, TCP_FREE_PORTS_END, 1750 tcp_globals.last_used_port); 1751 if (rc != EOK) 1752 return rc; 1725 1753 // set the next port as the search starting port number 1726 1754 tcp_globals.last_used_port = socket->port; 1727 1755 } 1728 1756 1729 ERROR_PROPAGATE(ip_get_route_req(tcp_globals.ip_phone, IPPROTO_TCP,1757 rc = ip_get_route_req(tcp_globals.ip_phone, IPPROTO_TCP, 1730 1758 addr, addrlen, &socket_data->device_id, 1731 &socket_data->pseudo_header, &socket_data->headerlen)); 1759 &socket_data->pseudo_header, &socket_data->headerlen); 1760 if (rc != EOK) 1761 return rc; 1732 1762 1733 1763 // create the notification packet 1734 ERROR_PROPAGATE(tcp_create_notification_packet(&packet, socket, 1735 socket_data, 1, 0)); 1764 rc = tcp_create_notification_packet(&packet, socket, socket_data, 1, 0); 1765 if (rc != EOK) 1766 return rc; 1736 1767 1737 1768 // unlock the globals and wait for an operation … … 1741 1772 socket_data->addrlen = addrlen; 1742 1773 // send the packet 1743 if (ERROR_OCCURRED(tcp_queue_packet(socket, socket_data, packet, 1)) || 1744 ERROR_OCCURRED(tcp_prepare_timeout(tcp_timeout, socket, socket_data, 1745 0, TCP_SOCKET_INITIAL, NET_DEFAULT_TCP_INITIAL_TIMEOUT, false))) { 1746 1774 1775 if (((rc = tcp_queue_packet(socket, socket_data, packet, 1)) != EOK) || 1776 ((rc = tcp_prepare_timeout(tcp_timeout, socket, socket_data, 0, 1777 TCP_SOCKET_INITIAL, NET_DEFAULT_TCP_INITIAL_TIMEOUT, false)) != 1778 EOK)) { 1747 1779 socket_data->addr = NULL; 1748 1780 socket_data->addrlen = 0; 1749 1781 fibril_rwlock_write_lock(&tcp_globals.lock); 1750 1751 1782 } else { 1752 1753 1783 packet = tcp_get_packets_to_send(socket, socket_data); 1754 1784 if (packet) { … … 1762 1792 fibril_condvar_wait(&socket_data->operation.condvar, 1763 1793 &socket_data->operation.mutex); 1764 ERROR_CODE= socket_data->operation.result;1765 if ( ERROR_CODE!= EOK) {1794 rc = socket_data->operation.result; 1795 if (rc != EOK) { 1766 1796 socket_data->addr = NULL; 1767 1797 socket_data->addrlen = 0; … … 1770 1800 socket_data->addr = NULL; 1771 1801 socket_data->addrlen = 0; 1772 ERROR_CODE= EINTR;1802 rc = EINTR; 1773 1803 } 1774 1804 } … … 1777 1807 1778 1808 // return the result 1779 return ERROR_CODE;1809 return rc; 1780 1810 } 1781 1811 … … 1784 1814 tcp_socket_data_ref socket_data, packet_t packet, size_t data_length) 1785 1815 { 1786 ERROR_DECLARE;1787 1788 1816 tcp_header_ref header; 1817 int rc; 1789 1818 1790 1819 assert(socket); … … 1801 1830 header->sequence_number = htonl(socket_data->next_outgoing); 1802 1831 1803 if (ERROR_OCCURRED(packet_set_addr(packet, NULL, 1804 (uint8_t *) socket_data->addr, socket_data->addrlen))) 1832 rc = packet_set_addr(packet, NULL, (uint8_t *) socket_data->addr, 1833 socket_data->addrlen); 1834 if (rc != EOK) 1805 1835 return tcp_release_and_return(packet, EINVAL); 1806 1836 … … 1816 1846 packet_t packet, size_t data_length) 1817 1847 { 1818 ERROR_DECLARE;1848 int rc; 1819 1849 1820 1850 assert(socket); … … 1822 1852 assert(socket->specific_data == socket_data); 1823 1853 1824 ERROR_PROPAGATE(tcp_queue_prepare_packet(socket, socket_data, packet, 1825 data_length)); 1826 1827 if (ERROR_OCCURRED(pq_add(&socket_data->outgoing, packet, 1828 socket_data->next_outgoing, data_length))) 1829 return tcp_release_and_return(packet, ERROR_CODE); 1854 rc = tcp_queue_prepare_packet(socket, socket_data, packet, data_length); 1855 if (rc != EOK) 1856 return rc; 1857 1858 rc = pq_add(&socket_data->outgoing, packet, socket_data->next_outgoing, 1859 data_length); 1860 if (rc != EOK) 1861 return tcp_release_and_return(packet, rc); 1830 1862 1831 1863 socket_data->next_outgoing += data_length; … … 1836 1868 tcp_get_packets_to_send(socket_core_ref socket, tcp_socket_data_ref socket_data) 1837 1869 { 1838 ERROR_DECLARE;1839 1840 1870 packet_t packet; 1841 1871 packet_t copy; … … 1843 1873 packet_t previous = NULL; 1844 1874 size_t data_length; 1875 int rc; 1845 1876 1846 1877 assert(socket); … … 1867 1898 if (!sending) { 1868 1899 sending = copy; 1869 } else if (ERROR_OCCURRED(pq_insert_after(previous, copy))) { 1870 pq_release_remote(tcp_globals.net_phone, 1871 packet_get_id(copy)); 1872 return sending; 1900 } else { 1901 rc = pq_insert_after(previous, copy); 1902 if (rc != EOK) { 1903 pq_release_remote(tcp_globals.net_phone, 1904 packet_get_id(copy)); 1905 return sending; 1906 } 1873 1907 } 1874 1908 … … 1876 1910 packet = pq_next(packet); 1877 1911 // overflow occurred ? 1878 if ( (!packet)&&1912 if (!packet && 1879 1913 (socket_data->last_outgoing > socket_data->next_outgoing)) { 1880 1914 printf("gpts overflow\n"); … … 1892 1926 packet_t packet, size_t data_length, size_t sequence_number) 1893 1927 { 1894 ERROR_DECLARE;1895 1896 1928 tcp_header_ref header; 1897 1929 uint32_t checksum; 1930 int rc; 1898 1931 1899 1932 assert(socket); … … 1902 1935 1903 1936 // adjust the pseudo header 1904 if (ERROR_OCCURRED(ip_client_set_pseudo_header_data_length(1905 socket_data-> pseudo_header, socket_data->headerlen,1906 packet_get_data_length(packet)))) {1937 rc = ip_client_set_pseudo_header_data_length(socket_data->pseudo_header, 1938 socket_data->headerlen, packet_get_data_length(packet)); 1939 if (rc != EOK) { 1907 1940 pq_release_remote(tcp_globals.net_phone, packet_get_id(packet)); 1908 1941 return NULL; … … 1929 1962 checksum = compute_checksum(0, socket_data->pseudo_header, 1930 1963 socket_data->headerlen); 1931 checksum = compute_checksum(checksum, (uint8_t *) packet_get_data(packet), 1964 checksum = compute_checksum(checksum, 1965 (uint8_t *) packet_get_data(packet), 1932 1966 packet_get_data_length(packet)); 1933 1967 header->checksum = htons(flip_checksum(compact_checksum(checksum))); 1934 1968 1935 1969 // prepare the packet 1936 if (ERROR_OCCURRED(ip_client_prepare_packet(packet, IPPROTO_TCP, 0, 0, 1937 0, 0)) || ERROR_OCCURRED(tcp_prepare_timeout(tcp_timeout, socket, 1938 socket_data, sequence_number, socket_data->state, 1939 socket_data->timeout, true))) { 1970 rc = ip_client_prepare_packet(packet, IPPROTO_TCP, 0, 0, 0, 0); 1971 if (rc != EOK) { 1972 pq_release_remote(tcp_globals.net_phone, packet_get_id(packet)); 1973 return NULL; 1974 } 1975 rc = tcp_prepare_timeout(tcp_timeout, socket, socket_data, 1976 sequence_number, socket_data->state, socket_data->timeout, true); 1977 if (rc != EOK) { 1940 1978 pq_release_remote(tcp_globals.net_phone, packet_get_id(packet)); 1941 1979 return NULL; … … 2044 2082 int 2045 2083 tcp_recvfrom_message(socket_cores_ref local_sockets, int socket_id, int flags, 2046 size_t * addrlen) 2047 { 2048 ERROR_DECLARE; 2049 2084 size_t *addrlen) 2085 { 2050 2086 socket_core_ref socket; 2051 2087 tcp_socket_data_ref socket_data; … … 2053 2089 packet_t packet; 2054 2090 size_t length; 2091 int rc; 2055 2092 2056 2093 assert(local_sockets); … … 2074 2111 // send the source address if desired 2075 2112 if (addrlen) { 2076 ERROR_PROPAGATE(data_reply(socket_data->addr, 2077 socket_data->addrlen)); 2113 rc = data_reply(socket_data->addr, socket_data->addrlen); 2114 if (rc != EOK) 2115 return rc; 2078 2116 *addrlen = socket_data->addrlen; 2079 2117 } … … 2084 2122 return NO_DATA; 2085 2123 2086 ERROR_PROPAGATE(packet_translate_remote(tcp_globals.net_phone, &packet, 2087 packet_id)); 2124 rc = packet_translate_remote(tcp_globals.net_phone, &packet, packet_id); 2125 if (rc != EOK) 2126 return rc; 2088 2127 2089 2128 // reply the packets 2090 ERROR_PROPAGATE(socket_reply_packets(packet, &length)); 2129 rc = socket_reply_packets(packet, &length); 2130 if (rc != EOK) 2131 return rc; 2091 2132 2092 2133 // release the packet … … 2099 2140 int 2100 2141 tcp_send_message(socket_cores_ref local_sockets, int socket_id, int fragments, 2101 size_t * data_fragment_size, int flags) 2102 { 2103 ERROR_DECLARE; 2104 2142 size_t *data_fragment_size, int flags) 2143 { 2105 2144 socket_core_ref socket; 2106 2145 tcp_socket_data_ref socket_data; … … 2111 2150 int index; 2112 2151 int result; 2152 int rc; 2113 2153 2114 2154 assert(local_sockets); … … 2131 2171 return ENOTCONN; 2132 2172 2133 ERROR_PROPAGATE(tl_get_ip_packet_dimension(tcp_globals.ip_phone, 2134 &tcp_globals.dimensions, socket_data->device_id, &packet_dimension)); 2173 rc = tl_get_ip_packet_dimension(tcp_globals.ip_phone, 2174 &tcp_globals.dimensions, socket_data->device_id, &packet_dimension); 2175 if (rc != EOK) 2176 return rc; 2135 2177 2136 2178 *data_fragment_size = … … 2138 2180 packet_dimension->content : socket_data->data_fragment_size); 2139 2181 2140 for (index = 0; index < fragments; ++index) {2182 for (index = 0; index < fragments; index++) { 2141 2183 // read the data fragment 2142 2184 result = tl_socket_read_packet_data(tcp_globals.net_phone, … … 2153 2195 2154 2196 tcp_prepare_operation_header(socket, socket_data, header, 0, 0); 2155 ERROR_PROPAGATE(tcp_queue_packet(socket, socket_data, packet, 2156 0)); 2197 rc = tcp_queue_packet(socket, socket_data, packet, 0); 2198 if (rc != EOK) 2199 return rc; 2157 2200 } 2158 2201 … … 2173 2216 tcp_close_message(socket_cores_ref local_sockets, int socket_id) 2174 2217 { 2175 ERROR_DECLARE;2176 2177 2218 socket_core_ref socket; 2178 2219 tcp_socket_data_ref socket_data; 2179 2220 packet_t packet; 2221 int rc; 2180 2222 2181 2223 // find the socket … … 2202 2244 default: 2203 2245 // just destroy 2204 if (ERROR_NONE(socket_destroy(tcp_globals.net_phone, socket_id,2246 rc = socket_destroy(tcp_globals.net_phone, socket_id, 2205 2247 local_sockets, &tcp_globals.sockets, 2206 tcp_free_socket_data))) { 2248 tcp_free_socket_data); 2249 if (rc == EOK) { 2207 2250 fibril_rwlock_write_unlock(socket_data->local_lock); 2208 2251 fibril_rwlock_write_unlock(&tcp_globals.lock); 2209 2252 } 2210 return ERROR_CODE;2253 return rc; 2211 2254 } 2212 2255 … … 2215 2258 2216 2259 // create the notification packet 2217 ERROR_PROPAGATE(tcp_create_notification_packet(&packet, socket, 2218 socket_data, 0, 1)); 2260 rc = tcp_create_notification_packet(&packet, socket, socket_data, 0, 1); 2261 if (rc != EOK) 2262 return rc; 2219 2263 2220 2264 // send the packet 2221 ERROR_PROPAGATE(tcp_queue_packet(socket, socket_data, packet, 1)); 2265 rc = tcp_queue_packet(socket, socket_data, packet, 1); 2266 if (rc != EOK) 2267 return rc; 2222 2268 2223 2269 // flush packets … … 2235 2281 2236 2282 int 2237 tcp_create_notification_packet(packet_t * 2283 tcp_create_notification_packet(packet_t *packet, socket_core_ref socket, 2238 2284 tcp_socket_data_ref socket_data, int synchronize, int finalize) 2239 2285 { 2240 ERROR_DECLARE;2241 2242 2286 packet_dimension_ref packet_dimension; 2243 2287 tcp_header_ref header; 2288 int rc; 2244 2289 2245 2290 assert(packet); 2246 2291 2247 2292 // get the device packet dimension 2248 ERROR_PROPAGATE(tl_get_ip_packet_dimension(tcp_globals.ip_phone, 2249 &tcp_globals.dimensions, socket_data->device_id, 2250 &packet_dimension)); 2293 rc = tl_get_ip_packet_dimension(tcp_globals.ip_phone, 2294 &tcp_globals.dimensions, socket_data->device_id, &packet_dimension); 2295 if (rc != EOK) 2296 return rc; 2251 2297 2252 2298 // get a new packet … … 2271 2317 int 2272 2318 tcp_accept_message(socket_cores_ref local_sockets, int socket_id, 2273 int new_socket_id, size_t * data_fragment_size, size_t * addrlen) 2274 { 2275 ERROR_DECLARE; 2276 2319 int new_socket_id, size_t *data_fragment_size, size_t *addrlen) 2320 { 2277 2321 socket_core_ref accepted; 2278 2322 socket_core_ref socket; 2279 2323 tcp_socket_data_ref socket_data; 2280 2324 packet_dimension_ref packet_dimension; 2325 int rc; 2281 2326 2282 2327 assert(local_sockets); … … 2312 2357 // TODO can it be in another state? 2313 2358 if (socket_data->state == TCP_SOCKET_ESTABLISHED) { 2314 ERROR_PROPAGATE(data_reply(socket_data->addr, 2315 socket_data->addrlen)); 2316 ERROR_PROPAGATE(tl_get_ip_packet_dimension( 2317 tcp_globals.ip_phone, &tcp_globals.dimensions, 2318 socket_data->device_id, &packet_dimension)); 2359 rc = data_reply(socket_data->addr, 2360 socket_data->addrlen); 2361 if (rc != EOK) 2362 return rc; 2363 rc = tl_get_ip_packet_dimension(tcp_globals.ip_phone, 2364 &tcp_globals.dimensions, socket_data->device_id, 2365 &packet_dimension); 2366 if (rc != EOK) 2367 return rc; 2319 2368 *addrlen = socket_data->addrlen; 2320 2369 … … 2326 2375 2327 2376 if (new_socket_id > 0) { 2328 ERROR_PROPAGATE(socket_cores_update( 2329 local_sockets, accepted->socket_id, 2330 new_socket_id)); 2377 rc = socket_cores_update(local_sockets, 2378 accepted->socket_id, new_socket_id); 2379 if (rc != EOK) 2380 return rc; 2331 2381 accepted->socket_id = new_socket_id; 2332 2382 } … … 2373 2423 } 2374 2424 2425 /** Releases the packet and returns the result. 2426 * 2427 * @param[in] packet The packet queue to be released. 2428 * @param[in] result The result to be returned. 2429 * @return The result parameter. 2430 */ 2375 2431 int tcp_release_and_return(packet_t packet, int result) 2376 2432 { … … 2381 2437 /** Default thread for new connections. 2382 2438 * 2383 * @param[in] iidThe initial message identifier.2384 * @param[in] icallThe initial message call structure.2439 * @param[in] iid The initial message identifier. 2440 * @param[in] icall The initial message call structure. 2385 2441 * 2386 2442 */ … … 2397 2453 int answer_count; 2398 2454 2399 /* 2400 Clear the answer structure 2401 */ 2455 /* Clear the answer structure */ 2402 2456 refresh_answer(&answer, &answer_count); 2403 2457 2404 /* 2405 Fetch the next message 2406 */ 2458 /* Fetch the next message */ 2407 2459 ipc_call_t call; 2408 2460 ipc_callid_t callid = async_get_call(&call); 2409 2461 2410 /* 2411 Process the message 2412 */ 2462 /* Process the message */ 2413 2463 int res = tl_module_message_standalone(callid, &call, &answer, 2414 2464 &answer_count); 2415 2465 2416 2466 /* 2417 End if said to either by the message or the processing result 2467 * End if told to either by the message or the processing 2468 * result. 2418 2469 */ 2419 2470 if ((IPC_GET_METHOD(call) == IPC_M_PHONE_HUNGUP) || … … 2430 2481 /** Starts the module. 2431 2482 * 2432 * @param argc The count of the command line arguments. Ignored parameter. 2433 * @param argv The command line parameters. Ignored parameter. 2434 * 2435 * @returns EOK on success. 2436 * @returns Other error codes as defined for each specific module start function. 2437 * 2483 * @returns EOK on success. 2484 * @returns Other error codes as defined for each specific module 2485 * start function. 2438 2486 */ 2439 2487 int 2440 2488 main(int argc, char *argv[]) 2441 2489 { 2442 ERROR_DECLARE; 2443 2444 /* 2445 Start the module 2446 */ 2447 if (ERROR_OCCURRED(tl_module_start_standalone(tl_client_connection))) 2448 return ERROR_CODE; 2449 2450 return EOK; 2490 int rc; 2491 2492 rc = tl_module_start_standalone(tl_client_connection); 2493 return rc; 2451 2494 } 2452 2495
Note:
See TracChangeset
for help on using the changeset viewer.