Handle failed and partial writes correctly.

This commit is contained in:
Steve Checkoway
2008-12-26 12:07:29 +00:00
parent 97024035e8
commit a92c75880a
@@ -13,19 +13,30 @@ REGISTER_SOUND_DRIVER_CLASS(LinuxWeedTech);
// Begin serial driver //
static int fd = -1;
static LightsState CurLights;
static LightsState CurLights;
static inline void SerialClose()
{
if( fd != 1 )
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 )
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 );
}