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