Changeset e64e40b in mainline


Ignore:
Timestamp:
2010-12-27T20:05:44Z (13 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
097967b
Parents:
6e5b4e7 (diff), 45bb1d2 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge TCP FIN fix and some cleanup.

Location:
uspace
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/generic/net/icmp_api.c

    r6e5b4e7 re64e40b  
    8989            tos, (sysarg_t) dont_fragment, NULL);
    9090
    91         // send the address
     91        /* Send the address */
    9292        async_data_write_start(icmp_phone, addr, (size_t) addrlen);
    9393
  • uspace/lib/c/generic/net/inet.c

    r6e5b4e7 re64e40b  
    6464        switch (family) {
    6565        case AF_INET:
    66                 // check the output buffer size
     66                /* Check output buffer size */
    6767                if (length < INET_ADDRSTRLEN)
    6868                        return ENOMEM;
    6969                       
    70                 // fill the buffer with the IPv4 address
     70                /* Fill buffer with IPv4 address */
    7171                snprintf(address, length, "%hhu.%hhu.%hhu.%hhu",
    7272                    data[0], data[1], data[2], data[3]);
     
    7575
    7676        case AF_INET6:
    77                 // check the output buffer size
     77                /* Check output buffer size */
    7878                if (length < INET6_ADDRSTRLEN)
    7979                        return ENOMEM;
    8080               
    81                 // fill the buffer with the IPv6 address
     81                /* Fill buffer with IPv6 address */
    8282                snprintf(address, length,
    8383                    "%hhx%hhx:%hhx%hhx:%hhx%hhx:%hhx%hhx:%hhx%hhx:%hhx%hhx:"
     
    124124                return EINVAL;
    125125
    126         // set the processing parameters
     126        /* Set processing parameters */
    127127        switch (family) {
    128128        case AF_INET:
     
    142142        }
    143143
    144         // erase if no address
     144        /* Erase if no address */
    145145        if (!address) {
    146146                bzero(data, count);
     
    148148        }
    149149
    150         // process the string from the beginning
     150        /* Process string from the beginning */
    151151        next = address;
    152152        index = 0;
    153153        do {
    154                 // if the actual character is set
     154                /* If the actual character is set */
    155155                if (next && *next) {
    156156
    157                         // if not on the first character
     157                        /* If not on the first character */
    158158                        if (index) {
    159                                 // move to the next character
     159                                /* Move to the next character */
    160160                                ++next;
    161161                        }
    162162
    163                         // parse the actual integral value
     163                        /* Parse the actual integral value */
    164164                        value = strtoul(next, &last, base);
    165                         // remember the last problematic character
    166                         // should be either '.' or ':' but is ignored to be more
    167                         // generic
     165                        /*
     166                         * Remember the last problematic character
     167                         * should be either '.' or ':' but is ignored to be
     168                         * more generic
     169                         */
    168170                        next = last;
    169171
    170                         // fill the address data byte by byte
     172                        /* Fill the address data byte by byte */
    171173                        shift = bytes - 1;
    172174                        do {
    173                                 // like little endian
     175                                /* like little endian */
    174176                                data[index + shift] = value;
    175177                                value >>= 8;
     
    178180                        index += bytes;
    179181                } else {
    180                         // erase the rest of the address
     182                        /* Erase the rest of the address */
    181183                        bzero(data + index, count - index);
    182184                        return EOK;
  • uspace/lib/c/generic/net/modules.c

    r6e5b4e7 re64e40b  
    6363    int answer_count)
    6464{
    65         // choose the most efficient answer function
     65        /* Choose the most efficient answer function */
    6666        if (answer || (!answer_count)) {
    6767                switch (answer_count) {
     
    178178        int phone;
    179179
    180         // if no timeout is set
     180        /* If no timeout is set */
    181181        if (timeout <= 0)
    182182                return async_connect_me_to_blocking(PHONE_NS, need, 0, 0);
     
    187187                        return phone;
    188188
    189                 // end if no time is left
     189                /* Abort if no time is left */
    190190                if (timeout <= 0)
    191191                        return ETIMEOUT;
    192192
    193                 // wait the minimum of the module wait time and the timeout
     193                /* Wait the minimum of the module wait time and the timeout */
    194194                usleep((timeout <= MODULE_WAIT_TIME) ?
    195195                    timeout : MODULE_WAIT_TIME);
     
    214214        ipc_callid_t callid;
    215215
    216         // fetch the request
     216        /* Fetch the request */
    217217        if (!async_data_read_receive(&callid, &length))
    218218                return EINVAL;
    219219
    220         // check the requested data size
     220        /* Check the requested data size */
    221221        if (length < data_length) {
    222222                async_data_read_finalize(callid, data, length);
     
    224224        }
    225225
    226         // send the data
     226        /* Send the data */
    227227        return async_data_read_finalize(callid, data, data_length);
    228228}
     
    242242        if (answer) {
    243243                IPC_SET_RETVAL(*answer, 0);
    244                 // just to be precize
     244                /* Just to be precise */
    245245                IPC_SET_IMETHOD(*answer, 0);
    246246                IPC_SET_ARG1(*answer, 0);
  • uspace/lib/c/generic/net/packet.c

    r6e5b4e7 re64e40b  
    191191        }
    192192        gpm_destroy(&pm_globals.packet_map);
    193         // leave locked
     193        /* leave locked */
    194194}
    195195
  • uspace/lib/c/generic/net/socket_client.c

    r6e5b4e7 re64e40b  
    220220                fibril_rwlock_read_lock(&socket_globals.lock);
    221221
    222                 // find the socket
     222                /* Find the socket */
    223223                socket = sockets_find(socket_get_sockets(),
    224224                    SOCKET_GET_SOCKET_ID(call));
     
    232232                case NET_SOCKET_RECEIVED:
    233233                        fibril_mutex_lock(&socket->receive_lock);
    234                         // push the number of received packet fragments
     234                        /* Push the number of received packet fragments */
    235235                        rc = dyn_fifo_push(&socket->received,
    236236                            SOCKET_GET_DATA_FRAGMENTS(call),
    237237                            SOCKET_MAX_RECEIVED_SIZE);
    238238                        if (rc == EOK) {
    239                                 // signal the received packet
     239                                /* Signal the received packet */
    240240                                fibril_condvar_signal(&socket->receive_signal);
    241241                        }
     
    244244
    245245                case NET_SOCKET_ACCEPTED:
    246                         // push the new socket identifier
     246                        /* Push the new socket identifier */
    247247                        fibril_mutex_lock(&socket->accept_lock);
    248248                        rc = dyn_fifo_push(&socket->accepted, 1,
    249249                            SOCKET_MAX_ACCEPTED_SIZE);
    250250                        if (rc == EOK) {
    251                                 // signal the accepted socket
     251                                /* Signal the accepted socket */
    252252                                fibril_condvar_signal(&socket->accept_signal);
    253253                        }
     
    264264                        fibril_rwlock_write_lock(&socket->sending_lock);
    265265
    266                         // set the data fragment size
     266                        /* Set the data fragment size */
    267267                        socket->data_fragment_size =
    268268                            SOCKET_GET_DATA_FRAGMENT_SIZE(call);
     
    342342                        socket_id = 1;
    343343                        ++count;
    344                 // only this branch for last_id
     344                /* Only this branch for last_id */
    345345                } else {
    346346                        if (socket_id < INT_MAX) {
     
    408408        int rc;
    409409
    410         // find the appropriate service
     410        /* Find the appropriate service */
    411411        switch (domain) {
    412412        case PF_INET:
     
    457457                return phone;
    458458
    459         // create a new socket structure
     459        /* Create a new socket structure */
    460460        socket = (socket_t *) malloc(sizeof(socket_t));
    461461        if (!socket)
     
    465465        fibril_rwlock_write_lock(&socket_globals.lock);
    466466
    467         // request a new socket
     467        /* Request a new socket */
    468468        socket_id = socket_generate_new_id();
    469469        if (socket_id <= 0) {
     
    484484        socket->header_size = (size_t) header_size;
    485485
    486         // finish the new socket initialization
     486        /* Finish the new socket initialization */
    487487        socket_initialize(socket, socket_id, phone, service);
    488         // store the new socket
     488        /* Store the new socket */
    489489        rc = sockets_add(socket_get_sockets(), socket_id, socket);
    490490
     
    531531        fibril_rwlock_read_lock(&socket_globals.lock);
    532532
    533         // find the socket
     533        /* Find the socket */
    534534        socket = sockets_find(socket_get_sockets(), socket_id);
    535535        if (!socket) {
     
    538538        }
    539539
    540         // request the message
     540        /* Request the message */
    541541        message_id = async_send_3(socket->phone, message,
    542542            (sysarg_t) socket->socket_id, arg2, socket->service, NULL);
    543         // send the address
     543        /* Send the address */
    544544        async_data_write_start(socket->phone, data, datalength);
    545545
     
    566566                return EINVAL;
    567567
    568         // send the address
     568        /* Send the address */
    569569        return socket_send_data(socket_id, NET_SOCKET_BIND, 0, my_addr,
    570570            (size_t) addrlen);
     
    591591        fibril_rwlock_read_lock(&socket_globals.lock);
    592592
    593         // find the socket
     593        /* Find the socket */
    594594        socket = sockets_find(socket_get_sockets(), socket_id);
    595595        if (!socket) {
     
    598598        }
    599599
    600         // request listen backlog change
     600        /* Request listen backlog change */
    601601        result = (int) async_req_3_0(socket->phone, NET_SOCKET_LISTEN,
    602602            (sysarg_t) socket->socket_id, (sysarg_t) backlog, socket->service);
     
    634634        fibril_rwlock_write_lock(&socket_globals.lock);
    635635
    636         // find the socket
     636        /* Find the socket */
    637637        socket = sockets_find(socket_get_sockets(), socket_id);
    638638        if (!socket) {
     
    643643        fibril_mutex_lock(&socket->accept_lock);
    644644
    645         // wait for an accepted socket
     645        /* Wait for an accepted socket */
    646646        ++ socket->blocked;
    647647        while (dyn_fifo_value(&socket->accepted) <= 0) {
    648648                fibril_rwlock_write_unlock(&socket_globals.lock);
    649649                fibril_condvar_wait(&socket->accept_signal, &socket->accept_lock);
    650                 // drop the accept lock to avoid deadlock
     650                /* Drop the accept lock to avoid deadlock */
    651651                fibril_mutex_unlock(&socket->accept_lock);
    652652                fibril_rwlock_write_lock(&socket_globals.lock);
     
    655655        -- socket->blocked;
    656656
    657         // create a new scoket
     657        /* Create a new socket */
    658658        new_socket = (socket_t *) malloc(sizeof(socket_t));
    659659        if (!new_socket) {
     
    681681        }
    682682
    683         // request accept
     683        /* Request accept */
    684684        message_id = async_send_5(socket->phone, NET_SOCKET_ACCEPT,
    685685            (sysarg_t) socket->socket_id, 0, socket->service, 0,
    686686            new_socket->socket_id, &answer);
    687687
    688         // read address
     688        /* Read address */
    689689        ipc_data_read_start(socket->phone, cliaddr, *addrlen);
    690690        fibril_rwlock_write_unlock(&socket_globals.lock);
     
    695695                        result = EINVAL;
    696696
    697                 // dequeue the accepted socket if successful
     697                /* Dequeue the accepted socket if successful */
    698698                dyn_fifo_pop(&socket->accepted);
    699                 // set address length
     699                /* Set address length */
    700700                *addrlen = SOCKET_GET_ADDRESS_LENGTH(answer);
    701701                new_socket->data_fragment_size =
    702702                    SOCKET_GET_DATA_FRAGMENT_SIZE(answer);
    703703        } else if (result == ENOTSOCK) {
    704                 // empty the queue if no accepted sockets
     704                /* Empty the queue if no accepted sockets */
    705705                while (dyn_fifo_pop(&socket->accepted) > 0)
    706706                        ;
     
    731731                return EDESTADDRREQ;
    732732
    733         // send the address
     733        /* Send the address */
    734734        return socket_send_data(socket_id, NET_SOCKET_CONNECT, 0, serv_addr,
    735735            addrlen);
     
    744744        int accepted_id;
    745745
    746         // destroy all accepted sockets
     746        /* Destroy all accepted sockets */
    747747        while ((accepted_id = dyn_fifo_pop(&socket->accepted)) >= 0)
    748748                socket_destroy(sockets_find(socket_get_sockets(), accepted_id));
     
    780780        }
    781781
    782         // request close
     782        /* Request close */
    783783        rc = (int) async_req_3_0(socket->phone, NET_SOCKET_CLOSE,
    784784            (sysarg_t) socket->socket_id, 0, socket->service);
     
    787787                return rc;
    788788        }
    789         // free the socket structure
     789        /* Free the socket structure */
    790790        socket_destroy(socket);
    791791
     
    833833        fibril_rwlock_read_lock(&socket_globals.lock);
    834834
    835         // find socket
     835        /* Find socket */
    836836        socket = sockets_find(socket_get_sockets(), socket_id);
    837837        if (!socket) {
     
    842842        fibril_rwlock_read_lock(&socket->sending_lock);
    843843
    844         // compute data fragment count
     844        /* Compute data fragment count */
    845845        if (socket->data_fragment_size > 0) {
    846846                fragments = (datalength + socket->header_size) /
     
    853853        }
    854854
    855         // request send
     855        /* Request send */
    856856        message_id = async_send_5(socket->phone, message,
    857857            (sysarg_t) socket->socket_id,
     
    859859            socket->service, (sysarg_t) flags, fragments, &answer);
    860860
    861         // send the address if given
     861        /* Send the address if given */
    862862        if (!toaddr ||
    863863            (async_data_write_start(socket->phone, toaddr, addrlen) == EOK)) {
    864864                if (fragments == 1) {
    865                         // send all if only one fragment
     865                        /* Send all if only one fragment */
    866866                        async_data_write_start(socket->phone, data, datalength);
    867867                } else {
    868                         // send the first fragment
     868                        /* Send the first fragment */
    869869                        async_data_write_start(socket->phone, data,
    870870                            socket->data_fragment_size - socket->header_size);
     
    872872                            socket->data_fragment_size - socket->header_size;
    873873       
    874                         // send the middle fragments
     874                        /* Send the middle fragments */
    875875                        while (--fragments > 1) {
    876876                                async_data_write_start(socket->phone, data,
     
    880880                        }
    881881
    882                         // send the last fragment
     882                        /* Send the last fragment */
    883883                        async_data_write_start(socket->phone, data,
    884884                            (datalength + socket->header_size) %
     
    892892            (SOCKET_GET_DATA_FRAGMENT_SIZE(answer) !=
    893893            socket->data_fragment_size)) {
    894                 // set the data fragment size
     894                /* Set the data fragment size */
    895895                socket->data_fragment_size =
    896896                    SOCKET_GET_DATA_FRAGMENT_SIZE(answer);
     
    917917int send(int socket_id, void *data, size_t datalength, int flags)
    918918{
    919         // without the address
     919        /* Without the address */
    920920        return sendto_core(NET_SOCKET_SEND, socket_id, data, datalength, flags,
    921921            NULL, 0);
     
    950950                return EDESTADDRREQ;
    951951
    952         // with the address
     952        /* With the address */
    953953        return sendto_core(NET_SOCKET_SENDTO, socket_id, data, datalength,
    954954            flags, toaddr, addrlen);
     
    966966 *                      read. The actual address length is set. Used only if
    967967 *                      fromaddr is not NULL.
    968  * @return              EOK on success.
     968 * @return              Positive received message size in bytes on success.
     969 * @return              Zero if no more data (other side closed the connection).
    969970 * @return              ENOTSOCK if the socket is not found.
    970971 * @return              EBADMEM if the data parameter is NULL.
     
    972973 * @return              Other error codes as defined for the spcific message.
    973974 */
    974 static int
     975static ssize_t
    975976recvfrom_core(sysarg_t message, int socket_id, void *data, size_t datalength,
    976977    int flags, struct sockaddr *fromaddr, socklen_t *addrlen)
     
    984985        size_t index;
    985986        ipc_call_t answer;
     987        ssize_t retval;
    986988
    987989        if (!data)
     
    996998        fibril_rwlock_read_lock(&socket_globals.lock);
    997999
    998         // find the socket
     1000        /* Find the socket */
    9991001        socket = sockets_find(socket_get_sockets(), socket_id);
    10001002        if (!socket) {
     
    10041006
    10051007        fibril_mutex_lock(&socket->receive_lock);
    1006         // wait for a received packet
     1008        /* Wait for a received packet */
    10071009        ++socket->blocked;
    1008         while ((result = dyn_fifo_value(&socket->received)) <= 0) {
     1010        while ((result = dyn_fifo_value(&socket->received)) < 0) {
    10091011                fibril_rwlock_read_unlock(&socket_globals.lock);
    10101012                fibril_condvar_wait(&socket->receive_signal,
    10111013                    &socket->receive_lock);
    10121014
    1013                 // drop the receive lock to avoid deadlock
     1015                /* Drop the receive lock to avoid deadlock */
    10141016                fibril_mutex_unlock(&socket->receive_lock);
    10151017                fibril_rwlock_read_lock(&socket_globals.lock);
     
    10191021        fragments = (size_t) result;
    10201022
    1021         // prepare lengths if more fragments
     1023        if (fragments == 0) {
     1024                /* No more data, other side has closed the connection. */
     1025                return 0;
     1026        }
     1027
     1028        /* Prepare lengths if more fragments */
    10221029        if (fragments > 1) {
    10231030                lengths = (size_t *) malloc(sizeof(size_t) * fragments +
     
    10291036                }
    10301037
    1031                 // request packet data
     1038                /* Request packet data */
    10321039                message_id = async_send_4(socket->phone, message,
    10331040                    (sysarg_t) socket->socket_id, 0, socket->service,
    10341041                    (sysarg_t) flags, &answer);
    10351042
    1036                 // read the address if desired
     1043                /* Read the address if desired */
    10371044                if(!fromaddr ||
    10381045                    (async_data_read_start(socket->phone, fromaddr,
    10391046                    *addrlen) == EOK)) {
    1040                         // read the fragment lengths
     1047                        /* Read the fragment lengths */
    10411048                        if (async_data_read_start(socket->phone, lengths,
    10421049                            sizeof(int) * (fragments + 1)) == EOK) {
    10431050                                if (lengths[fragments] <= datalength) {
    10441051
    1045                                         // read all fragments if long enough
     1052                                        /* Read all fragments if long enough */
    10461053                                        for (index = 0; index < fragments;
    10471054                                            ++index) {
     
    10571064
    10581065                free(lengths);
    1059         } else {
    1060                 // request packet data
     1066        } else { /* fragments == 1 */
     1067                /* Request packet data */
    10611068                message_id = async_send_4(socket->phone, message,
    10621069                    (sysarg_t) socket->socket_id, 0, socket->service,
    10631070                    (sysarg_t) flags, &answer);
    10641071
    1065                 // read the address if desired
     1072                /* Read the address if desired */
    10661073                if (!fromaddr ||
    10671074                    (async_data_read_start(socket->phone, fromaddr,
    10681075                        *addrlen) == EOK)) {
    1069                         // read all if only one fragment
     1076                        /* Read all if only one fragment */
    10701077                        async_data_read_start(socket->phone, data, datalength);
    10711078                }
     
    10751082        result = (int) ipc_result;
    10761083        if (result == EOK) {
    1077                 // dequeue the received packet
     1084                /* Dequeue the received packet */
    10781085                dyn_fifo_pop(&socket->received);
    1079                 // return read data length
    1080                 result = SOCKET_GET_READ_DATA_LENGTH(answer);
    1081                 // set address length
     1086                /* Return read data length */
     1087                retval = SOCKET_GET_READ_DATA_LENGTH(answer);
     1088                /* Set address length */
    10821089                if (fromaddr && addrlen)
    10831090                        *addrlen = SOCKET_GET_ADDRESS_LENGTH(answer);
     1091        } else {
     1092                retval = (ssize_t) result;
    10841093        }
    10851094
    10861095        fibril_mutex_unlock(&socket->receive_lock);
    10871096        fibril_rwlock_read_unlock(&socket_globals.lock);
    1088         return result;
     1097        return retval;
    10891098}
    10901099
     
    10951104 * @param[in] datalength The data length.
    10961105 * @param[in] flags     Various receive flags.
    1097  * @return              EOK on success.
     1106 * @return              Positive received message size in bytes on success.
     1107 * @return              Zero if no more data (other side closed the connection).
    10981108 * @return              ENOTSOCK if the socket is not found.
    10991109 * @return              EBADMEM if the data parameter is NULL.
     
    11021112 *                      message.
    11031113 */
    1104 int recv(int socket_id, void *data, size_t datalength, int flags)
    1105 {
    1106         // without the address
     1114ssize_t recv(int socket_id, void *data, size_t datalength, int flags)
     1115{
     1116        /* Without the address */
    11071117        return recvfrom_core(NET_SOCKET_RECV, socket_id, data, datalength,
    11081118            flags, NULL, NULL);
     
    11181128 * @param[in,out] addrlen The address length. The maximum address length is
    11191129 *                      read. The actual address length is set.
    1120  * @return              EOK on success.
     1130 * @return              Positive received message size in bytes on success.
     1131 * @return              Zero if no more data (other side closed the connection).
    11211132 * @return              ENOTSOCK if the socket is not found.
    11221133 * @return              EBADMEM if the data or fromaddr parameter is NULL.
     
    11251136 *                      message.
    11261137 */
    1127 int
     1138ssize_t
    11281139recvfrom(int socket_id, void *data, size_t datalength, int flags,
    11291140    struct sockaddr *fromaddr, socklen_t *addrlen)
     
    11351146                return NO_DATA;
    11361147
    1137         // with the address
     1148        /* With the address */
    11381149        return recvfrom_core(NET_SOCKET_RECVFROM, socket_id, data, datalength,
    11391150            flags, fromaddr, addrlen);
     
    11701181        fibril_rwlock_read_lock(&socket_globals.lock);
    11711182
    1172         // find the socket
     1183        /* Find the socket */
    11731184        socket = sockets_find(socket_get_sockets(), socket_id);
    11741185        if (!socket) {
     
    11771188        }
    11781189
    1179         // request option value
     1190        /* Request option value */
    11801191        message_id = async_send_3(socket->phone, NET_SOCKET_GETSOCKOPT,
    11811192            (sysarg_t) socket->socket_id, (sysarg_t) optname, socket->service,
    11821193            NULL);
    11831194
    1184         // read the length
     1195        /* Read the length */
    11851196        if (async_data_read_start(socket->phone, optlen,
    11861197            sizeof(*optlen)) == EOK) {
    1187                 // read the value
     1198                /* Read the value */
    11881199                async_data_read_start(socket->phone, value, *optlen);
    11891200        }
     
    12121223    size_t optlen)
    12131224{
    1214         // send the value
     1225        /* Send the value */
    12151226        return socket_send_data(socket_id, NET_SOCKET_SETSOCKOPT,
    12161227            (sysarg_t) optname, value, optlen);
  • uspace/lib/c/include/net/socket.h

    r6e5b4e7 re64e40b  
    6060extern int sendto(int, const void *, size_t, int, const struct sockaddr *,
    6161    socklen_t);
    62 extern int recv(int, void *, size_t, int);
    63 extern int recvfrom(int, void *, size_t, int, struct sockaddr *, socklen_t *);
     62extern ssize_t recv(int, void *, size_t, int);
     63extern ssize_t recvfrom(int, void *, size_t, int, struct sockaddr *, socklen_t *);
    6464extern int getsockopt(int, int, int, void *, size_t *);
    6565extern int setsockopt(int, int, int, const void *, size_t);
  • uspace/srv/net/tl/tcp/tcp.c

    r6e5b4e7 re64e40b  
    205205static int tcp_queue_received_packet(socket_core_t *, tcp_socket_data_t *,
    206206    packet_t *, int, size_t);
     207static void tcp_queue_received_end_of_data(socket_core_t *socket);
    207208
    208209static int tcp_received_msg(device_id_t, packet_t *, services_t, services_t);
     
    504505        size_t offset;
    505506        uint32_t new_sequence_number;
     507        bool forced_ack;
    506508        int rc;
    507509
     
    512514        assert(packet);
    513515
     516        forced_ack = false;
     517
    514518        new_sequence_number = ntohl(header->sequence_number);
    515519        old_incoming = socket_data->next_incoming;
    516520
    517         if (header->finalize)
    518                 socket_data->fin_incoming = new_sequence_number;
     521        if (header->finalize) {
     522                socket_data->fin_incoming = new_sequence_number +
     523                    total_length - TCP_HEADER_LENGTH(header);
     524        }
    519525
    520526        /* Trim begining if containing expected data */
     
    760766                /* Release duplicite or restricted */
    761767                pq_release_remote(tcp_globals.net_phone, packet_get_id(packet));
    762         }
    763 
    764         /* Change state according to the acknowledging incoming fin */
    765         if (IS_IN_INTERVAL_OVERFLOW(old_incoming, socket_data->fin_incoming,
    766             socket_data->next_incoming)) {
     768                forced_ack = true;
     769        }
     770
     771        if (header->finalize)
     772                socket_data->next_incoming += 1;
     773
     774        /* If next in sequence is an incoming FIN */
     775        if (socket_data->next_incoming == socket_data->fin_incoming) {
     776                /* Advance sequence number */
     777                socket_data->next_incoming += 1;
     778
     779                /* Handle FIN */
    767780                switch (socket_data->state) {
    768781                case TCP_SOCKET_FIN_WAIT_1:
     
    771784                        socket_data->state = TCP_SOCKET_CLOSING;
    772785                        break;
    773                 /*case TCP_ESTABLISHED:*/
     786                case TCP_SOCKET_ESTABLISHED:
     787                        /* Queue end-of-data marker on the socket. */
     788                        tcp_queue_received_end_of_data(socket);
     789                        socket_data->state = TCP_SOCKET_CLOSE_WAIT;
     790                        break;
    774791                default:
    775792                        socket_data->state = TCP_SOCKET_CLOSE_WAIT;
     
    779796
    780797        packet = tcp_get_packets_to_send(socket, socket_data);
    781         if (!packet) {
     798        if (!packet && (socket_data->next_incoming != old_incoming || forced_ack)) {
    782799                /* Create the notification packet */
    783800                rc = tcp_create_notification_packet(&packet, socket,
     
    835852
    836853        return EOK;
     854}
     855
     856/** Queue end-of-data marker on the socket.
     857 *
     858 * Next element in the sequence space is FIN. Queue end-of-data marker
     859 * on the socket.
     860 *
     861 * @param socket        Socket
     862 */
     863static void tcp_queue_received_end_of_data(socket_core_t *socket)
     864{
     865        assert(socket != NULL);
     866
     867        /* Notify the destination socket */
     868        async_msg_5(socket->phone, NET_SOCKET_RECEIVED,
     869            (sysarg_t) socket->socket_id,
     870            0, 0, 0,
     871            (sysarg_t) 0 /* 0 fragments == no more data */);
    837872}
    838873
Note: See TracChangeset for help on using the changeset viewer.