Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/net/tl/tcp/tcp.c

    r8e3a65c r0578271  
    2828
    2929/** @addtogroup tcp
    30  *  @{
     30 * @{
    3131 */
    3232
    3333/** @file
    34  *  TCP module implementation.
    35  *  @see tcp.h
     34 * TCP module implementation.
     35 * @see tcp.h
    3636 */
     37
     38#include "tcp.h"
     39#include "tcp_header.h"
     40#include "tcp_module.h"
    3741
    3842#include <assert.h>
     
    4347#include <stdio.h>
    4448#include <errno.h>
    45 #include <err.h>
    4649
    4750#include <ipc/ipc.h>
     
    7275#include <tl_interface.h>
    7376
    74 #include "tcp.h"
    75 #include "tcp_header.h"
    76 #include "tcp_module.h"
    77 
    7877/** TCP module name. */
    7978#define NAME    "TCP protocol"
     
    110109
    111110/** Returns a value indicating whether the value is in the interval respecting
    112  *  the possible overflow.
     111 * the possible overflow.
    113112 *
    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.
    118118 */
    119119#define IS_IN_INTERVAL_OVERFLOW(lower, value, higher_equal) \
     
    165165};
    166166
    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);
     167static int tcp_release_and_return(packet_t, int);
     168static void tcp_prepare_operation_header(socket_core_ref, tcp_socket_data_ref,
     169    tcp_header_ref, int synchronize, int);
     170static int tcp_prepare_timeout(int (*)(void *), socket_core_ref,
     171    tcp_socket_data_ref, size_t, tcp_socket_state_t, suseconds_t, int);
     172static void tcp_free_socket_data(socket_core_ref);
     173
     174static int tcp_timeout(void *);
     175
     176static int tcp_release_after_timeout(void *);
     177
     178static int tcp_process_packet(device_id_t, packet_t, services_t);
     179static int tcp_connect_core(socket_core_ref, socket_cores_ref,
     180    struct sockaddr *, socklen_t);
     181static int tcp_queue_prepare_packet(socket_core_ref, tcp_socket_data_ref,
     182    packet_t, size_t);
     183static int tcp_queue_packet(socket_core_ref, tcp_socket_data_ref, packet_t,
     184    size_t);
     185static packet_t tcp_get_packets_to_send(socket_core_ref, tcp_socket_data_ref);
     186static void tcp_send_packets(device_id_t, packet_t);
     187
     188static void tcp_process_acknowledgement(socket_core_ref, tcp_socket_data_ref,
     189    tcp_header_ref);
     190static packet_t tcp_send_prepare_packet(socket_core_ref, tcp_socket_data_ref,
     191    packet_t, size_t, size_t);
     192static 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);
     196static int tcp_create_notification_packet(packet_t *, socket_core_ref,
     197    tcp_socket_data_ref, int, int);
     198static void tcp_refresh_socket_data(tcp_socket_data_ref);
     199
     200static void tcp_initialize_socket_data(tcp_socket_data_ref);
     201
     202static int tcp_process_listen(socket_core_ref, tcp_socket_data_ref,
     203    tcp_header_ref, packet_t, struct sockaddr *, struct sockaddr *, size_t);
     204static int tcp_process_syn_sent(socket_core_ref, tcp_socket_data_ref,
     205    tcp_header_ref, packet_t);
     206static int tcp_process_syn_received(socket_core_ref, tcp_socket_data_ref,
     207    tcp_header_ref, packet_t);
     208static int tcp_process_established(socket_core_ref, tcp_socket_data_ref,
     209    tcp_header_ref, packet_t, int, size_t);
     210static int tcp_queue_received_packet(socket_core_ref, tcp_socket_data_ref,
     211    packet_t, int, size_t);
     212
     213static int tcp_received_msg(device_id_t, packet_t, services_t, services_t);
     214static int tcp_process_client_messages(ipc_callid_t, ipc_call_t);
     215
     216static int tcp_listen_message(socket_cores_ref, int, int);
     217static int tcp_connect_message(socket_cores_ref, int, struct sockaddr *,
     218    socklen_t);
     219static int tcp_recvfrom_message(socket_cores_ref, int, int, size_t *);
     220static int tcp_send_message(socket_cores_ref, int, int, size_t *, int);
     221static int tcp_accept_message(socket_cores_ref, int, int, size_t *, size_t *);
     222static int tcp_close_message(socket_cores_ref, int);
    245223
    246224/** TCP global data. */
    247225tcp_globals_t tcp_globals;
    248226
     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 */
    249234int tcp_initialize(async_client_conn_t client_connection)
    250235{
    251         ERROR_DECLARE;
     236        int rc;
    252237
    253238        assert(client_connection);
     
    260245        tcp_globals.ip_phone = ip_bind_service(SERVICE_IP, IPPROTO_TCP,
    261246            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);
    263249                return tcp_globals.ip_phone;
     250        }
    264251       
    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) {
    268258                socket_ports_destroy(&tcp_globals.sockets);
    269                 return ERROR_CODE;
     259                goto out;
    270260        }
    271261
    272262        tcp_globals.last_used_port = TCP_FREE_PORTS_START - 1;
     263
     264out:
    273265        fibril_rwlock_write_unlock(&tcp_globals.lock);
    274 
    275         return EOK;
     266        return rc;
    276267}
    277268
     
    280271    services_t error)
    281272{
    282         ERROR_DECLARE;
     273        int rc;
    283274
    284275        if (receiver != SERVICE_TCP)
     
    286277
    287278        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)
    289281                fibril_rwlock_write_unlock(&tcp_globals.lock);
    290282
    291         printf("receive %d \n", ERROR_CODE);
    292 
    293         return ERROR_CODE;
     283        printf("receive %d \n", rc);
     284
     285        return rc;
    294286}
    295287
    296288int tcp_process_packet(device_id_t device_id, packet_t packet, services_t error)
    297289{
    298         ERROR_DECLARE;
    299 
    300290        size_t length;
    301291        size_t offset;
     
    313303        struct sockaddr *dest;
    314304        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);
    335324        }
    336325
     
    350339
    351340        // 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);
    354344
    355345        // get tcp header
     
    367357        addrlen = (size_t) result;
    368358
    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);
    372362       
    373363        // find the destination socket
     
    379369                    ntohs(header->destination_port), SOCKET_MAP_KEY_LISTENING,
    380370                    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                                     0, packet);
    387                         }
    388                         return EADDRNOTAVAIL;
    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
    391381        printf("socket id %d\n", socket->socket_id);
    392382        socket_data = (tcp_socket_data_ref) socket->specific_data;
     
    402392        total_length = 0;
    403393        do {
    404                 ++fragments;
     394                fragments++;
    405395                length = packet_get_data_length(next_packet);
    406396                if (length <= 0)
     
    421411
    422412        if (error)
    423                 goto error;
     413                goto has_error_service;
    424414       
    425415        if (socket_data->state == TCP_SOCKET_LISTEN) {
    426 
    427416                if (socket_data->pseudo_header) {
    428417                        free(socket_data->pseudo_header);
     
    431420                }
    432421
    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) {
    436426                        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                }
    445437        }
    446438       
     
    452444                fibril_rwlock_write_unlock(socket_data->local_lock);
    453445
    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) {
    456449                        // checksum error ICMP
    457450                        icmp_parameter_problem_msg(tcp_globals.icmp_phone,
     
    464457        }
    465458
    466 error:
     459has_error_service:
    467460        fibril_rwlock_read_unlock(&tcp_globals.lock);
    468461
     
    470463        switch (socket_data->state) {
    471464        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);
    474467                break;
    475468        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);
    478471                break;
    479472        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);
    482474                break;
    483475        case TCP_SOCKET_FIN_WAIT_1:
     
    490482                // ack releasing the socket gets processed later
    491483        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);
    494486                break;
    495487        default:
     
    497489        }
    498490
    499         if (ERROR_CODE != EOK) {
    500                 printf("process %d\n", ERROR_CODE);
     491        if (rc != EOK) {
    501492                fibril_rwlock_write_unlock(socket_data->local_lock);
     493                printf("process %d\n", rc);
    502494        }
    503495
     
    507499int
    508500tcp_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{
    514503        packet_t next_packet;
    515504        packet_t tmp_packet;
     
    520509        size_t offset;
    521510        uint32_t new_sequence_number;
     511        int rc;
    522512
    523513        assert(socket);
     
    560550                }
    561551
    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                }
    565557
    566558                assert(new_sequence_number == socket_data->next_incoming);
     
    594586                        if (length <= offset)
    595587                                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                        }
    600595                        offset -= length;
    601596                        total_length -= length - offset;
     
    622617                // remove the header
    623618                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);
    627622
    628623                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;
    631628                } else {
    632629                        total_length = 1;
     
    636633                packet = socket_data->incoming;
    637634                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) {
    641637                                // remove the corrupted packet
    642638                                next_packet = pq_detach(packet);
     
    675671                                    socket_data->next_incoming) {
    676672                                        // queue received data
    677                                         ERROR_PROPAGATE(
    678                                             tcp_queue_received_packet(socket,
     673                                        rc = tcp_queue_received_packet(socket,
    679674                                            socket_data, packet, 1,
    680                                             packet_get_data_length(packet)));
     675                                            packet_get_data_length(packet));
     676                                        if (rc != EOK)
     677                                                return rc;
    681678                                        socket_data->next_incoming =
    682679                                            new_sequence_number;
     
    684681                                        continue;
    685682                                        // 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)) {
    689686                                        if (socket_data->next_incoming <
    690687                                            new_sequence_number) {
     
    696693                                                    new_sequence_number;
    697694                                        }
    698                                         if (ERROR_NONE(packet_trim(packet,
    699                                             length, 0))) {
     695                                        rc = packet_trim(packet,length, 0);
     696                                        if (rc == EOK) {
    700697                                                // queue received data
    701                                                 ERROR_PROPAGATE(
    702                                                     tcp_queue_received_packet(
     698                                                rc = tcp_queue_received_packet(
    703699                                                    socket, socket_data, packet,
    704700                                                    1, packet_get_data_length(
    705                                                     packet)));
     701                                                    packet));
     702                                                if (rc != EOK)
     703                                                        return rc;
    706704                                                socket_data->next_incoming =
    707705                                                    new_sequence_number;
     
    728726                // remove the header
    729727                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);
    733731
    734732                next_packet = pq_detach(packet);
    735733                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) {
    738737                        // remove the corrupted packets
    739738                        pq_release_remote(tcp_globals.net_phone,
     
    746745                                tmp_packet = pq_detach(next_packet);
    747746                                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) {
    752756                                        pq_release_remote(tcp_globals.net_phone,
    753757                                            packet_get_id(next_packet));
     
    781785        if (!packet) {
    782786                // 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;
    787794                packet = tcp_send_prepare_packet(socket, socket_data, packet, 1,
    788795                    socket_data->last_outgoing + 1);
     
    802809    size_t total_length)
    803810{
    804         ERROR_DECLARE;
    805 
    806811        packet_dimension_ref packet_dimension;
     812        int rc;
    807813
    808814        assert(socket);
     
    814820
    815821        // 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);
    823830
    824831        // decrease the window size
     
    839846    tcp_header_ref header, packet_t packet)
    840847{
    841         ERROR_DECLARE;
    842 
    843848        packet_t next_packet;
     849        int rc;
    844850
    845851        assert(socket);
     
    863869        }
    864870        // 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);
    869876        }
    870877        tcp_prepare_operation_header(socket, socket_data, header, 0, 0);
     
    895902    size_t addrlen)
    896903{
    897         ERROR_DECLARE;
    898 
    899904        packet_t next_packet;
    900905        socket_core_ref socket;
     
    903908        int listening_socket_id = listening_socket->socket_id;
    904909        int listening_port = listening_socket->port;
     910        int rc;
    905911
    906912        assert(listening_socket);
     
    932938        memcpy(socket_data->addr, src, socket_data->addrlen);
    933939        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) {
    936943                free(socket_data->addr);
    937944                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);
    940946        }
    941947
    942948        // create a socket
    943949        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) {
    946953                free(socket_data->addr);
    947954                free(socket_data);
    948                 return tcp_release_and_return(packet, ERROR_CODE);
     955                return tcp_release_and_return(packet, rc);
    949956        }
    950957
     
    961968        listening_socket = socket_port_find(&tcp_globals.sockets,
    962969            listening_port, SOCKET_MAP_KEY_LISTENING, 0);
    963         if ((!listening_socket) ||
     970        if (!listening_socket ||
    964971            (listening_socket->socket_id != listening_socket_id)) {
    965972                fibril_rwlock_write_unlock(&tcp_globals.lock);
     
    983990        assert(socket_data);
    984991
    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);
    987994        assert(socket == socket_port_find(&tcp_globals.sockets, listening_port,
    988995            (const char *) socket_data->addr, socket_data->addrlen));
    989996
    990 //      ERROR_CODE = socket_bind_free_port(&tcp_globals.sockets, socket,
     997//      rc = socket_bind_free_port(&tcp_globals.sockets, socket,
    991998//          TCP_FREE_PORTS_START, TCP_FREE_PORTS_END,
    992999//          tcp_globals.last_used_port);
    9931000//      tcp_globals.last_used_port = socket->port;
    9941001        fibril_rwlock_write_unlock(&tcp_globals.lock);
    995         if (ERROR_CODE != EOK) {
     1002        if (rc != EOK) {
    9961003                socket_destroy(tcp_globals.net_phone, socket->socket_id,
    9971004                    socket_data->local_sockets, &tcp_globals.sockets,
    9981005                    tcp_free_socket_data);
    999                 return tcp_release_and_return(packet, ERROR_CODE);
     1006                return tcp_release_and_return(packet, rc);
    10001007        }
    10011008
     
    10111018
    10121019        // 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) {
    10161035                socket_destroy(tcp_globals.net_phone, socket->socket_id,
    10171036                    socket_data->local_sockets, &tcp_globals.sockets,
    10181037                    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;
    10291039        }
    10301040
     
    10501060    tcp_socket_data_ref socket_data, tcp_header_ref header, packet_t packet)
    10511061{
    1052         ERROR_DECLARE;
    1053 
    10541062        socket_core_ref listening_socket;
    10551063        tcp_socket_data_ref listening_socket_data;
     1064        int rc;
    10561065
    10571066        assert(socket);
     
    10781087
    10791088                // 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) {
    10841092                        // notify the destination socket
    10851093                        async_msg_5(socket->phone, NET_SOCKET_ACCEPTED,
     
    10961104
    10971105        // 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;
    11001109
    11011110        // 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;
    11031114
    11041115        // flush packets
     
    11911202        if (number == socket_data->expected) {
    11921203                // increase the counter
    1193                 ++socket_data->expected_count;
     1204                socket_data->expected_count++;
    11941205                if (socket_data->expected_count == TCP_FAST_RETRANSMIT_COUNT) {
    11951206                        socket_data->expected_count = 1;
     
    12001211}
    12011212
    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 */
     1226int
     1227tcp_message_standalone(ipc_callid_t callid, ipc_call_t *call,
     1228    ipc_call_t *answer, int *answer_count)
     1229{
    12071230        packet_t packet;
     1231        int rc;
    12081232
    12091233        assert(call);
     
    12141238        switch (IPC_GET_METHOD(*call)) {
    12151239        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;
    12251251        case IPC_M_CONNECT_TO_ME:
    12261252                return tcp_process_client_messages(callid, *call);
     
    15211547        socket = socket_port_find(&tcp_globals.sockets, timeout->port,
    15221548            timeout->key, timeout->key_length);
    1523         if (!(socket && (socket->socket_id == timeout->socket_id)))
     1549        if (!socket || (socket->socket_id != timeout->socket_id))
    15241550                goto out;
    15251551       
     
    15321558        if (timeout->sequence_number) {
    15331559                // increase the timeout counter;
    1534                 ++socket_data->timeout_count;
     1560                socket_data->timeout_count++;
    15351561                if (socket_data->timeout_count == TCP_MAX_TIMEOUTS) {
    15361562                        // TODO release as connection lost
     
    16671693    struct sockaddr *addr, socklen_t addrlen)
    16681694{
    1669         ERROR_DECLARE;
    1670 
    16711695        socket_core_ref socket;
     1696        int rc;
    16721697
    16731698        assert(local_sockets);
     
    16801705                return ENOTSOCK;
    16811706       
    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) {
    16841709                tcp_free_socket_data(socket);
    16851710                // unbind if bound
     
    16901715                }
    16911716        }
    1692         return ERROR_CODE;
     1717        return rc;
    16931718}
    16941719
     
    16971722    struct sockaddr *addr, socklen_t addrlen)
    16981723{
    1699         ERROR_DECLARE;
    1700 
    17011724        tcp_socket_data_ref socket_data;
    17021725        packet_t packet;
     1726        int rc;
    17031727
    17041728        assert(socket);
     
    17161740
    17171741        // 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       
    17201746        if (socket->port <= 0) {
    17211747                // 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;
    17251753                // set the next port as the search starting port number
    17261754                tcp_globals.last_used_port = socket->port;
    17271755        }
    17281756
    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,
    17301758            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;
    17321762
    17331763        // 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;
    17361767
    17371768        // unlock the globals and wait for an operation
     
    17411772        socket_data->addrlen = addrlen;
    17421773        // 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)) {
    17471779                socket_data->addr = NULL;
    17481780                socket_data->addrlen = 0;
    17491781                fibril_rwlock_write_lock(&tcp_globals.lock);
    1750 
    17511782        } else {
    1752 
    17531783                packet = tcp_get_packets_to_send(socket, socket_data);
    17541784                if (packet) {
     
    17621792                        fibril_condvar_wait(&socket_data->operation.condvar,
    17631793                            &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) {
    17661796                                socket_data->addr = NULL;
    17671797                                socket_data->addrlen = 0;
     
    17701800                        socket_data->addr = NULL;
    17711801                        socket_data->addrlen = 0;
    1772                         ERROR_CODE = EINTR;
     1802                        rc = EINTR;
    17731803                }
    17741804        }
     
    17771807
    17781808        // return the result
    1779         return ERROR_CODE;
     1809        return rc;
    17801810}
    17811811
     
    17841814    tcp_socket_data_ref socket_data, packet_t packet, size_t data_length)
    17851815{
    1786         ERROR_DECLARE;
    1787 
    17881816        tcp_header_ref header;
     1817        int rc;
    17891818
    17901819        assert(socket);
     
    18011830        header->sequence_number = htonl(socket_data->next_outgoing);
    18021831
    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)
    18051835                return tcp_release_and_return(packet, EINVAL);
    18061836
     
    18161846    packet_t packet, size_t data_length)
    18171847{
    1818         ERROR_DECLARE;
     1848        int rc;
    18191849
    18201850        assert(socket);
     
    18221852        assert(socket->specific_data == socket_data);
    18231853
    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);
    18301862
    18311863        socket_data->next_outgoing += data_length;
     
    18361868tcp_get_packets_to_send(socket_core_ref socket, tcp_socket_data_ref socket_data)
    18371869{
    1838         ERROR_DECLARE;
    1839 
    18401870        packet_t packet;
    18411871        packet_t copy;
     
    18431873        packet_t previous = NULL;
    18441874        size_t data_length;
     1875        int rc;
    18451876
    18461877        assert(socket);
     
    18671898                if (!sending) {
    18681899                        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                        }
    18731907                }
    18741908
     
    18761910                packet = pq_next(packet);
    18771911                // overflow occurred ?
    1878                 if ((!packet) &&
     1912                if (!packet &&
    18791913                    (socket_data->last_outgoing > socket_data->next_outgoing)) {
    18801914                        printf("gpts overflow\n");
     
    18921926    packet_t packet, size_t data_length, size_t sequence_number)
    18931927{
    1894         ERROR_DECLARE;
    1895 
    18961928        tcp_header_ref header;
    18971929        uint32_t checksum;
     1930        int rc;
    18981931
    18991932        assert(socket);
     
    19021935
    19031936        // 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) {
    19071940                pq_release_remote(tcp_globals.net_phone, packet_get_id(packet));
    19081941                return NULL;
     
    19291962        checksum = compute_checksum(0, socket_data->pseudo_header,
    19301963            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),
    19321966            packet_get_data_length(packet));
    19331967        header->checksum = htons(flip_checksum(compact_checksum(checksum)));
    19341968
    19351969        // 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) {
    19401978                pq_release_remote(tcp_globals.net_phone, packet_get_id(packet));
    19411979                return NULL;
     
    20332071        if (!fibril) {
    20342072                free(operation_timeout);
    2035                 return EPARTY;
     2073                return EPARTY;  /* FIXME: use another EC */
    20362074        }
    20372075//      fibril_mutex_lock(&socket_data->operation.mutex);
     
    20442082int
    20452083tcp_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{
    20502086        socket_core_ref socket;
    20512087        tcp_socket_data_ref socket_data;
     
    20532089        packet_t packet;
    20542090        size_t length;
     2091        int rc;
    20552092
    20562093        assert(local_sockets);
     
    20742111        // send the source address if desired
    20752112        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;
    20782116                *addrlen = socket_data->addrlen;
    20792117        }
     
    20842122                return NO_DATA;
    20852123
    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;
    20882127
    20892128        // 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;
    20912132
    20922133        // release the packet
     
    20992140int
    21002141tcp_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{
    21052144        socket_core_ref socket;
    21062145        tcp_socket_data_ref socket_data;
     
    21112150        int index;
    21122151        int result;
     2152        int rc;
    21132153
    21142154        assert(local_sockets);
     
    21312171                return ENOTCONN;
    21322172
    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;
    21352177
    21362178        *data_fragment_size =
     
    21382180            packet_dimension->content : socket_data->data_fragment_size);
    21392181
    2140         for (index = 0; index < fragments; ++index) {
     2182        for (index = 0; index < fragments; index++) {
    21412183                // read the data fragment
    21422184                result = tl_socket_read_packet_data(tcp_globals.net_phone,
     
    21532195
    21542196                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;
    21572200        }
    21582201
     
    21732216tcp_close_message(socket_cores_ref local_sockets, int socket_id)
    21742217{
    2175         ERROR_DECLARE;
    2176 
    21772218        socket_core_ref socket;
    21782219        tcp_socket_data_ref socket_data;
    21792220        packet_t packet;
     2221        int rc;
    21802222
    21812223        // find the socket
     
    22022244        default:
    22032245                // just destroy
    2204                 if (ERROR_NONE(socket_destroy(tcp_globals.net_phone, socket_id,
     2246                rc = socket_destroy(tcp_globals.net_phone, socket_id,
    22052247                    local_sockets, &tcp_globals.sockets,
    2206                     tcp_free_socket_data))) {
     2248                    tcp_free_socket_data);
     2249                if (rc == EOK) {
    22072250                        fibril_rwlock_write_unlock(socket_data->local_lock);
    22082251                        fibril_rwlock_write_unlock(&tcp_globals.lock);
    22092252                }
    2210                 return ERROR_CODE;
     2253                return rc;
    22112254        }
    22122255
     
    22152258
    22162259        // 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;
    22192263
    22202264        // 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;
    22222268
    22232269        // flush packets
     
    22352281
    22362282int
    2237 tcp_create_notification_packet(packet_t * packet, socket_core_ref socket,
     2283tcp_create_notification_packet(packet_t *packet, socket_core_ref socket,
    22382284    tcp_socket_data_ref socket_data, int synchronize, int finalize)
    22392285{
    2240         ERROR_DECLARE;
    2241 
    22422286        packet_dimension_ref packet_dimension;
    22432287        tcp_header_ref header;
     2288        int rc;
    22442289
    22452290        assert(packet);
    22462291
    22472292        // 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;
    22512297
    22522298        // get a new packet
     
    22712317int
    22722318tcp_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{
    22772321        socket_core_ref accepted;
    22782322        socket_core_ref socket;
    22792323        tcp_socket_data_ref socket_data;
    22802324        packet_dimension_ref packet_dimension;
     2325        int rc;
    22812326
    22822327        assert(local_sockets);
     
    23122357                // TODO can it be in another state?
    23132358                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;
    23192368                        *addrlen = socket_data->addrlen;
    23202369
     
    23262375       
    23272376                        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;
    23312381                                accepted->socket_id = new_socket_id;
    23322382                        }
     
    23732423}
    23742424
     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 */
    23752431int tcp_release_and_return(packet_t packet, int result)
    23762432{
     
    23812437/** Default thread for new connections.
    23822438 *
    2383  *  @param[in] iid The initial message identifier.
    2384  *  @param[in] icall The initial message call structure.
     2439 * @param[in] iid       The initial message identifier.
     2440 * @param[in] icall     The initial message call structure.
    23852441 *
    23862442 */
     
    23972453                int answer_count;
    23982454
    2399                 /*
    2400                    Clear the answer structure
    2401                  */
     2455                /* Clear the answer structure */
    24022456                refresh_answer(&answer, &answer_count);
    24032457
    2404                 /*
    2405                    Fetch the next message
    2406                  */
     2458                /* Fetch the next message */
    24072459                ipc_call_t call;
    24082460                ipc_callid_t callid = async_get_call(&call);
    24092461
    2410                 /*
    2411                    Process the message
    2412                  */
     2462                /* Process the message */
    24132463                int res = tl_module_message_standalone(callid, &call, &answer,
    24142464                    &answer_count);
    24152465
    24162466                /*
    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.
    24182469                 */
    24192470                if ((IPC_GET_METHOD(call) == IPC_M_PHONE_HUNGUP) ||
     
    24302481/** Starts the module.
    24312482 *
    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.
    24382486 */
    24392487int
    24402488main(int argc, char *argv[])
    24412489{
    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;
    24512494}
    24522495
Note: See TracChangeset for help on using the changeset viewer.