use of deleted function nng::socket& nng::socket::operator=(const nng::socket&)
somptueux opened this issue · comments
While trying to build a c++ class with g++ with swig for using it in python, I get the compiling error mentioned above. Is there an issue in the implementation?
running build_ext building '_CommunicationViaNNG' extension swigging CommunicationViaNNG.i to CommunicationViaNNG_wrap.cpp swig -python -c++ -o CommunicationViaNNG_wrap.cpp CommunicationViaNNG.i creating build creating build/temp.linux-x86_64-3.6 g++ -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -Isrc -I/usr/include/python3.6m -c CommunicationViaNNG_wrap.cpp -o build/temp.linux-x86_64-3.6/CommunicationViaNNG_wrap.o -I/home/user1/Documents/extLibs -lnng -lpthread CommunicationViaNNG_wrap.cpp: In function ‘PyObject* _wrap_CommIF_socket_set(PyObject*, PyObject*)’: CommunicationViaNNG_wrap.cpp:2962:15: error: use of deleted function ‘nng::socket& nng::socket::operator=(const nng::socket&)’ arg2 = *temp; ^~~~ In file included from /home/user1/Documents/extLibs/nngpp/nngpp.h:3:0, from src/CommunicationViaNNG.h:1, from CommunicationViaNNG_wrap.cpp:2774: /home/user1/Documents/extLibs/nngpp/socket.h:19:10: note: declared here socket& operator=( const socket& rhs ) = delete; ^~~~~~~~ CommunicationViaNNG_wrap.cpp:2966:30: error: use of deleted function ‘nng::socket& nng::socket::operator=(const nng::socket&)’ if (arg1) (arg1)->socket = arg2; ^~~~ In file included from /home/user1/Documents/extLibs/nngpp/nngpp.h:3:0, from src/CommunicationViaNNG.h:1, from CommunicationViaNNG_wrap.cpp:2774: /home/user1/Documents/extLibs/nngpp/socket.h:19:10: note: declared here socket& operator=( const socket& rhs ) = delete; ^~~~~~~~ CommunicationViaNNG_wrap.cpp: In function ‘PyObject* _wrap_CommIF_socket_get(PyObject*, PyObject*)’: CommunicationViaNNG_wrap.cpp:2989:28: error: use of deleted function ‘nng::socket& nng::socket::operator=(const nng::socket&)’ result = ((arg1)->socket); ^ In file included from /home/user1/Documents/extLibs/nngpp/nngpp.h:3:0, from src/CommunicationViaNNG.h:1, from CommunicationViaNNG_wrap.cpp:2774: /home/user1/Documents/extLibs/nngpp/socket.h:19:10: note: declared here socket& operator=( const socket& rhs ) = delete; ^~~~~~~~ CommunicationViaNNG_wrap.cpp:2990:92: error: use of deleted function ‘nng::socket::socket(const nng::socket&)’ ointerObj((new nng::socket(static_cast< const nng::socket& >(result))), SWIGTYPE_p_nng__socket, SWIG_POINTER_OWN | 0 ); ^ CommunicationViaNNG_wrap.cpp:1088:89: note: in definition of macro ‘SWIG_NewPointerObj’ terObj(ptr, type, flags) SWIG_Python_NewPointerObj(NULL, ptr, type, flags) ^~~ In file included from /home/user1/Documents/extLibs/nngpp/nngpp.h:3:0, from src/CommunicationViaNNG.h:1, from CommunicationViaNNG_wrap.cpp:2774: /home/user1/Documents/extLibs/nngpp/socket.h:13:2: note: declared here socket( const socket& rhs ) = delete; ^~~~~~ error: command 'g++' failed with exit status 1
You are trying to copy nng::socket
. This is not possible.
Use move operations to transfer ownership of the socket, e.g.
nng::socket new_socket_object = std::move(existing_socket_object)
Alternatively use nng::socket_view
to get a non-owning view on the socket:
nng::socket_view view = existing_socket;
The critical wrapper function is automatically created by swig, so this is not an issue concerning nngpp.
Thank you for your quick reply.
Hi
I had similar issue, as well, using SWIG to interface some socket management functions like the following:
static nng::socket_view getIpcIndexSocket()
{
std::string sLane = "ipc:///aBridgeIndex";
nng::socket_view _socket(nng::survey::open());
// nng::set_opt_recv_timeout(_socket, 1000);
_socket.dial(sLane.c_str());
std::cout << "ipc index socket open" << std::endl;
return _socket;
}
And the Swig interface file (.i) declares:
nng::socket_view getIpcIndexSocket();
It compiles great now, but when importing the generated (python in this case) module, running that method throws an nng::exception
:
terminate called after throwing an instance of 'nng::exception'
what(): Object closed
right when the _socket.dial(...)
method is called.
Any clue about what's wrong with the code? There is nothing else going on in the Swig side, this is just a proof of concept, only method called.
Thanks
@somptueux I could compile with Swig using the socket_view, but as you can see in my last comment the socket appears not to survive after open().
Did you get it working? Can you share your piece of code?