34#ifndef _UTILS_HUBDEVICE_HXX_
35#define _UTILS_HUBDEVICE_HXX_
150 while (done <
unit())
166 if ((ret < 0) && (errno == EINTR || errno == EAGAIN))
171#if OPENMRN_FEATURE_BSD_SOCKETS_REPORT_EOF_ERROR
179 errno, strerror(errno));
231 reinterpret_cast<const uint8_t *
>(this->
message()->data()->data());
232 size_t size = this->
message()->data()->size();
245 return this->release_and_exit();
248 ssize_t ret = ::write(
port_->
fd_, buf, size);
256#if OPENMRN_FEATURE_BSD_SOCKETS_REPORT_EOF_ERROR
270 return this->release_and_exit();
330 port->kReadThreadStackSize);
See OSMutexLock in os/OS.hxx.
Lightweight locking class for protecting small critical sections.
This class sends a notification in its destructor.
A BarrierNotifiable allows to create a number of child Notifiable and wait for all of them to finish.
BarrierNotifiable * new_child()
Call this for each child task.
Base class for all QMember types that hold data in an expandable format.
void shutdown()
Terminates the executor thread.
Implementation the ExecutorBase with a specific number of priority bands.
Read thread implementation with template-inspecific methods.
void * entry() OVERRIDE
User entry point for the created thread.
ReadThreadBase(FdHubPortBase *port)
Constructor.
virtual void send_message(const void *buf, int size)=0
Sends off a buffer.
FdHubPortBase * port_
Parent port.
Template-nonspecific base class for FdHubPort.
static void fill_thread_name(char *buf, char mode, int fd)
Puts the desired thread name for the read or write thread.
unsigned hasError_
If this is 1, the fd has been closed.
void report_error()
Call when an IO error is encountered.
static const int kReadThreadStackSize
How many bytes of stack should we allocate to the read thread's stack.
FdHubPortBase(int fd, Notifiable *done)
Constructor.
char threadName_[30]
Temporary buffer used for rendering thread names.
Service writeService_
Service for the write flow.
static const int kWriteThreadStackSize
How many bytes of stack should we allocate to the write thread's stack.
Executor< 1 > writeThread_
This executor is running the writes.
BarrierNotifiable barrier_
This barrier will be notified when both read and write thread has exited.
const char * fill_thread_name(char mode, int fd)
Puts the desired thread name for the read or write thread.
virtual void unregister_write_port()=0
Removes the write flow from the hub's registration.
unsigned writeExitEnqueued_
If this is 1, we have already enqueued the request to exit the write flow.
Shared base class for thread-based and select-based hub devices.
int fd_
The device file descriptor.
Thread performing the read operations on the device.
void init()
Initializes the semaphore notifiables.
static const int kUnit
This is the minimum number of bytes that we will send.
SemaphoreNotifiableBlock * semaphores_
If non-null, one slot will be acquired for each incoming message.
void send_message(const void *buf, int size) OVERRIDE
Sends off a buffer.
ReadThread(FdHubPort< HFlow > *port)
Constructor.
static const int kBufSize
We will allocate this many bytes for read buffer.
FdHubPort< HFlow > * port()
HubPort that connects a raw device to a strongly typed Hub.
FdHubPort(HFlow *hub, int fd, Notifiable *done)
Constructor.
HFlow * hub_
Parent hub to send the data to / read the data from.
FdHubWriteFlow< typename HFlow::value_type > writeFlow_
StateFlow that is performing the actual writes.
void unregister_write_port() OVERRIDE
Removes the write flow from the hub's registration.
ReadThread readThread_
An OSThread child that is performing the reads.
State flow for writing data to an fd.
FdHubPortBase * port_
The owning port.
StateFlowBase::Action entry() OVERRIDE
Handles the next incoming entry.
FdHubWriteFlow(FdHubPortBase *parent)
Constructor.
MessageType * alloc()
Synchronously allocates a message buffer from the pool of this flow.
An object that can schedule itself on an executor to run.
This class provides a threading API.
void start(const char *name, int priority, size_t stack_size)
Starts the thread.
A block of BarrierNotifiable objects, with a synchronous allocation call.
Collection of related state machines that pend on incoming messages.
Return type for a state flow callback.
State flow with a given typed input queue.
void release() OVERRIDE
Unrefs the current buffer.
void send(MessageType *msg, unsigned priority=UINT_MAX) OVERRIDE
Sends a message to the state flow for processing.
#define LOG_ERROR(message...)
Shorthand for LOG(LEVEL_ERROR, message...). See LOG.
#define OVERRIDE
Function attribute for virtual functions declaring that this funciton is overriding a funciton that s...