mirror of
https://github.com/zeek/zeek.git
synced 2025-10-17 14:08:20 +00:00

These are non-functional changes. * accounting * activation * actual * added * addresult * aggregable * aligned * alternatively * ambiguous * analysis * analyzer * anticlimactic * apparently * application * appropriate * arithmetic * assignment * assigns * associated * authentication * authoritative * barrier * boundary * broccoli * buffering * caching * called * canonicalized * capturing * certificates * ciphersuite * columns * communication * comparison * comparisons * compilation * component * concatenating * concatenation * connection * convenience * correctly * corresponding * could * counting * data * declared * decryption * defining * dependent * deprecated * detached * dictionary * directional * directly * directory * discarding * disconnecting * distinguishes * documentation * elsewhere * emitted * empty * endianness * endpoint * enumerator * essentially * evaluated * everything * exactly * execute * explicit * expressions * facilitates * fiddling * filesystem * flag * flagged * for * fragments * guarantee * guaranteed * happen * happening * hemisphere * identifier * identifies * identify * implementation * implemented * implementing * including * inconsistency * indeterminate * indices * individual * information * initial * initialization * initialize * initialized * initializes * instantiate * instantiated * instantiates * interface * internal * interpreted * interpreter * into * it * iterators * length * likely * log * longer * mainly * mark * maximum * message * minimum * module * must * name * namespace * necessary * nonexistent * not * notifications * notifier * number * objects * occurred * operations * original * otherwise * output * overridden * override * overriding * overwriting * ownership * parameters * particular * payload * persistent * potential * precision * preexisting * preservation * preserved * primarily * probably * procedure * proceed * process * processed * processes * processing * propagate * propagated * prototype * provides * publishing * purposes * queue * reached * reason * reassem * reassemble * reassembler * recommend * record * reduction * reference * regularly * representation * request * reserved * retrieve * returning * separate * should * shouldn't * significant * signing * simplified * simultaneously * single * somebody * sources * specific * specification * specified * specifies * specify * statement * subdirectories * succeeded * successful * successfully * supplied * synchronization * tag * temporarily * terminating * that * the * transmitted * true * truncated * try * understand * unescaped * unforwarding * unknown * unknowndata * unspecified * update * usually * which * wildcard Signed-off-by: Josh Soref <2119212+jsoref@users.noreply.github.com>
130 lines
3.3 KiB
C++
130 lines
3.3 KiB
C++
// See the file "COPYING" in the main distribution directory for copyright.
|
|
|
|
#pragma once
|
|
|
|
namespace zeek::detail
|
|
{
|
|
|
|
class Pipe
|
|
{
|
|
public:
|
|
/**
|
|
* Create a pair of file descriptors via pipe(), or aborts if it cannot.
|
|
* @param flags0 file descriptor flags to set on read end of pipe.
|
|
* @param flags1 file descriptor flags to set on write end of pipe.
|
|
* @param status_flags0 descriptor status flags to set on read end of pipe.
|
|
* @param status_flags1 descriptor status flags to set on write end of pipe.
|
|
* @param fds may be supplied to open an existing file descriptors rather
|
|
* than create ones from a new pipe. Should point to memory containing
|
|
* two consecutive file descriptors, the "read" one and then the "write" one.
|
|
*/
|
|
explicit Pipe(int flags0 = 0, int flags1 = 0, int status_flags0 = 0, int status_flags1 = 0,
|
|
int* fds = nullptr);
|
|
|
|
/**
|
|
* Close the pair of file descriptors owned by the object.
|
|
*/
|
|
~Pipe();
|
|
|
|
/**
|
|
* Make a copy of another Pipe object (file descriptors are dup'd).
|
|
*/
|
|
Pipe(const Pipe& other);
|
|
|
|
/**
|
|
* Assign a Pipe object by closing file descriptors and duping those of
|
|
* the other.
|
|
*/
|
|
Pipe& operator=(const Pipe& other);
|
|
|
|
/**
|
|
* @return the file descriptor associated with the read-end of the pipe.
|
|
*/
|
|
int ReadFD() const { return fds[0]; }
|
|
|
|
/**
|
|
* @return the file descriptor associated with the write-end of the pipe.
|
|
*/
|
|
int WriteFD() const { return fds[1]; }
|
|
|
|
/**
|
|
* Sets the given file descriptor flags for both the read and write end
|
|
* of the pipe.
|
|
*/
|
|
void SetFlags(int flags);
|
|
|
|
/**
|
|
* Unsets the given file descriptor flags for both the read and write end
|
|
* of the pipe.
|
|
*/
|
|
void UnsetFlags(int flags);
|
|
|
|
private:
|
|
int fds[2];
|
|
int flags[2];
|
|
int status_flags[2];
|
|
};
|
|
|
|
/**
|
|
* A pair of pipes that can be used for bi-directional IPC.
|
|
*/
|
|
class PipePair
|
|
{
|
|
public:
|
|
/**
|
|
* Create a pair of pipes
|
|
* @param flags file descriptor flags to set on pipes
|
|
* @status_flags descriptor status flags to set on pipes
|
|
* @fds may be supplied to open existing file descriptors rather
|
|
* than create ones from a new pair of pipes. Should point to memory
|
|
* containing four consecutive file descriptors, "read" end and "write" end
|
|
* of the first pipe followed by the "read" end and "write" end of the
|
|
* second pipe.
|
|
*/
|
|
PipePair(int flags, int status_flags, int* fds = nullptr);
|
|
|
|
/**
|
|
* @return the pipe used for receiving input
|
|
*/
|
|
Pipe& In() { return pipes[swapped]; }
|
|
|
|
/**
|
|
* @return the pipe used for sending output
|
|
*/
|
|
Pipe& Out() { return pipes[! swapped]; }
|
|
|
|
/**
|
|
* @return the pipe used for receiving input
|
|
*/
|
|
const Pipe& In() const { return pipes[swapped]; }
|
|
|
|
/**
|
|
* @return the pipe used for sending output
|
|
*/
|
|
const Pipe& Out() const { return pipes[! swapped]; }
|
|
|
|
/**
|
|
* @return a file descriptor that may used for receiving messages by
|
|
* polling/reading it.
|
|
*/
|
|
int InFD() const { return In().ReadFD(); }
|
|
|
|
/**
|
|
* @return a file descriptor that may be used for sending messages by
|
|
* writing to it.
|
|
*/
|
|
int OutFD() const { return Out().WriteFD(); }
|
|
|
|
/**
|
|
* Swaps the meaning of the pipes in the pair. E.g. call this after
|
|
* fork()'ing so that the child process uses the right pipe for
|
|
* reading/writing.
|
|
*/
|
|
void Swap() { swapped = ! swapped; }
|
|
|
|
private:
|
|
Pipe pipes[2];
|
|
bool swapped = false;
|
|
};
|
|
|
|
} // namespace zeek::detail
|