handle removal of the serialdevice

This commit is contained in:
bjarnedevel0per
2018-09-11 10:26:36 +02:00
parent 1b9591e07a
commit db7a3b79a2

View File

@@ -210,6 +210,7 @@ public enum PortError: Int32, Error {
case mustBeOpen
case stringsMustBeUTF8
case unableToConvertByteToCharacter
case deviceNotConnected
}
public class SerialPort {
@@ -372,6 +373,12 @@ extension SerialPort {
throw PortError.mustBeOpen
}
var s: stat = stat()
fstat(fileDescriptor, &s)
if s.st_nlink != 1 {
throw PortError.deviceNotConnected
}
let bytesRead = read(fileDescriptor, buffer, size)
return bytesRead
}