Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem: sock.get(zmq::sockopt::type) is not typesafe #523

Merged
merged 1 commit into from Oct 22, 2021

Conversation

jasujm
Copy link
Contributor

@jasujm jasujm commented Oct 21, 2021

Solution: Add zmq::sockopt::socket_type that is used to get() an enumerator from zmq::socket_type instead of plain int.

It makes code like this compile:

#include <zmq.hpp>

#include

int main()
{
zmq::context_t ctx;
zmq::socket_t sock(ctx, zmq::socket_type::push);
assert(sock.get(zmq::sockopt::socket_type) == zmq::socket_type::push);
return 0;
}

This patch solves #522

Solution: Add `zmq::sockopt::socket_type` that is used to `get()` an enumerator
from `zmq::socket_type` instead of plain `int`.

It makes code like this compile:

  #include <zmq.hpp>

  #include <cassert>

  int main()
  {
      zmq::context_t ctx;
      zmq::socket_t sock(ctx, zmq::socket_type::push);
      assert(sock.get(zmq::sockopt::socket_type) == zmq::socket_type::push);
      return 0;
  }
@coveralls
Copy link

Pull Request Test Coverage Report for Build 1369079373

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 86.037%

Totals Coverage Status
Change from base Build 1266731609: 0.0%
Covered Lines: 801
Relevant Lines: 931

💛 - Coveralls

@gummif
Copy link
Member

gummif commented Oct 22, 2021

Looks good, thanks.

@gummif gummif merged commit c170aab into zeromq:master Oct 22, 2021
@XieJiSS
Copy link

XieJiSS commented Mar 19, 2022

Hi @gummif , I encountered this error when trying to #include "zmq.hpp":

// This is the macro expansion result
using socket_type_t = integral_option<16, socket_type, false>; inline constexpr socket_type_t socket_type {}
// The error
"zmq::sockopt::socket_type" is not a type name

According to my linter, this is caused by

cppzmq/zmq.hpp

Line 1652 in a98fa4a

ZMQ_DEFINE_INTEGRAL_OPT(ZMQ_TYPE, socket_type, socket_type);

My workaround is:

// socket_type seems to be resolved to zmq::sockopt::socket_type instead of the enum class zmq::socket_type
ZMQ_DEFINE_INTEGRAL_OPT(ZMQ_TYPE, socket_type, zmq::socket_type);

I'm not very familiar with cpp, so I'm wondering whether this should be considered as a bug introduced by the PR, or an issue caused by possible misconfiguration?

My environment: #define CPPZMQ_LANG _MSVC_LANG which extends to 201703L and #define _MSC_VER 1929

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants