JX Application Framework
|
#include <JMessageProtocol.h>
Public Member Functions | |
JMessageProtocol (const bool synchSend=false) | |
JMessageProtocol (const ACE_HANDLE fd, const bool synchSend=false) | |
~JMessageProtocol () override | |
void | GetProtocol (JString *separator, JString *disconnect) const |
void | SetProtocol (const JUtf8Byte *separatorStr, const JSize separatorByteCount, const JUtf8Byte *disconnectStr, const JSize disconnectByteCount) |
void | UseUNIXProtocol () |
void | UseMacintoshProtocol () |
void | UseDOSProtocol () |
bool | ReceivedDisconnect () const |
void | SendDisconnect () |
bool | HasMessages () const |
JSize | GetMessageCount () const |
bool | GetNextMessage (JString *message) |
bool | PeekNextMessage (JString *message) |
bool | PeekPartialMessage (JString *message) |
void | SendMessage (const JString &message) |
void | SendData (const JString &data) |
bool | WantsBlankMessages () const |
void | SetWantsBlankMessages (const bool wantsBlanks=true) |
JSize | GetBufferSize () const |
void | SetBufferSize (const JSize bufferSize) |
int | handle_input (ACE_HANDLE) override |
![]() | |
JNetworkProtocolBase (const bool synch) | |
~JNetworkProtocolBase () override | |
bool | DataPending () const |
void | Flush () |
bool | WillSendSynch () const |
void | ShouldSendSynch (const bool synch=true) |
int | handle_output (ACE_HANDLE) override |
![]() | |
JBroadcaster () | |
virtual | ~JBroadcaster () |
JBroadcaster & | operator= (const JBroadcaster &source) |
bool | HasSenders () const |
JSize | GetSenderCount () const |
bool | HasRecipients () const |
JSize | GetRecipientCount () const |
virtual JString | ToString () const |
template<class T > | |
void | ListenTo (const JBroadcaster *sender, const std::function< void(const T &)> &f) |
Protected Member Functions | |
bool | BytesEqual (const JString &s1, const JString &s2) const |
![]() | |
void | Send (const JString &data) |
void | Send (const JUtf8Byte *data, const JSize count) |
void | Send (const iovec data[], const JSize count) |
![]() | |
JBroadcaster (const JBroadcaster &source) | |
void | ListenTo (const JBroadcaster *sender) |
void | StopListening (const JBroadcaster *sender) |
void | ClearWhenGoingAway (const JBroadcaster *sender, void *pointerToMember) |
void | StopListening (const JBroadcaster *sender, const std::type_info &messageType) |
template<class T > | |
void | Send (JBroadcaster *recipient, const T &message) |
template<class T > | |
void | Broadcast (const T &message) |
virtual void | Receive (JBroadcaster *sender, const Message &message) |
void | SendWithFeedback (JBroadcaster *recipient, Message *message) |
void | BroadcastWithFeedback (Message *message) |
virtual void | ReceiveWithFeedback (JBroadcaster *sender, Message *message) |
virtual void | ReceiveGoingAway (JBroadcaster *sender) |
JMessageProtocol< ACE_PEER_STREAM_1 >::JMessageProtocol | ( | const bool | synchSend = false | ) |
Parses incoming bytes into messages separated by itsSeparatorStr.
The data that you send can contain any byte sequence other than itsDisconnectStr. This sequence is reserved for terminating the connection. (You can set itsDisconnectStr to be empty.)
The default is the UNIX protocol which uses "\n" as separator and "\0" as terminator. Macintosh sets the separator to "\r", and DOS sets the separator to "\r\n". In general, the separator must not contain the terminator, and visa versa.
You cannot use the std::function version of ListenTo() because the way this class broadcasts confuses the type inference.
JMessageProtocol< ACE_PEER_STREAM_1 >::JMessageProtocol | ( | const ACE_HANDLE | fd, |
const bool | synchSend = false |
||
) |
|
override |
Client must call SendDisconnect() explicitly. This makes their code clearer. It also allows using this class on read-only connections because the client can ensure that nothing will ever be written.
|
protected |
Compare raw bytes because control characters are often zero-length in UTF-8.
JSize JMessageProtocol< ACE_PEER_STREAM_1 >::GetBufferSize | ( | ) | const |
This controls how much is read from the connection at one time.
JSize JMessageProtocol< ACE_PEER_STREAM_1 >::GetMessageCount | ( | ) | const |
bool JMessageProtocol< ACE_PEER_STREAM_1 >::GetNextMessage | ( | JString * | message | ) |
Stores the next complete message in *message and removes it from the queue. Returns false if no complete messages are available.
void JMessageProtocol< ACE_PEER_STREAM_1 >::GetProtocol | ( | JString * | separator, |
JString * | disconnect | ||
) | const |
|
override |
This is called when we receive data. It is also safe for anybody else to call it.
bool JMessageProtocol< ACE_PEER_STREAM_1 >::HasMessages | ( | ) | const |
bool JMessageProtocol< ACE_PEER_STREAM_1 >::PeekNextMessage | ( | JString * | message | ) |
Stores the next complete message in *message. Returns false if no complete messages are available.
bool JMessageProtocol< ACE_PEER_STREAM_1 >::PeekPartialMessage | ( | JString * | message | ) |
Stores the message that is being received in *message. Returns false if the message is empty.
bool JMessageProtocol< ACE_PEER_STREAM_1 >::ReceivedDisconnect | ( | ) | const |
void JMessageProtocol< ACE_PEER_STREAM_1 >::SendData | ( | const JString & | data | ) |
Sends the given data without a separator. The data can contain separators.
void JMessageProtocol< ACE_PEER_STREAM_1 >::SendDisconnect | ( | ) |
void JMessageProtocol< ACE_PEER_STREAM_1 >::SendMessage | ( | const JString & | message | ) |
Sends the given data and then a separator. The data can contain separators.
void JMessageProtocol< ACE_PEER_STREAM_1 >::SetBufferSize | ( | const JSize | bufferSize | ) |
void JMessageProtocol< ACE_PEER_STREAM_1 >::SetProtocol | ( | const JUtf8Byte * | separatorStr, |
const JSize | separatorByteCount, | ||
const JUtf8Byte * | disconnectStr, | ||
const JSize | disconnectByteCount | ||
) |
void JMessageProtocol< ACE_PEER_STREAM_1 >::SetWantsBlankMessages | ( | const bool | wantsBlanks = true | ) |
void JMessageProtocol< ACE_PEER_STREAM_1 >::UseDOSProtocol | ( | ) |
void JMessageProtocol< ACE_PEER_STREAM_1 >::UseMacintoshProtocol | ( | ) |
void JMessageProtocol< ACE_PEER_STREAM_1 >::UseUNIXProtocol | ( | ) |
bool JMessageProtocol< ACE_PEER_STREAM_1 >::WantsBlankMessages | ( | ) | const |