Max OS 0.3
Loading...
Searching...
No Matches
MaxOS::processes::SharedMessageEndpoint Class Referencefinal

A endpoint that allows processes to queue messages on. More...

#include <ipc.h>

Inheritance diagram for MaxOS::processes::SharedMessageEndpoint:

Public Member Functions

 SharedMessageEndpoint (const string &name, size_t size, resources::resource_type_t type)
 Creates a new shared message endpoint.
 
 ~SharedMessageEndpoint () final
 Destroys the shared message endpoint and frees all messages.
 
void send (const ipc_iovec_t *vec, size_t count)
 Combines a multipart message and sends it to the endpoint.
 
int read (void *buffer, size_t size, size_t flags) final
 Reads the first message from the endpoint or will yield until a message has been written.
 
int write (const void *buffer, size_t size, size_t flags) final
 Handles writing to the message endpoint resource by writing the buffer as a message.
 

Detailed Description

A endpoint that allows processes to queue messages on.

Definition at line 70 of file ipc.h.

Constructor & Destructor Documentation

◆ SharedMessageEndpoint()

SharedMessageEndpoint::SharedMessageEndpoint ( const string &  name,
size_t  size,
resources::resource_type_t  type 
)

Creates a new shared message endpoint.

Parameters
nameThe name of the endpoint
sizeThe size of messages that can be sent
typeThe type of resource

Definition at line 112 of file ipc.cpp.

113: Resource(name, size, type)
114{
115
116}
KPI::Resource Resource
Alias to make the libsyscore Resource accessible here.
Definition resource.h:26

◆ ~SharedMessageEndpoint()

SharedMessageEndpoint::~SharedMessageEndpoint ( )
final

Destroys the shared message endpoint and frees all messages.

Definition at line 121 of file ipc.cpp.

121 {
122
123 // Free the messages
124 for(auto& message : m_queue)
125 delete message;
126}

Member Function Documentation

◆ read()

int SharedMessageEndpoint::read ( void *  buffer,
size_t  size,
size_t  flags 
)
final

Reads the first message from the endpoint or will yield until a message has been written.

Parameters
bufferWhere to write the message to
sizeMax size of the message to be read
flags0 to block, 1 for async
Returns
The amount of bytes read (0 means no messages available for async)
Todo:
int here to size_t in syscall - fix

Definition at line 165 of file ipc.cpp.

165 {
166
167 // Wait for a message
168 while(m_queue.empty()) {
169 if (flags)
170 return 0;
171
172 // Block
174 }
175
176 // Read the message into the buffer
177 buffer_t* message = m_queue.pop_front();
178 size_t readable = size > message->capacity() ? message->capacity() : size;
179 memcpy(buffer, message -> raw(), readable);
180
181 //@todo free the message mem here now aswell?
182
183 return readable;
184}
static Thread * current_thread()
Gets the thread on the currently executing core.
void yield()
Pass execution to the next ready thread.
Definition process.cpp:103

References MaxOS::processes::GlobalScheduler::current_thread(), and MaxOS::processes::Thread::yield().

◆ send()

void SharedMessageEndpoint::send ( const ipc_iovec_t *  vec,
size_t  count 
)

Combines a multipart message and sends it to the endpoint.

Parameters
vecThe io vector containing the parts
countHow many entries the vector has
Todo:
validate stuff

Definition at line 135 of file ipc.cpp.

135 {
136
137 m_message_lock.lock();
138
139 // Parse the message parts
140 size_t size = 0;
141 for (size_t i = 0; i < count; ++i)
142 size += vec[i].length;
143
144 // Create the message
145 auto* new_message = new buffer_t(size);
146 for (size_t i = 0; i < count; ++i)
147 new_message->copy_from(vec[i].address, vec[i].length);
148
149 // Send the message
150 m_queue.push_back(new_message);
151 m_message_lock.unlock();
152
153}
void lock()
Lock the spinlock once it is available, sleeping until other processes are done with it.
Definition block.cpp:23
void unlock()
Unlock the spinlock.
Definition block.cpp:30

References MaxOS::processes::BlockingLock::lock(), and MaxOS::processes::BlockingLock::unlock().

Referenced by write().

◆ write()

int SharedMessageEndpoint::write ( const void *  buffer,
size_t  size,
size_t  flags 
)
final

Handles writing to the message endpoint resource by writing the buffer as a message.

Parameters
bufferThe message to write to the endpoint
sizeThe size of the message
flagsUnused
Returns
The amount of bytes written

Definition at line 194 of file ipc.cpp.

194 {
195
196 // Send the buffer as the entire message
197 ipc_iovec_t message = {buffer, size};
198 send(&message, 1);
199
200 return size;
201}
void send(const ipc_iovec_t *vec, size_t count)
Combines a multipart message and sends it to the endpoint.
Definition ipc.cpp:135
Read/Write call entry for a list of I/O requests in a RPC call.
Definition ipc.h:34

References send().


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