mbed-os/drivers
Kevin Bracey 9678c8052e Make UARTSerial send all data when blocking
Previously, write() was somewhat soft - it only ever made one attempt to
wait for buffer space, so it would take as much data as would fit in the
buffer in one call.

This is not the intent of a POSIX filehandle write. It should try to
send everything if blocking, and only send less if interrupted by a
signal:

 - If the O_NONBLOCK flag is clear, write() shall block the calling
   thread until the data can be accepted.

 - If the O_NONBLOCK flag is set, write() shall not block the thread.
   If some data can be written without blocking the thread, write()
   shall write what it can and return the number of bytes written.
   Otherwise, it shall return -1 and set errno to [EAGAIN].

This "send all" behaviour is of slightly limited usefulness in POSIX, as
you still usually have to worry about the interruption possibility:

  - If write() is interrupted by a signal before it writes any data, it
    shall return -1 with errno set to [EINTR].

  - If write() is interrupted by a signal after it successfully writes
    some data, it shall return the number of bytes written.

But as mbed OS does not have the possibility of signal interruption, if we
strengthen write to write everything, we can make applications' lives
easier - they can just do "write(large amount)" confident that it will
all go in one call (if no errors).

So, rework to make multiple writes to the buffer, blocking as necessary,
until all data is written.

This change does not apply to read(), which is correct in only blocking until
some data is available:

 - If O_NONBLOCK is set, read() shall return -1 and set errno to [EAGAIN].

 - If O_NONBLOCK is clear, read() shall block the calling thread until some
   data becomes available.

 - The use of the O_NONBLOCK flag has no effect if there is some data
   available.
2017-11-21 09:51:36 +02:00
..
AnalogIn.cpp
AnalogIn.h
AnalogOut.h
BusIn.cpp
BusIn.h
BusInOut.cpp
BusInOut.h
BusOut.cpp
BusOut.h
CAN.cpp
CAN.h
DigitalIn.h
DigitalInOut.h
DigitalOut.h
Ethernet.cpp
Ethernet.h
FlashIAP.cpp
FlashIAP.h
I2C.cpp
I2C.h
I2CSlave.cpp
I2CSlave.h
InterruptIn.cpp
InterruptIn.h
InterruptManager.cpp
InterruptManager.h
LowPowerTicker.h
LowPowerTimeout.h
LowPowerTimer.h
PortIn.h
PortInOut.h
PortOut.h
PwmOut.h
RawSerial.cpp
RawSerial.h
SPI.cpp
SPI.h
SPISlave.cpp
SPISlave.h
Serial.cpp
Serial.h
SerialBase.cpp
SerialBase.h
Ticker.cpp
Ticker.h
Timeout.cpp
Timeout.h
Timer.cpp
Timer.h
TimerEvent.cpp
TimerEvent.h
UARTSerial.cpp
UARTSerial.h
mbed_lib.json