From d4f2064e6e0ccc1d07e693b6becaadc365ff4bfa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20Schl=C3=BCter?= Date: Tue, 27 Jul 2021 19:42:58 +0900 Subject: [PATCH] Remove redundant static_cast in examples. Not only is it unnecessary because zmq::socket_t automatically converts to void* via operator void*, it is also misleading as the operator is called in spite of the appearance that it's just a cast. Now, other comments in zmq.hpp indicate that this is not really the intent (note the comments near the bool conversion), and I believe the cleanest fix would be to add a member to zmq::socket_t that returns the void* needed for polling (.pollable()? I really can't find a good name), or for zmq::pollitem_t to handle the conversion transparently. --- examples/C++/asyncsrv.cpp | 2 +- examples/C++/lbbroker.cpp | 6 +++--- examples/C++/lpclient.cpp | 2 +- examples/C++/mdbroker.cpp | 2 +- examples/C++/mdcliapi.hpp | 2 +- examples/C++/mdcliapi2.hpp | 2 +- examples/C++/mdwrkapi.hpp | 2 +- examples/C++/mspoller.cpp | 4 ++-- examples/C++/ppqueue.cpp | 4 ++-- examples/C++/rrbroker.cpp | 4 ++-- examples/C++/spqueue.cpp | 4 ++-- examples/C++/taskwork2.cpp | 4 ++-- examples/C++/tripping.cpp | 4 ++-- 13 files changed, 21 insertions(+), 21 deletions(-) diff --git a/examples/C++/asyncsrv.cpp b/examples/C++/asyncsrv.cpp index 42e34e761..614fb3925 100644 --- a/examples/C++/asyncsrv.cpp +++ b/examples/C++/asyncsrv.cpp @@ -35,7 +35,7 @@ class client_task { client_socket_.connect("tcp://localhost:5570"); zmq::pollitem_t items[] = { - { static_cast(client_socket_), 0, ZMQ_POLLIN, 0 } }; + { client_socket_, 0, ZMQ_POLLIN, 0 } }; int request_nbr = 0; try { while (true) { diff --git a/examples/C++/lbbroker.cpp b/examples/C++/lbbroker.cpp index 89f978e14..b2758e01f 100644 --- a/examples/C++/lbbroker.cpp +++ b/examples/C++/lbbroker.cpp @@ -105,10 +105,10 @@ int main(int argc, char *argv[]) // Initialize poll set zmq::pollitem_t items[] = { - // Always poll for worker activity on backend - { static_cast(backend), 0, ZMQ_POLLIN, 0 }, + // Always poll for worker activity on backend + { backend, 0, ZMQ_POLLIN, 0 }, // Poll front-end only if we have available workers - { static_cast(frontend), 0, ZMQ_POLLIN, 0 } + { frontend, 0, ZMQ_POLLIN, 0 } }; if (worker_queue.size()) zmq::poll(&items[0], 2, -1); diff --git a/examples/C++/lpclient.cpp b/examples/C++/lpclient.cpp index a3f86ef98..e6241eb7a 100644 --- a/examples/C++/lpclient.cpp +++ b/examples/C++/lpclient.cpp @@ -42,7 +42,7 @@ int main () { while (expect_reply) { // Poll socket for a reply, with timeout zmq::pollitem_t items[] = { - { static_cast(*client), 0, ZMQ_POLLIN, 0 } }; + { *client, 0, ZMQ_POLLIN, 0 } }; zmq::poll (&items[0], 1, REQUEST_TIMEOUT); // If we got a reply, process it diff --git a/examples/C++/mdbroker.cpp b/examples/C++/mdbroker.cpp index 01559caf5..5294d39cf 100644 --- a/examples/C++/mdbroker.cpp +++ b/examples/C++/mdbroker.cpp @@ -392,7 +392,7 @@ class broker { int64_t heartbeat_at = now + HEARTBEAT_INTERVAL; while (!s_interrupted) { zmq::pollitem_t items [] = { - { static_cast(*m_socket), 0, ZMQ_POLLIN, 0} }; + { *m_socket, 0, ZMQ_POLLIN, 0} }; int64_t timeout = heartbeat_at - now; if (timeout < 0) timeout = 0; diff --git a/examples/C++/mdcliapi.hpp b/examples/C++/mdcliapi.hpp index c542ece56..284e9b895 100644 --- a/examples/C++/mdcliapi.hpp +++ b/examples/C++/mdcliapi.hpp @@ -107,7 +107,7 @@ class mdcli { while (!s_interrupted) { // Poll socket for a reply, with timeout zmq::pollitem_t items [] = { - { static_cast(*m_client), 0, ZMQ_POLLIN, 0 } }; + { *m_client, 0, ZMQ_POLLIN, 0 } }; zmq::poll (items, 1, m_timeout); // If we got a reply, process it diff --git a/examples/C++/mdcliapi2.hpp b/examples/C++/mdcliapi2.hpp index f840c8cc7..6153364f4 100644 --- a/examples/C++/mdcliapi2.hpp +++ b/examples/C++/mdcliapi2.hpp @@ -103,7 +103,7 @@ class mdcli { { // Poll socket for a reply, with timeout zmq::pollitem_t items[] = { - { static_cast(*m_client), 0, ZMQ_POLLIN, 0 } }; + { *m_client, 0, ZMQ_POLLIN, 0 } }; zmq::poll (items, 1, m_timeout); // If we got a reply, process it diff --git a/examples/C++/mdwrkapi.hpp b/examples/C++/mdwrkapi.hpp index ee5dd3212..c58776ff2 100644 --- a/examples/C++/mdwrkapi.hpp +++ b/examples/C++/mdwrkapi.hpp @@ -132,7 +132,7 @@ class mdwrk { while (!s_interrupted) { zmq::pollitem_t items[] = { - { static_cast(*m_worker), 0, ZMQ_POLLIN, 0 } }; + { *m_worker, 0, ZMQ_POLLIN, 0 } }; zmq::poll (items, 1, m_heartbeat); if (items[0].revents & ZMQ_POLLIN) { diff --git a/examples/C++/mspoller.cpp b/examples/C++/mspoller.cpp index 61d0461b6..bd1b81bb0 100644 --- a/examples/C++/mspoller.cpp +++ b/examples/C++/mspoller.cpp @@ -21,8 +21,8 @@ int main (int argc, char *argv[]) // Initialize poll set zmq::pollitem_t items [] = { - { static_cast(receiver), 0, ZMQ_POLLIN, 0 }, - { static_cast(subscriber), 0, ZMQ_POLLIN, 0 } + { receiver, 0, ZMQ_POLLIN, 0 }, + { subscriber, 0, ZMQ_POLLIN, 0 } }; // Process messages from both sockets while (1) { diff --git a/examples/C++/ppqueue.cpp b/examples/C++/ppqueue.cpp index e5118ded9..fae21a0f7 100644 --- a/examples/C++/ppqueue.cpp +++ b/examples/C++/ppqueue.cpp @@ -110,8 +110,8 @@ int main (void) while (1) { zmq::pollitem_t items [] = { - { static_cast(backend), 0, ZMQ_POLLIN, 0 }, - { static_cast(frontend), 0, ZMQ_POLLIN, 0 } + { backend, 0, ZMQ_POLLIN, 0 }, + { frontend, 0, ZMQ_POLLIN, 0 } }; // Poll frontend only if we have available workers if (queue.size()) { diff --git a/examples/C++/rrbroker.cpp b/examples/C++/rrbroker.cpp index 5307d4f89..1527cc075 100644 --- a/examples/C++/rrbroker.cpp +++ b/examples/C++/rrbroker.cpp @@ -17,8 +17,8 @@ int main (int argc, char *argv[]) // Initialize poll set zmq::pollitem_t items [] = { - { static_cast(frontend), 0, ZMQ_POLLIN, 0 }, - { static_cast(backend), 0, ZMQ_POLLIN, 0 } + { frontend, 0, ZMQ_POLLIN, 0 }, + { backend, 0, ZMQ_POLLIN, 0 } }; // Switch messages between sockets diff --git a/examples/C++/spqueue.cpp b/examples/C++/spqueue.cpp index f19b2f18b..94b7e8690 100644 --- a/examples/C++/spqueue.cpp +++ b/examples/C++/spqueue.cpp @@ -25,8 +25,8 @@ int main (void) while (1) { zmq::pollitem_t items [] = { - { static_cast(backend), 0, ZMQ_POLLIN, 0 }, - { static_cast(frontend), 0, ZMQ_POLLIN, 0 } + { backend, 0, ZMQ_POLLIN, 0 }, + { frontend, 0, ZMQ_POLLIN, 0 } }; // Poll frontend only if we have available workers if (worker_queue.size()) diff --git a/examples/C++/taskwork2.cpp b/examples/C++/taskwork2.cpp index 94c5487c3..f1ccbef84 100644 --- a/examples/C++/taskwork2.cpp +++ b/examples/C++/taskwork2.cpp @@ -25,8 +25,8 @@ int main (int argc, char *argv[]) // Process messages from receiver and controller zmq::pollitem_t items [] = { - { static_cast(receiver), 0, ZMQ_POLLIN, 0 }, - { static_cast(controller), 0, ZMQ_POLLIN, 0 } + { receiver, 0, ZMQ_POLLIN, 0 }, + { controller, 0, ZMQ_POLLIN, 0 } }; // Process messages from both sockets while (1) { diff --git a/examples/C++/tripping.cpp b/examples/C++/tripping.cpp index 123ba90a4..58c7b14b8 100644 --- a/examples/C++/tripping.cpp +++ b/examples/C++/tripping.cpp @@ -73,8 +73,8 @@ broker_task (void *args) // Initialize poll set zmq::pollitem_t items [] = { - { static_cast(frontend), 0, ZMQ_POLLIN, 0 }, - { static_cast(backend), 0, ZMQ_POLLIN, 0 } + { frontend, 0, ZMQ_POLLIN, 0 }, + { backend, 0, ZMQ_POLLIN, 0 } }; while (1) { zmq::poll (items, 2, -1);