GRPC synchronous request error: call to deleted constructor - c++

I am trying to configure a grpc::ClientContext as part of a syncrhonous request using GRPC. Note, without the context 'stuff' all is working fine.
My function looks like this:
grpc::Status Connection::syncLookup(Foo::LookupRequest &request, Foo::LookupResponse *response) {
bool failure = false;
grpc::ClientContext ctx;
Clock::time_point now = Clock::now();
auto time_since_epoch = std::chrono::duration_cast<Ms>(now.time_since_epoch()).count();
if (rpc_timeout_ms_ > 0)
{
Clock::time_point deadline = now + Ms(rpc_timeout_ms_);
ctx.set_deadline(deadline);
}
grpc::Status status = lookup_stub_->Lookup(&ctx, request, response);
if (!status.ok())
{
failure = true;
stats_worker_.record(time_since_epoch, failure, peerAddress(ctx));
return status;
}
stats_worker_.record(time_since_epoch, failure, response->serverid());
return status;
}
The error I get is:
In file included from ~/.local/include/grpc++/grpc++.h:26:
In file included from ~/.local/include/grpcpp/grpcpp.h:53:
In file included from ~/.local/include/grpcpp/client_context.h:37:
~/.local/include/grpcpp/impl/codegen/client_context.h:275:24: error: call to deleted constructor of 'grpc::TimePoint<time_point<steady_clock, duration<long long, ratio<1, 1000000000>>>>'
grpc::TimePoint<T> deadline_tp(deadline);
^ ~~~~~~~~
~/dev/cpp/grpc/lookupv2/lookup.cc:104:17: note: in instantiation of function template specialization 'grpc::ClientContext::set_deadline<std::chrono::time_point<std::chrono::steady_clock, std::chrono::duration<long long, std::ratio<1, 1000000000>>>>' requested here
ctx.set_deadline(deadline);
~/.local/include/grpcpp/impl/codegen/time.h:48:3: note: 'TimePoint' has been explicitly marked deleted here
TimePoint(const T& /*time*/) = delete;
In file included from ~/.local/include/grpc++/grpc++.h:26:
In file included from ~/.local/include/grpcpp/grpcpp.h:53:
In file included from ~/.local/include/grpcpp/client_context.h:37:
~/.local/include/grpcpp/impl/codegen/client_context.h:276:29: error: attempt to use a deleted function
deadline_ = deadline_tp.raw_time();
^
~/.local/include/grpcpp/impl/codegen/time.h:49:16: note: 'raw_time' has been explicitly marked deleted here
gpr_timespec raw_time() = delete;
where it states:
~/dev/cpp/grpc/lookupv2/lookup.cc:104:17
is the line ctx.set_deadline(deadline);
From reading around the 'the internet' this is because a copy is trying to occur when there is no copy constructor present (or something). I believe the work around is to use a std_pointer or something, but now I'm slightly out of my depth now.
It seems this isn't a completely standard issue, or atleast i haven't found anything online to suggest there is a clear cut solution to this.
Any help in getting past this error would be greatly appreciated.

Related

error: no matching function for call to ‘ompl::tools::SelfConfig::getDefaultNearestNeighbors(ompl::geometric::RRT*)’

when compiling my own project, I got an error as follows:
myRRT.cc:80:78: error: no matching function for call to ‘ompl::tools::SelfConfig::getDefaultNearestNeighbors(ompl::geometric::RRT*)’
nn_.reset(tools::SelfConfig::getDefaultNearestNeighbors<Motion *>(this));
^
In file included from /home/htf/Downloads/Active-ORB-SLAM2-octomap/src/myRRT.cc:36:0:
/opt/ros/indigo/include/ompl/tools/config/SelfConfig.h:93:42: note: candidate: template<class _T> static ompl::NearestNeighbors<_T>* ompl::tools::SelfConfig::getDefaultNearestNeighbors(const StateSpacePtr&)
static NearestNeighbors<_T>* getDefaultNearestNeighbors(const base::StateSpacePtr &space)
^
/opt/ros/indigo/include/ompl/tools/config/SelfConfig.h:93:42: note: template argument deduction/substitution failed:
/home/htf/Downloads/Active-ORB-SLAM2-octomap/src/myRRT.cc:80:78: note: cannot convert ‘(ompl::geometric::RRT*)this’ (type ‘ompl::geometric::RRT*’) to type ‘const StateSpacePtr& {aka const boost::shared_ptr<ompl::base::StateSpace>&}’
nn_.reset(tools::SelfConfig::getDefaultNearestNeighbors<Motion *>(this))
here is a part of my source code,
void ompl::geometric::RRT::setup()
{
Planner::setup();
tools::SelfConfig sc(si_, getName());
sc.configurePlannerRange(maxDistance_);
if (!nn_)
nn_.reset(tools::SelfConfig::getDefaultNearestNeighbors<Motion *>(this));
nn_->setDistanceFunction(std::bind(&RRT::distanceFunction, this, std::placeholders::_1, std::placeholders::_2));
}
this is one of a example file what I have referedRRT
does anyone have encountered the similar question? i'am new to C++, hope to get some clues. thank you in advance.
ompl::tools::SelfConfig::getDefaultNearestNeighbors(ompl::geometric::RRT*)
so you should modify it like this:
nn_.reset(tools::SelfConfig::getDefaultNearestNeighbors<Motion>(*this));
maybe motion is the templete and (*this) means you want to call object using (*this)
I am also the green hand. I am not sure.

Error: no matching function for call to BufferIO::open(const char*&, int)

//Displayed Error message in eclipse cdt.
- Syntax error
- candidate is:
- no matching function for call to ‘BufferIO::open(const char*&,
int)’
//BufferIO::BufferIO(const char* filename) {
// trying to open a a file
if( (mfile = int open(filename, O_RDONLY | O_DIRECT)) == -1) {
STDERR("opening file failed");
}
}
There isn't really enough information in your posting to provide a full answer; however, if I had to guess, I would assume that you're trying to either call the C function open() or perhaps fstream::open() BUT, you have already declared and/or defined a BufferIO::open() function. If that guess is correct, then you have namespace issues.
Or, if you're actually TRYING to call BufferIO::open(), then you need to provide us with the source and/or declaration so we can help you determine why it doesn't match.

Proper set_socket_init_handler syntax or modify source to turn on TCP_NODELAY with websocket++

I'm having trouble implementing the example code to turn on TCP_NODELAY for a websocket++ endpoint.
This is a client example, and this is a server example.
The testee examples compile and work as expected, and the debug examples frequently compile and work as expected.
I've tried to set on_socket_init handler both ways, but I get nearly the same error each time. One such set of errors is this:
In constructor ‘broadcast_server::broadcast_server()’:
error: no matching function for call to ‘websocketpp::client<websocketpp::config::asio_tls_client>::set_socket_init_handler(std::_Bind_helper<false, void (*)(std::weak_ptr<void>, boost::asio::basic_stream_socket<boost::asio::ip::tcp>&), const std::_Placeholder<1>&, const std::_Placeholder<2>&>::type)’
m_endpoint.set_socket_init_handler(bind(&on_socket_init,::_1,::_2));
^
note: candidate is:
In file included from websocketpp/config/asio.hpp:33:0,
from websocketpp/transport/asio/security/tls.hpp:373:10: note: void websocketpp::transport::asio::tls_socket::endpoint::set_socket_init_handler(websocketpp::transport::asio::tls_socket::socket_init_handler)
void set_socket_init_handler(socket_init_handler h) {
^
websocketpp/transport/asio/security/tls.hpp:373:10: note: no known conversion for argument 1 from ‘std::_Bind_helper<false, void (*)(std::weak_ptr<void>, boost::asio::basic_stream_socket<boost::asio::ip::tcp>&), const std::_Placeholder<1>&, const std::_Placeholder<2>&>::type {aka std::_Bind<void (*(std::_Placeholder<1>, std::_Placeholder<2>))(std::weak_ptr<void>, boost::asio::basic_stream_socket<boost::asio::ip::tcp>&)>}’ to ‘websocketpp::transport::asio::tls_socket::socket_init_handler {aka std::function<void(std::weak_ptr<void>, boost::asio::ssl::stream<boost::asio::basic_stream_socket<boost::asio::ip::tcp> >&)>}’
error: no matching function for call to ‘websocketpp::server<websocketpp::config::asio_tls>::set_socket_init_handler(std::_Bind_helper<false, void (*)(std::weak_ptr<void>, boost::asio::basic_stream_socket<boost::asio::ip::tcp>&), const std::_Placeholder<1>&, const std::_Placeholder<2>&>::type)’
m_server.set_socket_init_handler(bind(&on_socket_init,::_1,::_2));
^
note: candidate is:
In file included from websocketpp/config/asio.hpp:33:0,
from websocketpp/transport/asio/security/tls.hpp:373:10: note: void websocketpp::transport::asio::tls_socket::endpoint::set_socket_init_handler(websocketpp::transport::asio::tls_socket::socket_init_handler)
void set_socket_init_handler(socket_init_handler h) {
^
websocketpp/transport/asio/security/tls.hpp:373:10: note: no known conversion for argument 1 from ‘std::_Bind_helper<false, void (*)(std::weak_ptr<void>, boost::asio::basic_stream_socket<boost::asio::ip::tcp>&), const std::_Placeholder<1>&, const std::_Placeholder<2>&>::type {aka std::_Bind<void (*(std::_Placeholder<1>, std::_Placeholder<2>))(std::weak_ptr<void>, boost::asio::basic_stream_socket<boost::asio::ip::tcp>&)>}’ to ‘websocketpp::transport::asio::tls_socket::socket_init_handler {aka std::function<void(std::weak_ptr<void>, boost::asio::ssl::stream<boost::asio::basic_stream_socket<boost::asio::ip::tcp> >&)>}’
I've seen another post where another developer claimed to have it running, and since I do not understand this syntax fully
m_endpoint.set_socket_init_handler(bind(&type::on_socket_init,this,::_1));
I am unsure of how to begin to diagnose this problem.
How can the above errors be resolved?
NOTE I am implementing TLS.
Needed code
I'm mostly interested in incorporating the contents of this function:
void on_socket_init(websocketpp::connection_hdl hdl, boost::asio::ip::tcp::socket & s) {
boost::asio::ip::tcp::no_delay option(true);
s.set_option(option);
}
Is there a way to modify the source so that this setting is made by default?
The socket_init_handler is a low level hook designed to allow full access to the underlying socket after it is initialized but before it is used. The signature of the socket_init_handler depends on what transport policy in use. While very similar in most ways, asio/plain and asio/tls are actually distinct transport policies and do have some differences.
One of those differences is that the underlying socket typed used in the asio/tls policy is an ssl stream wrapping a socket rather than just the raw socket. As such, the signature of the socket_init_handler for the asio/tls transport is different than that of asio/plain. The signature for the handler on an endpoint using asio/tls transport is:
typedef lib::function<void(connection_hdl,boost::asio::ssl::stream<boost::asio::ip::tcp::socket>&)> socket_init_handler;
This can be found in the documentation at http://doxygen.websocketpp.org/namespacewebsocketpp_1_1transport_1_1asio_1_1tls__socket.html
A corresponding socket init handler that sets TCP_NODELAY for might look like:
void on_socket_init(websocketpp::connection_hdl hdl, boost::asio::ssl::stream<boost::asio::ip::tcp::socket> & s) {
boost::asio::ip::tcp::no_delay option(true);
s.lowest_layer().set_option(option);
}
endpoint.set_socket_init_handler(&on_socket_init);
socket_init_handler is a 2-argument function:
typedef lib::function<void(connection_hdl,boost::asio::ip::tcp::socket&)> socket_init_handler;
if on_socket_init is free function (not a method of a class type), then it should be like
m_endpoint.set_socket_init_handler( &on_socket_init );

Boost: Threading and mutexes in a functor

I'm trying something simple with threads and mutexes in C++ with boost.
This is the code:
#include <iostream>
#include <boost/thread/thread.hpp>
class mutex_test
{
private:
boost::mutex mut;
public:
void operator()()
{
boost::mutex::scoped_lock lock(mut);
std::cout << "Hi!" << std::endl;
}
};
int main()
{
mutex_test tester;
boost::thread tester_thread(tester);
tester_thread.join();
return 0;
}
On compile, I get this error:
In file included from C:\boost/boost/thread/detail/thread.hpp:15:0,
from C:\boost/boost/thread/thread.hpp:22,
from main.cpp:3:
C:\boost/boost/thread/detail/move.hpp: In instantiation of 'typename boost::decay<T>::type boost::thread_detail::decay_copy(T&&) [with T = mutex_test&; typename boost::decay<T>::type = mutex_test]':
C:\boost/boost/thread/detail/thread.hpp:265:88: required from 'boost::thread::thread(F&&) [with F = mutex_test&]'
main.cpp:20:36: required from here
C:\boost/boost/thread/detail/move.hpp:246:37: error: use of deleted function 'mutex_test::mutex_test(const mutex_test&)'
main.cpp:5:7: note: 'mutex_test::mutex_test(const mutex_test&)' is implicitly deleted because the default definition would be ill-formed:
main.cpp:5:7: error: use of deleted function 'boost::mutex::mutex(const boost::mutex&)'
In file included from C:\boost/boost/thread/mutex.hpp:14:0,
from C:\boost/boost/thread/detail/thread.hpp:16,
from C:\boost/boost/thread/thread.hpp:22,
from main.cpp:3:
C:\boost/boost/thread/win32/mutex.hpp:29:9: error: declared here
In file included from C:\boost/boost/thread/thread.hpp:22:0,
from main.cpp:3:
C:\boost/boost/thread/detail/thread.hpp: In instantiation of 'boost::detail::thread_data<F>::thread_data(F&&) [with F = mutex_test]':
C:\boost/boost/thread/win32/thread_heap_alloc.hpp:100:72: required from 'T* boost::detail::heap_new(A1&&) [with T = boost::detail::thread_data<mutex_test>; A1 = mutex_test]'
C:\boost/boost/thread/detail/thread.hpp:214:38: required from 'static boost::detail::thread_data_ptr boost::thread::make_thread_info(F&&) [with F = mutex_test; boost::detail::thread_data_ptr = boost::intrusive_ptr<boost::detail::thread_data_base>]'
C:\boost/boost/thread/detail/thread.hpp:265:88: required from 'boost::thread::thread(F&&) [with F = mutex_test&]'
main.cpp:20:36: required from here
C:\boost/boost/thread/detail/thread.hpp:98:40: error: use of deleted function 'mutex_test::mutex_test(const mutex_test&)'
In file included from C:\boost/boost/system/system_error.hpp:14:0,
from C:\boost/boost/thread/exceptions.hpp:22,
from C:\boost/boost/thread/win32/thread_primitives.hpp:16,
from C:\boost/boost/thread/win32/thread_data.hpp:11,
from C:\boost/boost/thread/thread.hpp:15,
from main.cpp:3:
C:\boost/boost/system/error_code.hpp:214:36: warning: 'boost::system::posix_category' defined but not used [-Wunused-variable]
C:\boost/boost/system/error_code.hpp:215:36: warning: 'boost::system::errno_ecat' defined but not used [-Wunused-variable]
C:\boost/boost/system/error_code.hpp:216:36: warning: 'boost::system::native_ecat' defined but not used [-Wunused-variable]
Makefile:21: recipe for target 'main.o' failed
The error only occurs when I try to create a thread for the functor; executing it straight works fine.
Additionally, if I remove all references to mutexes and locks it works fine.
E: Had the wrong error log. Whoops.
boost::mutex is not a copyable or moveable (using boost's move implementation) type, and hence, passing it in that way to the thread will not work, since that constructor makes a copy of the functor to execute on the thread.
In your test case, you would want to use the following
boost::thread tester_thread(boost::ref(functor))
This passes it by reference, instead of by copy. Note, this also requires that the functor remain valid until the thread exits. Since you're joining the thread, that's the case here, but more complicated cases that might not be true.

Boost 1.53 local date time compiler error with -std=c++0x

Using g++ version 4.7.2, if I try compiling the following
#include <boost/date_time/local_time/local_time.hpp>
class Bar
{
public:
Bar() { tz_db_.load_from_file("/home/date_time_zonespec.csv"); }
private:
boost::local_time::tz_database tz_db_;
};
int main()
{
return 0;
}
with -std=c++0x I get the following error.
In file included from /usr/local/include/boost/date_time/local_time/local_time_types.hpp:18:0,
from /usr/local/include/boost/date_time/local_time/local_time.hpp:13,
from test.h:4,
from test.cpp:1: /usr/local/include/boost/date_time/local_time/custom_time_zone.hpp: In instantiation of ‘bool boost::local_time::custom_time_zone_base<CharT>::has_dst() const [with CharT = char]’: test.cpp:11:1: required from here /usr/local/include/boost/date_time/local_time/custom_time_zone.hpp:67:30: error: cannot convert ‘const boost::shared_ptr<boost::date_time::dst_day_calc_rule<boost::gregorian::date>
>’ to ‘bool’ in return
If I leave off the c++0x option, everything is fine.
Can anybody tell me what's going on here?
When you build for C++11, boost::shared_ptr::operator bool() is declared explicit. This is generally a good thing to do, but unfortunately it breaks code that relies on implicit conversions, such as this function (which is the cause of your error):
virtual bool has_dst() const
{
return (dst_calc_rules_); //if calc_rule is set the tz has dst
}
where dst_calc_rules_ is a shared_ptr.
Until someone at Boost gets round to fixing it, there are two things you could do:
Hack that function to return bool(dst_calc_rules_);
Define BOOST_NO_CXX11_EXPLICIT_CONVERSION_OPERATORS to allow implicit conversions.