diff --git a/src/iosource/FD_Set.h b/src/iosource/FD_Set.h deleted file mode 100644 index 9176611c93..0000000000 --- a/src/iosource/FD_Set.h +++ /dev/null @@ -1,101 +0,0 @@ -#pragma once - -#include -#include - -namespace iosource { - -/** - * A container holding a set of file descriptors. - */ -class FD_Set { -public: - - /** - * Constructor. The set is initially empty. - */ - FD_Set() : max(-1), fds() - { } - - /** - * Insert a file descriptor in to the set. - * @param fd the fd to insert in the set. - * @return false if fd was already in the set, else true. - */ - bool Insert(int fd) - { - if ( max < fd ) - max = fd; - - return fds.insert(fd).second; - } - - /** - * Inserts all the file descriptors from another set in to this one. - * @param other a file descriptor set to merge in to this one. - */ - void Insert(const FD_Set& other) - { - for ( std::set::const_iterator it = other.fds.begin(); - it != other.fds.end(); ++it ) - Insert(*it); - } - - /** - * Empties the set. - */ - void Clear() - { max = -1; fds.clear(); } - - /** - * Insert file descriptors in to a fd_set for use with select(). - * @return the greatest file descriptor inserted. - */ - int Set(fd_set* set) const - { - for ( std::set::const_iterator it = fds.begin(); it != fds.end(); - ++it ) - FD_SET(*it, set); - - return max; - } - - /** - * @return Whether a file descriptor belonging to this set is within the - * fd_set arugment. - */ - bool Ready(fd_set* set) const - { - for ( std::set::const_iterator it = fds.begin(); it != fds.end(); - ++it ) - { - if ( FD_ISSET(*it, set) ) - return true; - } - - return false; - } - - /** - * @return whether any file descriptors have been added to the set. - */ - bool Empty() const - { - return fds.empty(); - } - - /** - * @return the greatest file descriptor of all that have been added to the - * set, or -1 if the set is empty. - */ - int Max() const - { - return max; - } - -private: - int max; - std::set fds; -}; - -} // namespace bro diff --git a/src/iosource/IOSource.h b/src/iosource/IOSource.h index e899a11754..67807fa0b4 100644 --- a/src/iosource/IOSource.h +++ b/src/iosource/IOSource.h @@ -7,8 +7,6 @@ extern "C" { } #include -#include "FD_Set.h" -#include "Timer.h" namespace iosource { @@ -21,28 +19,28 @@ public: /** * Constructor. */ - IOSource() { idle = false; closed = false; } + IOSource() { closed = false; } /** * Destructor. */ virtual ~IOSource() {} - /** - * Returns true if source has nothing ready to process. - */ - bool IsIdle() const { return idle; } - /** * Returns true if more data is to be expected in the future. * Otherwise, source may be removed. */ bool IsOpen() const { return ! closed; } + /** + * Returns true if this is a packet source. + */ + virtual bool IsPacketSource() const { return false; } + /** * Initializes the source. Can be overwritten by derived classes. */ - virtual void Init() { } + virtual void InitSource() { } /** * Finalizes the source when it's being closed. Can be overwritten by @@ -51,76 +49,48 @@ public: virtual void Done() { } /** - * Returns select'able file descriptors for this source. Leaves the - * passed values untouched if not available. + * Return the next timeout value for this source. This should be + * overridden by source classes where they have a timeout value + * that can wake up the poll. * - * @param read Pointer to container where to insert a read descriptor. + * Must be overriden by derived classes. * - * @param write Pointer to container where to insert a write descriptor. - * - * @param except Pointer to container where to insert a except descriptor. + * @return A value for the next time that the source thinks the + * poll should time out in seconds from the current time. Return + * -1 if this source should not be considered. This should be a + * a value relative to network_time, not an absolute time. */ - virtual void GetFds(FD_Set* read, FD_Set* write, FD_Set* except) = 0; + virtual double GetNextTimeout() = 0; /** - * Returns the timestamp (in \a global network time) associated with - * next data item from this source. If the source wants the data - * item to be processed with a local network time, it sets the - * argument accordingly. - * - * This method will be called only when either IsIdle() returns - * false, or select() on one of the fds returned by GetFDs() - * indicates that there's data to process. - * - * Must be overridden by derived classes. - * - * @param network_time A pointer to store the \a local network time - * associated with the next item (as opposed to global network time). - * - * @return The global network time of the next entry, or a value - * smaller than zero if none is available currently. - */ - virtual double NextTimestamp(double* network_time) = 0; - - /** - * Processes and consumes next data item. - * - * This method will be called only when either IsIdle() returns - * false, or select() on one of the fds returned by GetFDs() - * indicates that there's data to process. + * Processes and consumes next data item. This will be called by + * net_run when this IOSource has been marked ready. * * Must be overridden by derived classes. */ virtual void Process() = 0; /** - * Returns the tag of the timer manafger associated with the last + * Returns the tag of the timer manager associated with the last * procesees data item. * * Can be overridden by derived classes. * * @return The tag, or null for the global timer manager. - * + * */ - virtual TimerMgr::Tag* GetCurrentTag() { return 0; } + virtual std::string* GetCurrentTag() { return 0; } /** - * Returns a descriptual tag representing the source for debugging. + * Returns a descriptive tag representing the source for debugging. * - * Can be overridden by derived classes. + * Must be overridden by derived classes. * * @return The debugging name. */ virtual const char* Tag() = 0; protected: - /* - * Callback for derived classes to call when they have gone dry - * temporarily. - * - * @param is_idle True if the source is idle currently. - */ - void SetIdle(bool is_idle) { idle = is_idle; } /* * Callback for derived class to call when they have shutdown. @@ -130,7 +100,6 @@ protected: void SetClosed(bool is_closed) { closed = is_closed; } private: - bool idle; bool closed; };