VirtualBox

Changeset 64298 in vbox for trunk/src


Ignore:
Timestamp:
Oct 17, 2016 1:55:11 PM (8 years ago)
Author:
vboxsync
Message:

bugref:8573: applied FIN-RST-2.diff: fix for shutting down half-closed sockets

Location:
trunk/src/VBox/Devices/Network/slirp
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/Network/slirp/socket.c

    r63676 r64298  
    363363        {
    364364            int fUninitializedTemplate = 0;
     365            int shuterr;
     366
    365367            fUninitializedTemplate = RT_BOOL((   sototcpcb(so)
    366368                                              && (  sototcpcb(so)->t_template.ti_src.s_addr == INADDR_ANY
     
    369371            Log2(("%s: disconnected, nn = %d, errno = %d (%s)\n",
    370372                  RT_GCC_EXTENSION __PRETTY_FUNCTION__, nn, sockerr, strerror(sockerr)));
    371             sofcantrcvmore(so);
    372             if (!fUninitializedTemplate)
     373
     374            shuterr = sofcantrcvmore(so);
     375            if (!sockerr && !shuterr && !fUninitializedTemplate)
    373376                tcp_sockclosed(pData, sototcpcb(so));
    374377            else
     
    11011104}
    11021105
    1103 void
     1106int
    11041107sofcantrcvmore(struct  socket *so)
    11051108{
     1109    int err = 0;
     1110
    11061111    LogFlowFunc(("ENTER: so:%R[natsock]\n", so));
    11071112    if ((so->so_state & SS_NOFDREF) == 0)
    11081113    {
    1109         shutdown(so->s, 0);
     1114        /*
     1115         * If remote closes first and then sends an RST, the recv() in
     1116         * soread() will keep reporting EOF without any error
     1117         * indication, so we must also check if shutdown() succeeds
     1118         * here.
     1119         */
     1120        int status = shutdown(so->s, 0);
     1121        if (status < 0)
     1122            err = errno;
    11101123    }
    11111124    so->so_state &= ~(SS_ISFCONNECTING);
    11121125    if (so->so_state & SS_FCANTSENDMORE)
     1126    {
     1127        /*
     1128         * If we have closed first, and remote closes, shutdown will
     1129         * return ENOTCONN, but this is expected.  Don't tell the
     1130         * caller there was an error.
     1131         */
     1132        if (err == ENOTCONN)
     1133            err = 0;
    11131134        so->so_state = SS_NOFDREF; /* Don't select it */
    11141135                                   /* XXX close() here as well? */
     1136    }
    11151137    else
    11161138        so->so_state |= SS_FCANTRCVMORE;
    1117     LogFlowFuncLeave();
     1139
     1140    LogFlowFunc(("LEAVE: %d\n", err));
     1141    return err;
    11181142}
    11191143
  • trunk/src/VBox/Devices/Network/slirp/socket.h

    r62511 r64298  
    182182void soisfconnecting (register struct socket *);
    183183void soisfconnected (register struct socket *);
    184 void sofcantrcvmore (struct  socket *);
     184int sofcantrcvmore (struct  socket *);
    185185void sofcantsendmore (struct socket *);
    186186void soisfdisconnected (struct socket *);
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette