summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2026-04-09 23:02:54 +0200
committerCarl Hetherington <cth@carlh.net>2026-04-09 23:02:54 +0200
commitc11c50e7addfd9acce51ee64f11d8a03af4bd864 (patch)
tree6bbdafda6faf94586dc353d92841ed2b51d3a438 /src/lib
parented686c73b22ff7093f18653f3d3831ef1162d2ba (diff)
White space: nanomsg.{cc,h}
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/nanomsg.cc39
-rw-r--r--src/lib/nanomsg.h16
2 files changed, 27 insertions, 28 deletions
diff --git a/src/lib/nanomsg.cc b/src/lib/nanomsg.cc
index fe3827247..4ec37635e 100644
--- a/src/lib/nanomsg.cc
+++ b/src/lib/nanomsg.cc
@@ -36,9 +36,9 @@ using boost::optional;
#define NANOMSG_URL "ipc:///tmp/dcpomatic.ipc"
-Nanomsg::Nanomsg (bool server)
+Nanomsg::Nanomsg(bool server)
{
- _socket = nn_socket (AF_SP, NN_PAIR);
+ _socket = nn_socket(AF_SP, NN_PAIR);
if (_socket < 0) {
throw runtime_error("Could not set up nanomsg socket");
}
@@ -54,21 +54,21 @@ Nanomsg::Nanomsg (bool server)
}
-Nanomsg::~Nanomsg ()
+Nanomsg::~Nanomsg()
{
- nn_shutdown (_socket, _endpoint);
- nn_close (_socket);
+ nn_shutdown(_socket, _endpoint);
+ nn_close(_socket);
}
bool
-Nanomsg::send (string s, int timeout)
+Nanomsg::send(string s, int timeout)
{
if (timeout != 0) {
- nn_setsockopt (_socket, NN_SOL_SOCKET, NN_SNDTIMEO, &timeout, sizeof(int));
+ nn_setsockopt(_socket, NN_SOL_SOCKET, NN_SNDTIMEO, &timeout, sizeof(int));
}
- int const r = nn_send (_socket, s.c_str(), s.length(), timeout ? 0 : NN_DONTWAIT);
+ int const r = nn_send(_socket, s.c_str(), s.length(), timeout ? 0 : NN_DONTWAIT);
if (r < 0) {
if (errno == ETIMEDOUT || errno == EAGAIN) {
return false;
@@ -83,7 +83,7 @@ Nanomsg::send (string s, int timeout)
optional<string>
-Nanomsg::get_from_pending ()
+Nanomsg::get_from_pending()
{
if (_pending.empty()) {
return {};
@@ -96,10 +96,10 @@ Nanomsg::get_from_pending ()
void
-Nanomsg::recv_and_parse (int flags)
+Nanomsg::recv_and_parse(int flags)
{
char* buf = 0;
- int const received = nn_recv (_socket, &buf, NN_MSG, flags);
+ int const received = nn_recv(_socket, &buf, NN_MSG, flags);
if (received < 0)
{
if (errno == ETIMEDOUT || errno == EAGAIN) {
@@ -107,36 +107,35 @@ Nanomsg::recv_and_parse (int flags)
}
LOG_DISK("nn_recv failed");
- throw CommunicationFailedError ();
+ throw CommunicationFailedError();
}
char* p = buf;
for (int i = 0; i < received; ++i) {
if (*p == '\n') {
- _pending.push_front (_current);
+ _pending.push_front(_current);
_current = "";
} else {
_current += *p;
}
++p;
}
- nn_freemsg (buf);
+ nn_freemsg(buf);
}
optional<string>
-Nanomsg::receive (int timeout)
+Nanomsg::receive(int timeout)
{
if (timeout != 0) {
- nn_setsockopt (_socket, NN_SOL_SOCKET, NN_RCVTIMEO, &timeout, sizeof(int));
+ nn_setsockopt(_socket, NN_SOL_SOCKET, NN_RCVTIMEO, &timeout, sizeof(int));
}
- auto l = get_from_pending ();
- if (l) {
+ if (auto l = get_from_pending()) {
return *l;
}
- recv_and_parse (timeout ? 0 : NN_DONTWAIT);
+ recv_and_parse(timeout ? 0 : NN_DONTWAIT);
- return get_from_pending ();
+ return get_from_pending();
}
diff --git a/src/lib/nanomsg.h b/src/lib/nanomsg.h
index 8d89d6d99..bd15a670f 100644
--- a/src/lib/nanomsg.h
+++ b/src/lib/nanomsg.h
@@ -27,27 +27,27 @@
class Nanomsg
{
public:
- explicit Nanomsg (bool server);
- ~Nanomsg ();
+ explicit Nanomsg(bool server);
+ ~Nanomsg();
- Nanomsg (Nanomsg const&) = delete;
- Nanomsg& operator= (Nanomsg const&) = delete;
+ Nanomsg(Nanomsg const&) = delete;
+ Nanomsg& operator=(Nanomsg const&) = delete;
/** Try to send a message, waiting for some timeout before giving up.
* @param timeout Timeout in milliseconds, or -1 for infinite timeout.
* @return true if the send happened, false if there was a timeout.
*/
- bool send (std::string s, int timeout);
+ bool send(std::string s, int timeout);
/** Try to receive a message, waiting for some timeout before giving up.
* @param timeout Timeout in milliseconds, or -1 for infinite timeout.
* @return Empty if the timeout was reached, otherwise the received string.
*/
- boost::optional<std::string> receive (int timeout);
+ boost::optional<std::string> receive(int timeout);
private:
- boost::optional<std::string> get_from_pending ();
- void recv_and_parse (int flags);
+ boost::optional<std::string> get_from_pending();
+ void recv_and_parse(int flags);
int _socket;
int _endpoint;