Merge branch 'khorben/blocking'

This commit is contained in:
Pierre Pronchery 2017-12-13 23:07:45 +01:00
commit 7121808f28
4 changed files with 13 additions and 2 deletions

View File

@ -72,7 +72,7 @@ void CloseProxmark() {
int OpenProxmark(size_t i) { int OpenProxmark(size_t i) {
sp = uart_open(serial_port_name); sp = uart_open(serial_port_name);
if (sp == INVALID_SERIAL_PORT || sp == CLAIMED_SERIAL_PORT) { if (sp == INVALID_SERIAL_PORT || sp == CLAIMED_SERIAL_PORT || sp == NONBLOCKING_SERIAL_PORT) {
//poll once a second //poll once a second
return 0; return 0;
} }

View File

@ -362,7 +362,7 @@ int main(int argc, char* argv[]) {
msleep(1000); msleep(1000);
printf("."); printf(".");
fflush(stdout); fflush(stdout);
} while(++openCount < 20 && (sp == INVALID_SERIAL_PORT || sp == CLAIMED_SERIAL_PORT)); } while(++openCount < 20 && (sp == INVALID_SERIAL_PORT || sp == CLAIMED_SERIAL_PORT || sp == NONBLOCKING_SERIAL_PORT));
printf("\n"); printf("\n");
} }

View File

@ -56,6 +56,10 @@ typedef void* serial_port;
*/ */
#define CLAIMED_SERIAL_PORT (void*)(~2) #define CLAIMED_SERIAL_PORT (void*)(~2)
/* Returned by uart_open if the serial port specified is in non-blocking mode.
*/
#define NONBLOCKING_SERIAL_PORT (void*)(~4)
/* Given a user-specified port name, connect to the port and return a structure /* Given a user-specified port name, connect to the port and return a structure
* used for future references to that port. * used for future references to that port.
* *

View File

@ -86,6 +86,13 @@ serial_port uart_open(const char* pcPortName)
return CLAIMED_SERIAL_PORT; return CLAIMED_SERIAL_PORT;
} }
int i;
i = fcntl(sp->fd, F_GETFL, 0);
if((i & ~O_NONBLOCK) != i && fcntl(sp->fd, F_SETFL, i & ~O_NONBLOCK) != 0) {
free(sp);
return NONBLOCKING_SERIAL_PORT;
}
// Try to retrieve the old (current) terminal info struct // Try to retrieve the old (current) terminal info struct
if(tcgetattr(sp->fd,&sp->tiOld) == -1) { if(tcgetattr(sp->fd,&sp->tiOld) == -1) {
uart_close(sp); uart_close(sp);