SNode.C
Loading...
Searching...
No Matches
core::pipe::PipeSource Class Reference

#include <PipeSource.h>

Inheritance diagram for core::pipe::PipeSource:
Collaboration diagram for core::pipe::PipeSource:

Public Member Functions

 PipeSource (const PipeSource &)=delete
 
PipeSourceoperator= (const PipeSource &)=delete
 
 PipeSource (int fd)
 
 ~PipeSource () override
 
void send (const char *chunk, std::size_t chunkLen)
 
void send (const std::string &data)
 
void eof ()
 
void setOnError (const std::function< void(int)> &onError)
 
- Public Member Functions inherited from core::DescriptorEventReceiver
 DescriptorEventReceiver (const std::string &name, DescriptorEventPublisher &descriptorEventPublisher, const utils::Timeval &timeout=TIMEOUT::DISABLE)
 
int getRegisteredFd () const
 
bool isEnabled () const
 
bool isSuspended () const
 
void setTimeout (const utils::Timeval &timeout)
 
utils::Timeval getTimeout (const utils::Timeval &currentTime) const
 
void checkTimeout (const utils::Timeval &currentTime)
 
- Public Member Functions inherited from core::EventReceiver
 EventReceiver (const std::string &name)
 
 EventReceiver (EventReceiver &)=delete
 
 EventReceiver (EventReceiver &&)=delete
 
EventReceiveroperator= (EventReceiver &)=delete
 
EventReceiveroperator= (EventReceiver &&)=delete
 
virtual void destruct ()
 
void span ()
 
void relax ()
 
const std::string & getName () const
 

Protected Member Functions

void writeEvent () override
 
void unobservedEvent () override
 
- Protected Member Functions inherited from core::eventreceiver::WriteEventReceiver
 WriteEventReceiver (const std::string &name, const utils::Timeval &timeout)
 
virtual void writeTimeout ()
 
- Protected Member Functions inherited from core::DescriptorEventReceiver
bool enable (int fd)
 
void disable ()
 
void suspend ()
 
void resume ()
 
- Protected Member Functions inherited from core::Observer
void observed ()
 
void unObserved ()
 
 Observer ()=default
 
 Observer (Observer &)=delete
 
 Observer (Observer &&)=delete
 
virtual ~Observer ()
 
- Protected Member Functions inherited from core::EventReceiver
virtual ~EventReceiver ()=default
 
 EventReceiver (const std::string &name)
 
 EventReceiver (EventReceiver &)=delete
 
 EventReceiver (EventReceiver &&)=delete
 
EventReceiveroperator= (EventReceiver &)=delete
 
EventReceiveroperator= (EventReceiver &&)=delete
 
virtual void destruct ()
 
void span ()
 
void relax ()
 
const std::string & getName () const
 

Private Attributes

std::function< void(int errnum)> onError
 
std::vector< char > writeBuffer
 

Additional Inherited Members

- Static Public Member Functions inherited from core::EventReceiver
static void atNextTick (const std::function< void(void)> &callBack)
 
- Static Protected Member Functions inherited from core::EventReceiver
static void atNextTick (const std::function< void(void)> &callBack)
 

Detailed Description

Definition at line 36 of file PipeSource.h.

Constructor & Destructor Documentation

◆ PipeSource() [1/2]

core::pipe::PipeSource::PipeSource ( const PipeSource & )
delete

◆ PipeSource() [2/2]

core::pipe::PipeSource::PipeSource ( int fd)
explicit

Definition at line 38 of file PipeSource.cpp.

39 : core::eventreceiver::WriteEventReceiver("PipeSource fd = " + std::to_string(fd), 60) {
40 if (!WriteEventReceiver::enable(fd)) {
41 delete this;
42 } else {
43 WriteEventReceiver::suspend();
44 }
45 }

References core::DescriptorEventReceiver::enable(), PipeSource(), and core::DescriptorEventReceiver::suspend().

Referenced by core::pipe::Pipe::Pipe(), and PipeSource().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ~PipeSource()

core::pipe::PipeSource::~PipeSource ( )
override

Definition at line 47 of file PipeSource.cpp.

47 {
49 }
int close(int fd)
Definition unistd.cpp:45

References core::DescriptorEventReceiver::getRegisteredFd().

Here is the call graph for this function:

Member Function Documentation

◆ eof()

void core::pipe::PipeSource::eof ( )

Definition at line 67 of file PipeSource.cpp.

67 {
68 WriteEventReceiver::disable();
69 }

References core::DescriptorEventReceiver::disable().

Here is the call graph for this function:

◆ operator=()

PipeSource & core::pipe::PipeSource::operator= ( const PipeSource & )
delete

◆ send() [1/2]

void core::pipe::PipeSource::send ( const char * chunk,
std::size_t chunkLen )

Definition at line 55 of file PipeSource.cpp.

55 {
56 writeBuffer.insert(writeBuffer.end(), chunk, chunk + chunkLen);
57
58 if (WriteEventReceiver::isSuspended()) {
59 WriteEventReceiver::resume();
60 }
61 }
std::vector< char > writeBuffer
Definition PipeSource.h:58

References core::DescriptorEventReceiver::isSuspended(), and core::DescriptorEventReceiver::resume().

Here is the call graph for this function:

◆ send() [2/2]

void core::pipe::PipeSource::send ( const std::string & data)

Definition at line 63 of file PipeSource.cpp.

63 {
64 send(data.data(), data.size());
65 }
void send(const char *chunk, std::size_t chunkLen)

◆ setOnError()

void core::pipe::PipeSource::setOnError ( const std::function< void(int)> & onError)

Definition at line 51 of file PipeSource.cpp.

51 {
52 this->onError = onError;
53 }
std::function< void(int errnum)> onError
Definition PipeSource.h:56

◆ unobservedEvent()

void core::pipe::PipeSource::unobservedEvent ( )
overrideprotectedvirtual

Implements core::Observer.

Definition at line 90 of file PipeSource.cpp.

90 {
91 delete this;
92 }

◆ writeEvent()

void core::pipe::PipeSource::writeEvent ( )
overrideprotectedvirtual

Implements core::eventreceiver::WriteEventReceiver.

Definition at line 71 of file PipeSource.cpp.

71 {
72 const ssize_t ret = core::system::write(
74
75 if (ret > 0) {
76 writeBuffer.erase(writeBuffer.begin(), writeBuffer.begin() + ret);
77
78 if (writeBuffer.empty()) {
79 WriteEventReceiver::suspend();
80 }
81 } else if (errno != EAGAIN && errno != EWOULDBLOCK && errno != EINTR) {
82 WriteEventReceiver::disable();
83
84 if (onError) {
85 onError(errno);
86 }
87 }
88 }
#define MAX_SEND_JUNKSIZE
ssize_t write(int fd, const void *buf, std::size_t count)
Definition unistd.cpp:40

References core::DescriptorEventReceiver::disable(), and core::DescriptorEventReceiver::suspend().

Here is the call graph for this function:

Member Data Documentation

◆ onError

std::function<void(int errnum)> core::pipe::PipeSource::onError
private

Definition at line 56 of file PipeSource.h.

◆ writeBuffer

std::vector<char> core::pipe::PipeSource::writeBuffer
private

Definition at line 58 of file PipeSource.h.


The documentation for this class was generated from the following files: