9 #ifndef CPPSERVER_NANOMSG_SERVER_H 10 #define CPPSERVER_NANOMSG_SERVER_H 14 #include "threads/thread.h" 39 explicit Server(
Domain domain,
Protocol protocol,
const std::string& address,
bool threading =
true);
75 size_t Send(
const void* buffer,
size_t size);
81 size_t Send(
const std::string& text) {
return Send(text.data(), text.size()); }
95 size_t TrySend(
const void* buffer,
size_t size);
101 size_t TrySend(
const std::string& text) {
return TrySend(text.data(), text.size()); }
141 virtual void onIdle() { CppCommon::Thread::Yield(); }
154 virtual void onError(
int error,
const std::string& message) {}
158 std::string _address;
161 std::atomic<bool> _connected;
165 std::atomic<bool> _joining;
166 std::atomic<bool> _receiving;
175 #endif // CPPSERVER_NANOMSG_SERVER_H
size_t TrySend(const std::string &text)
Try to send a text string to the client in non-blocking mode.
virtual void onStarted()
Handle server started notification.
size_t Send(const void *buffer, size_t size)
Send data to the client.
bool Start()
Start the server.
size_t size() const noexcept
Get the message size.
size_t TryReceive(Message &message)
Try to receive a message from the client in non-blocking mode.
Socket & socket() noexcept
Get the Nanomsg socket.
C++ Server project definitions.
bool Restart()
Restart the server.
bool Stop()
Stop the server.
virtual void onThreadCleanup()
Cleanup thread handler.
virtual void onIdle()
Handle server idle notification.
virtual void onThreadInitialize()
Initialize thread handler.
Server(Domain domain, Protocol protocol, const std::string &address, bool threading=true)
Initialize server with a given domain, protocol and endpoint address.
size_t Send(const std::string &text)
Send a text string to the client.
uint8_t * buffer() noexcept
Get the message buffer.
Server & operator=(const Server &)=delete
virtual void onReceived(Message &message)
Handle message received notification.
bool IsStarted() const noexcept
Is the server started?
bool IsConnected() const noexcept
Is socket connected?
size_t Send(const Message &message)
Send a message to the client.
Protocol
Nanomsg protocol.
size_t Receive(Message &message)
Receive a message from the client.
virtual void onError(int error, const std::string &message)
Handle error notification.
Nanomsg socket definition.
size_t TrySend(const void *buffer, size_t size)
Try to send data to the client in non-blocking mode.
bool IsOpened() const noexcept
Is socket opened?
size_t TrySend(const Message &message)
Try to send a message to the client in non-blocking mode.
virtual void onStopped()
Handle server stopped notification.