Re: Input flush action for userspace FromDevice?
Markku Savela <[email protected]> Fri, 19 Oct 2012 08:47:37 +0300
| Newsgroups | gmane.network.routing.click |
|---|---|
| Message-ID | <[email protected]> |
On 10/17/2012 01:19 PM, Markku Savela wrote: > I cannot find such function in FromDevice or is there? First > that comes to mind is some kind of flush handler that > would read and discard input, until none... (there is, of > course, a small concern of reading forever and never seeing > "no data" if new data for socket is generated faster than > click can read). Ok, here is my test for such handler. This is not anything that could be incorporated as is: it is hard coded to assume the linux method for reading -- I didn't have time to study how to achieve same with PCAP or NETMAP... I suppose I should have wrapped this in FROMDEVICE_ALLOW_LINUX and check the selected _method too. _______________________________________________ click mailing list [email protected] https://amsterdam.lcs.mit.edu/mailman/listinfo/click
flush.diff
(text/x-patch, 1.1 KB)
diff --git a/elements/userlevel/fromdevice.cc b/elements/userlevel/fromdevice.cc
index 3da8dab..924ab8f 100644
--- a/elements/userlevel/fromdevice.cc
+++ b/elements/userlevel/fromdevice.cc
@@ -626,10 +626,24 @@ FromDevice::read_handler(Element* e, void *thunk)
}
int
-FromDevice::write_handler(const String &, Element *e, void *, ErrorHandler *)
+FromDevice::write_handler(const String &, Element *e, void *data, ErrorHandler *)
{
FromDevice* fd = static_cast<FromDevice*>(e);
- fd->_count = 0;
+ unsigned count = 0;
+ unsigned char buf[100];
+
+ switch ((int)data) {
+ case 0:
+ fd->_count = 0;
+ break;
+ case 1:
+ while (recv(fd->_fd, buf, sizeof(buf), MSG_DONTWAIT) > 0)
+ ++count;
+ click_chatter("flushed %u", count);
+ break;
+ default:
+ break;
+ }
return 0;
}
@@ -640,6 +654,7 @@ FromDevice::add_handlers()
add_read_handler("encap", read_handler, 1);
add_read_handler("count", read_handler, 2);
add_write_handler("reset_counts", write_handler, 0, Handler::BUTTON);
+ add_write_handler("flush", write_handler, 1, Handler::BUTTON);
}
CLICK_ENDDECLS