mirror of
https://github.com/nfc-tools/libnfc.git
synced 2026-03-13 11:03:48 +00:00
Error handling improvement:
- Attempt to sort errors depending their source - Rename DE* errors to differenciate Device-Error and Driver-Error - Add ENOTIMPL error to raise a error when a feature is not (yet) implemented in libnfc
This commit is contained in:
@@ -276,32 +276,32 @@ select:
|
||||
// Read error
|
||||
if (res < 0) {
|
||||
DBG ("%s", "RX error.");
|
||||
return DEIO;
|
||||
return ECOMIO;
|
||||
}
|
||||
// Read time-out
|
||||
if (res == 0) {
|
||||
DBG ("Timeout!");
|
||||
return DETIMEOUT;
|
||||
return ECOMTIMEOUT;
|
||||
}
|
||||
|
||||
if (FD_ISSET (iAbortFd, &rfds)) {
|
||||
// Abort requested
|
||||
DBG ("Abort!");
|
||||
close (iAbortFd);
|
||||
return DEABORT;
|
||||
return EOPABORT;
|
||||
}
|
||||
|
||||
// Retrieve the count of the incoming bytes
|
||||
res = ioctl (((serial_port_unix *) sp)->fd, FIONREAD, &available_bytes_count);
|
||||
if (res != 0) {
|
||||
return DEIO;
|
||||
return ECOMIO;
|
||||
}
|
||||
// There is something available, read the data
|
||||
// DBG ("expected bytes: %zu, received bytes: %d, available bytes: %d", szRx, received_bytes_count, available_bytes_count);
|
||||
res = read (((serial_port_unix *) sp)->fd, pbtRx + received_bytes_count, MIN(available_bytes_count, (expected_bytes_count - received_bytes_count)));
|
||||
// Stop if the OS has some troubles reading the data
|
||||
if (res <= 0) {
|
||||
return DEIO;
|
||||
return ECOMIO;
|
||||
}
|
||||
received_bytes_count += res;
|
||||
|
||||
@@ -322,7 +322,7 @@ uart_send (serial_port sp, const byte_t * pbtTx, const size_t szTx)
|
||||
if ((int) szTx == write (((serial_port_unix *) sp)->fd, pbtTx, szTx))
|
||||
return 0;
|
||||
else
|
||||
return DEIO;
|
||||
return ECOMIO;
|
||||
}
|
||||
|
||||
char **
|
||||
|
||||
@@ -165,18 +165,18 @@ uart_receive (serial_port sp, byte_t * pbtRx, const size_t szRx, void * abort_p)
|
||||
|
||||
if (!res) {
|
||||
WARN("ReadFile returned error\n");
|
||||
return DEIO;
|
||||
return ECOMIO;
|
||||
}
|
||||
if (((DWORD)szRx) > dwTotalBytesReceived) {
|
||||
dwBytesToGet -= dwBytesReceived;
|
||||
}
|
||||
|
||||
if (abort_flag_p != NULL && (*abort_flag_p) && dwTotalBytesReceived == 0) {
|
||||
return DEABORT;
|
||||
return EOPABORT;
|
||||
}
|
||||
} while (((DWORD)szRx) > dwTotalBytesReceived);
|
||||
|
||||
return (dwTotalBytesReceived == (DWORD) szRx) ? 0 : DEIO;
|
||||
return (dwTotalBytesReceived == (DWORD) szRx) ? 0 : ECOMIO;
|
||||
}
|
||||
|
||||
int
|
||||
@@ -184,10 +184,10 @@ uart_send (serial_port sp, const byte_t * pbtTx, const size_t szTx)
|
||||
{
|
||||
DWORD dwTxLen = 0;
|
||||
if (!WriteFile (((serial_port_windows *) sp)->hPort, pbtTx, szTx, &dwTxLen, NULL)) {
|
||||
return DEIO;
|
||||
return ECOMIO;
|
||||
}
|
||||
if (!dwTxLen)
|
||||
return DEIO;
|
||||
return ECOMIO;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user