Handle failed and partial writes correctly.
This commit is contained in:
@@ -19,13 +19,24 @@ static inline void SerialClose()
|
|||||||
{
|
{
|
||||||
if( fd != 1 )
|
if( fd != 1 )
|
||||||
close( fd );
|
close( fd );
|
||||||
|
fd = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void SerialOut(const char *str, int len)
|
static inline void SerialOut( const char *str, size_t len )
|
||||||
{
|
{
|
||||||
if( fd ==-1 )
|
if( fd ==-1 )
|
||||||
return;
|
return;
|
||||||
write( fd, str, len );
|
while( len )
|
||||||
|
{
|
||||||
|
ssize_t result = write( fd, str, len );
|
||||||
|
if( result == -1 )
|
||||||
|
{
|
||||||
|
LOG->Trace( "Failed to write to lights driver: %s", strerror(errno) );
|
||||||
|
SerialClose();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
len -= result;
|
||||||
|
}
|
||||||
usleep( 2000 );
|
usleep( 2000 );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user