]> cvs.zerfleddert.de Git - hmcfgusb/blobdiff - culfw.c
Merge pull request #1 from bullshit/debian
[hmcfgusb] / culfw.c
diff --git a/culfw.c b/culfw.c
index 72c5c6a2f7ef02810d78f3c81952f905ec6189cb..6cfa975736318aeaa7049136555b0148a340aef9 100644 (file)
--- a/culfw.c
+++ b/culfw.c
@@ -1,6 +1,6 @@
 /* culfw driver
  *
- * Copyright (c) 2013 Michael Gernoth <michael@gernoth.net>
+ * Copyright (c) 2014 Michael Gernoth <michael@gernoth.net>
  *
  * Permission is hereby granted, free of charge, to any person obtaining a copy
  * of this software and associated documentation files (the "Software"), to
@@ -141,7 +141,7 @@ int culfw_poll(struct culfw_dev *dev, int timeout)
        pfds[0].fd = dev->fd;
        pfds[0].events = POLLIN;
 
-       ret = poll(pfds, 1, timeout * 1000);
+       ret = poll(pfds, 1, timeout);
        if (ret == -1)
                return -1;
 
@@ -175,3 +175,34 @@ void culfw_close(struct culfw_dev *dev)
 {
        close(dev->fd);
 }
+
+void culfw_flush(struct culfw_dev *dev)
+{
+       struct pollfd pfds[1];
+       int ret;
+       int r = 0;
+       uint8_t buf[1024];
+
+       tcflush(dev->fd, TCIOFLUSH);
+
+       while(1) {
+               memset(pfds, 0, sizeof(struct pollfd) * 1);
+
+               pfds[0].fd = dev->fd;
+               pfds[0].events = POLLIN;
+
+               ret = poll(pfds, 1, 100);
+               if (ret <= 0)
+                       break;
+
+               if (!(pfds[0].revents & POLLIN))
+                       break;
+
+               memset(buf, 0, sizeof(buf));
+               r = read(dev->fd, buf, sizeof(buf));
+               if (r <= 0)
+                       break;
+       }
+
+       return;
+}
Impressum, Datenschutz