Add new features to IOSource::Manager, used by DNS_Mgr

- iosource_mgr can now track write events to file descriptors as well
  as read events. This adds an argument to both RegisterFd() and
  UnregisterFd() for setting the mode, defaulting to read.
- IOSources can now implement a ProcessFd() method that allows them to
  handle events to single file descriptors instead of of having to
  loop through/track sets of them at processing time.
This commit is contained in:
Tim Wojtulewicz 2022-04-05 21:14:04 -07:00
parent c2bf602d94
commit f9f37b11c6
6 changed files with 179 additions and 63 deletions

View file

@ -12,10 +12,20 @@ namespace zeek::iosource
class IOSource
{
public:
enum ProcessFlags
{
READ = 0x01,
WRITE = 0x02
};
/**
* Constructor.
*
* @param process_fd A flag for indicating whether the child class implements
* the ProcessFd() method. This is used by the run loop for dispatching to the
* appropriate process method.
*/
IOSource() { closed = false; }
IOSource(bool process_fd = false) : implements_process_fd(process_fd) { }
/**
* Destructor.
@ -66,6 +76,19 @@ public:
*/
virtual void Process() = 0;
/**
* Optional process method that allows an IOSource to only process
* the file descriptor that is found ready and not every possible
* descriptor. If this method is implemented, true must be passed
* to the IOSource constructor via the child class.
*
* @param fd The file descriptor to process.
* @param flags Flags indicating what type of event is being
* processed.
*/
virtual void ProcessFd(int fd, int flags) { }
bool ImplementsProcessFd() const { return implements_process_fd; }
/**
* Returns a descriptive tag representing the source for debugging.
*
@ -84,7 +107,8 @@ protected:
void SetClosed(bool is_closed) { closed = is_closed; }
private:
bool closed;
bool closed = false;
bool implements_process_fd = false;
};
} // namespace zeek::iosource