0
0
mirror of https://github.com/zeromq/libzmq.git synced 2024-12-27 15:41:05 +08:00
fixes zmq_unbind failing with ENOENT
This commit is contained in:
Dylan Cali 2015-06-28 23:45:27 -05:00
parent c629a9265c
commit 717d69005d
5 changed files with 32 additions and 0 deletions

View File

@ -303,6 +303,26 @@ int zmq::ctx_t::register_endpoint (const char *addr_, endpoint_t &endpoint_)
return 0; return 0;
} }
int zmq::ctx_t::unregister_endpoint (
const std::string &addr_, socket_base_t *socket_)
{
endpoints_sync.lock ();
const endpoints_t::iterator it = endpoints.find (addr_);
if (it == endpoints.end () || it->second.socket != socket_) {
endpoints_sync.unlock ();
errno = ENOENT;
return -1;
}
// Remove endpoint.
endpoints.erase (it);
endpoints_sync.unlock ();
return 0;
}
void zmq::ctx_t::unregister_endpoints (socket_base_t *socket_) void zmq::ctx_t::unregister_endpoints (socket_base_t *socket_)
{ {
endpoints_sync.lock (); endpoints_sync.lock ();

View File

@ -92,6 +92,7 @@ namespace zmq
// Management of inproc endpoints. // Management of inproc endpoints.
int register_endpoint (const char *addr_, endpoint_t &endpoint_); int register_endpoint (const char *addr_, endpoint_t &endpoint_);
int unregister_endpoint (const std::string &addr_, socket_base_t *socket_);
void unregister_endpoints (zmq::socket_base_t *socket_); void unregister_endpoints (zmq::socket_base_t *socket_);
endpoint_t find_endpoint (const char *addr_); endpoint_t find_endpoint (const char *addr_);

View File

@ -134,6 +134,12 @@ int zmq::object_t::register_endpoint (const char *addr_, endpoint_t &endpoint_)
return ctx->register_endpoint (addr_, endpoint_); return ctx->register_endpoint (addr_, endpoint_);
} }
int zmq::object_t::unregister_endpoint (
const std::string &addr_, socket_base_t *socket_)
{
return ctx->unregister_endpoint (addr_, socket_);
}
void zmq::object_t::unregister_endpoints (socket_base_t *socket_) void zmq::object_t::unregister_endpoints (socket_base_t *socket_)
{ {
return ctx->unregister_endpoints (socket_); return ctx->unregister_endpoints (socket_);

View File

@ -22,6 +22,7 @@
#ifndef __ZMQ_OBJECT_HPP_INCLUDED__ #ifndef __ZMQ_OBJECT_HPP_INCLUDED__
#define __ZMQ_OBJECT_HPP_INCLUDED__ #define __ZMQ_OBJECT_HPP_INCLUDED__
#include <string>
#include "stdint.hpp" #include "stdint.hpp"
namespace zmq namespace zmq
@ -57,6 +58,8 @@ namespace zmq
// Using following function, socket is able to access global // Using following function, socket is able to access global
// repository of inproc endpoints. // repository of inproc endpoints.
int register_endpoint (const char *addr_, zmq::endpoint_t &endpoint_); int register_endpoint (const char *addr_, zmq::endpoint_t &endpoint_);
int unregister_endpoint (
const std::string &addr_, socket_base_t *socket_);
void unregister_endpoints (zmq::socket_base_t *socket_); void unregister_endpoints (zmq::socket_base_t *socket_);
zmq::endpoint_t find_endpoint (const char *addr_); zmq::endpoint_t find_endpoint (const char *addr_);
void destroy_socket (zmq::socket_base_t *socket_); void destroy_socket (zmq::socket_base_t *socket_);

View File

@ -600,6 +600,8 @@ int zmq::socket_base_t::term_endpoint (const char *addr_)
// Disconnect an inproc socket // Disconnect an inproc socket
if (protocol == "inproc") { if (protocol == "inproc") {
if (unregister_endpoint (std::string (addr_), this) == 0)
return 0;
std::pair <inprocs_t::iterator, inprocs_t::iterator> range = inprocs.equal_range (std::string (addr_)); std::pair <inprocs_t::iterator, inprocs_t::iterator> range = inprocs.equal_range (std::string (addr_));
if (range.first == range.second) { if (range.first == range.second) {
errno = ENOENT; errno = ENOENT;