[update] submit_wait timeout

pull/11/head
Fabien Le Mentec 2011-09-11 00:58:24 -05:00
rodzic 0f6e8186d0
commit 6e98918137
1 zmienionych plików z 14 dodań i 0 usunięć

Wyświetl plik

@ -2,6 +2,7 @@
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include <time.h>
#include <sys/types.h>
#include <libusb-1.0/libusb.h>
#include "stlink-hw.h"
@ -106,6 +107,9 @@ static void on_trans_done(struct libusb_transfer* trans)
static int submit_wait(struct libusb_transfer* trans)
{
struct timeval start;
struct timeval now;
struct timeval diff;
struct trans_ctx trans_ctx;
enum libusb_error error;
@ -121,6 +125,8 @@ static int submit_wait(struct libusb_transfer* trans)
return -1;
}
gettimeofday(&start, NULL);
while (!(trans_ctx.flags & TRANS_FLAGS_IS_DONE))
{
if (libusb_handle_events(NULL))
@ -128,6 +134,14 @@ static int submit_wait(struct libusb_transfer* trans)
printf("libusb_handle_events()\n");
return -1;
}
gettimeofday(&now, NULL);
timersub(&now, &start, &diff);
if (diff.tv_sec >= 3)
{
printf("libusb_handle_events() timeout\n");
return -1;
}
}
return 0;