Commit 27a8961c authored by Pieter Hintjens's avatar Pieter Hintjens

Problem: resolution of int optval_ was made more verbose

There's no value in this as the same pattern is repeated in several
places and it's fair to expect people to understand it.

Solution: revert to the old, one-liner style.
parent c8318912
...@@ -70,8 +70,7 @@ int zmq::dealer_t::xsetsockopt (int option_, const void *optval_, ...@@ -70,8 +70,7 @@ int zmq::dealer_t::xsetsockopt (int option_, const void *optval_,
size_t optvallen_) size_t optvallen_)
{ {
bool is_int = (optvallen_ == sizeof (int)); bool is_int = (optvallen_ == sizeof (int));
int value = 0; int value = is_int? *((int *) optval_): 0;
if (is_int) memcpy(&value, optval_, sizeof (int));
switch (option_) { switch (option_) {
case ZMQ_PROBE_ROUTER: case ZMQ_PROBE_ROUTER:
......
...@@ -92,8 +92,7 @@ int zmq::options_t::setsockopt (int option_, const void *optval_, ...@@ -92,8 +92,7 @@ int zmq::options_t::setsockopt (int option_, const void *optval_,
size_t optvallen_) size_t optvallen_)
{ {
bool is_int = (optvallen_ == sizeof (int)); bool is_int = (optvallen_ == sizeof (int));
int value = 0; int value = is_int? *((int *) optval_): 0;
if (is_int) memcpy(&value, optval_, sizeof (int));
#if defined (ZMQ_ACT_MILITANT) #if defined (ZMQ_ACT_MILITANT)
bool malformed = true; // Did caller pass a bad option value? bool malformed = true; // Did caller pass a bad option value?
#endif #endif
......
...@@ -204,8 +204,8 @@ bool zmq::req_t::xhas_out () ...@@ -204,8 +204,8 @@ bool zmq::req_t::xhas_out ()
int zmq::req_t::xsetsockopt (int option_, const void *optval_, size_t optvallen_) int zmq::req_t::xsetsockopt (int option_, const void *optval_, size_t optvallen_)
{ {
bool is_int = (optvallen_ == sizeof (int)); bool is_int = (optvallen_ == sizeof (int));
int value = 0; int value = is_int? *((int *) optval_): 0;
if (is_int) memcpy(&value, optval_, sizeof (int));
switch (option_) { switch (option_) {
case ZMQ_REQ_CORRELATE: case ZMQ_REQ_CORRELATE:
if (is_int && value >= 0) { if (is_int && value >= 0) {
......
...@@ -97,8 +97,7 @@ int zmq::router_t::xsetsockopt (int option_, const void *optval_, ...@@ -97,8 +97,7 @@ int zmq::router_t::xsetsockopt (int option_, const void *optval_,
size_t optvallen_) size_t optvallen_)
{ {
bool is_int = (optvallen_ == sizeof (int)); bool is_int = (optvallen_ == sizeof (int));
int value = 0; int value = is_int? *((int *) optval_): 0;
if (is_int) memcpy(&value, optval_, sizeof (int));
switch (option_) { switch (option_) {
case ZMQ_CONNECT_RID: case ZMQ_CONNECT_RID:
......
...@@ -178,8 +178,8 @@ int zmq::stream_t::xsetsockopt (int option_, const void *optval_, ...@@ -178,8 +178,8 @@ int zmq::stream_t::xsetsockopt (int option_, const void *optval_,
size_t optvallen_) size_t optvallen_)
{ {
bool is_int = (optvallen_ == sizeof (int)); bool is_int = (optvallen_ == sizeof (int));
int value = 0; int value = is_int? *((int *) optval_): 0;
if (is_int) memcpy(&value, optval_, sizeof (int));
switch (option_) { switch (option_) {
case ZMQ_CONNECT_RID: case ZMQ_CONNECT_RID:
if (optval_ && optvallen_) { if (optval_ && optvallen_) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment