VirtualBox

Changeset 83520 in vbox for trunk/src/VBox/Runtime


Ignore:
Timestamp:
Apr 3, 2020 8:33:32 AM (5 years ago)
Author:
vboxsync
Message:

Runtime/r3/serialport-posix: More error checking, read/write methods should return an error if read() or write() return 0 bytes as this indicate an end of file condition which is an error for serial ports, and check for the POLLERR flag first before checking POLLIN (as both get set)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/r3/posix/serialport-posix.cpp

    r82968 r83520  
    822822         */
    823823        ssize_t cbRead = read(pThis->iFd, pvBuf, cbToRead);
    824         if (cbRead >= 0)
     824        if (cbRead > 0)
    825825        {
    826826            if (pcbRead)
     
    835835                    if (cbReadPart < 0)
    836836                        return RTErrConvertFromErrno(errno);
     837                    else if (cbReadPart == 0)
     838                        return VERR_DEV_IO_ERROR;
    837839
    838840                    cbRead += cbReadPart;
     
    840842            }
    841843        }
     844        else if (cbRead == 0)
     845            rc = VERR_DEV_IO_ERROR;
    842846        else
    843847            rc = RTErrConvertFromErrno(errno);
     
    874878            *pcbRead = cbThisRead;
    875879        }
    876         else if (cbThisRead == 0 || errno == EAGAIN || errno == EWOULDBLOCK)
     880        else if (cbThisRead == 0)
     881            rc = VERR_DEV_IO_ERROR;
     882        else if (   errno == EAGAIN
     883# ifdef EWOULDBLOCK
     884#  if EWOULDBLOCK != EAGAIN
     885                 || errno == EWOULDBLOCK
     886#  endif
     887# endif
     888                )
    877889            rc = VINF_TRY_AGAIN;
    878890        else
     
    899911         */
    900912        ssize_t cbWritten = write(pThis->iFd, pvBuf, cbToWrite);
    901         if (cbWritten >= 0)
     913        if (cbWritten > 0)
    902914        {
    903915            if (pcbWritten)
     
    912924                    if (cbWrittenPart < 0)
    913925                        return RTErrConvertFromErrno(errno);
     926                    else if (cbWrittenPart == 0)
     927                        return VERR_DEV_IO_ERROR;
    914928                    cbWritten += cbWrittenPart;
    915929                }
    916930            }
    917931        }
     932        else if (cbWritten == 0)
     933            rc = VERR_DEV_IO_ERROR;
     934        else
     935            rc = RTErrConvertFromErrno(errno);
    918936    }
    919937
     
    939957        if (cbThisWrite > 0)
    940958            *pcbWritten = cbThisWrite;
    941         else if (cbThisWrite == 0 || errno == EAGAIN || errno == EWOULDBLOCK)
     959        else if (cbThisWrite == 0)
     960            rc = VERR_DEV_IO_ERROR;
     961        else if (   errno == EAGAIN
     962# ifdef EWOULDBLOCK
     963#  if EWOULDBLOCK != EAGAIN
     964                 || errno == EWOULDBLOCK
     965#  endif
     966# endif
     967                )
    942968            rc = VINF_TRY_AGAIN;
    943969        else
     
    10921118            if (aPollFds[0].revents != 0)
    10931119            {
    1094                 fEvtsPending |= (aPollFds[0].revents & POLLIN) ? RTSERIALPORT_EVT_F_DATA_RX : 0;
    1095                 fEvtsPending |= (aPollFds[0].revents & POLLOUT) ? RTSERIALPORT_EVT_F_DATA_TX : 0;
    1096                 /** @todo BREAK condition detection. */
     1120                if (aPollFds[0].revents & POLLERR)
     1121                    rc = VERR_DEV_IO_ERROR;
     1122                else
     1123                {
     1124                    fEvtsPending |= (aPollFds[0].revents & POLLIN) ? RTSERIALPORT_EVT_F_DATA_RX : 0;
     1125                    fEvtsPending |= (aPollFds[0].revents & POLLOUT) ? RTSERIALPORT_EVT_F_DATA_TX : 0;
     1126                    /** @todo BREAK condition detection. */
     1127                }
    10971128            }
    10981129
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