libzmq icon indicating copy to clipboard operation
libzmq copied to clipboard

When using inproc mode, the closure of an open socket will still affect the creation of new sockets

Open szn409 opened this issue 9 months ago • 0 comments

#include "zmq.hpp"
#include "fmt/format.h"
#include <thread>

using namespace std::chrono_literals;

int main()
{
  zmq::context_t ctx;
  int            count = 0;

  for (int i = 0; i < 3; ++i)
  {
    try
    {
      while (true)
      {
        zmq::socket_t sock(ctx, zmq::socket_type::pull);
        sock.set(zmq::sockopt::linger, 0);
        sock.connect("inproc://szn");
        ++count;
      }
    }
    catch (std::exception& e)
    {
      fmt::print("got error: {}, count is {}\n", e.what(), count);
      count = 0;
      std::this_thread::sleep_for(5s);
    }
  }

  return 0;
}
/*
got error: Too many open files, count is 1023
got error: Too many open files, count is 0
got error: Too many open files, count is 0
*/

szn409 avatar Mar 23 '25 03:03 szn409