2019-04-08 12:01:52 +00:00
|
|
|
#ifndef LLARP_EV_PIPE_HPP
|
|
|
|
#define LLARP_EV_PIPE_HPP
|
|
|
|
|
|
|
|
#include <ev/ev.hpp>
|
|
|
|
|
2019-04-08 14:04:58 +00:00
|
|
|
/// a unidirectional packet pipe
|
|
|
|
struct llarp_ev_pkt_pipe : public llarp::ev_io
|
2019-04-08 12:01:52 +00:00
|
|
|
{
|
2019-04-08 14:04:58 +00:00
|
|
|
llarp_ev_pkt_pipe(llarp_ev_loop_ptr loop);
|
|
|
|
|
|
|
|
/// start the pipe, initialize fds
|
|
|
|
bool
|
2019-08-22 11:18:05 +00:00
|
|
|
StartPipe();
|
2019-04-08 14:04:58 +00:00
|
|
|
|
|
|
|
/// write to the pipe from outside the event loop
|
|
|
|
/// returns true on success
|
|
|
|
/// returns false on failure
|
|
|
|
bool
|
|
|
|
Write(const llarp_buffer_t& buf);
|
|
|
|
|
|
|
|
/// override me to handle a packet from the other side in the owned event loop
|
|
|
|
virtual void
|
|
|
|
OnRead(const llarp_buffer_t& buf) = 0;
|
|
|
|
|
|
|
|
ssize_t
|
|
|
|
do_write(void* buf, size_t sz) override;
|
|
|
|
|
2019-07-30 23:42:13 +00:00
|
|
|
bool
|
2019-04-08 14:04:58 +00:00
|
|
|
tick() override;
|
|
|
|
|
|
|
|
int
|
|
|
|
read(byte_t* buf, size_t sz) override;
|
2019-04-08 12:01:52 +00:00
|
|
|
|
|
|
|
private:
|
2019-04-08 14:04:58 +00:00
|
|
|
llarp_ev_loop_ptr m_Loop;
|
|
|
|
int writefd;
|
2019-04-08 12:01:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|