Having trouble with boost thread library
#ifndef UTILS_NETWORK_TCP_CONNECTION_HPP #define UTILS_NETWORK_TCP_CONNECTION_HPP namespace utils{ namespace thread{ template <typename shared_obj_type, typename thread_pool_type, typename serverlet_type> class tcp_connection{ private: int newsockfd; shared_obj_type obj; thread_pool_type pool; serverlet_type serverlet; bool initialized_; public: tcp_connection() : initialized_ (false) {} tcp_connection(int newsockfd, shared_obj_type obj, thread_pool_type pool, serverlet_type serverlet) : newsockfd(newsockfd), obj(obj), pool(pool), serverlet(serverlet), initialized_(true) { } bool initialized() { return initialized_; } bool initialize(int newsockfd, shared_obj_type obj, thread_pool_type pool, serverlet_type serverlet); void operator ()(); }; template <typename shared_obj_type, typename thread_pool_type, typename serverlet_type> bool tcp_connection<shared_obj_type, thread_pool_type, serverlet_type>::initialize (int newsockfd, shared_obj_type obj, thread_pool_type pool, serverlet_type serverlet) { this->newsockfd = newsockfd; this->obj = obj; this->pool = pool; this->serverlet = serverlet; initialized_ = true; return initialized_; } template <typename shared_obj_type, typename thread_pool_type, typename serverlet_type> void tcp_connection<shared_obj_type, thread_pool_type, serverlet_type>::operator() () { //if(initialized_) serverlet_type(newsockfd, obj); <---- causes error pool->release(); } } } #endif main.cpp: provides definition of serverlet_type #include "utils/thread/tcp_server.hpp" #include "utils/thread/thread_pool.h" #include <boost/shared_ptr.hpp> #include <vector> #include <iostream> typedef std::vector<int> shared_obj_type; typedef boost::shared_ptr<boost_thread::thread_pool> thread_pool_type; typedef void (*serverlet_type)(int, shared_obj_type); void servlet(int sock, shared_obj_type ){ std::cout << "got a new socket for a new connection: " << sock << std::endl; } int main(){ shared_obj_type x; thread_pool_type p( new boost_thread::thread_pool(20) ); utils::thread::tcp_server<shared_obj_type, thread_pool_type, serverlet_type> server; server.initialize(x, p, servlet, 10000, 5); boost::thread s(server); s.join(); } /root/cpp-utils-header-lib/include/utils/thread/tcp_connection.hpp: In member function `void utils::thread::tcp_connection<shared_obj_type, thread_pool_type, serverlet_type>::operator()() [with shared_obj_type = shared_obj_type, thread_pool_type = thread_pool_type, serverlet_type = void (*)(int, shared_obj_type)]': /usr/include/boost/function/function_template.hpp:155: instantiated from `static void boost::detail::function::void_function_obj_invoker0<FunctionObj, R>::invoke(boost::detail::function::function_buffer&) [with FunctionObj = utils::thread::tcp_connection<shared_obj_type, thread_pool_type, void (*)(int, shared_obj_type)>, R = void]' /usr/include/boost/function/function_template.hpp:368: instantiated from `void boost::detail::function::basic_vtable0<R, Allocator>::init(FunctionObj, boost::detail::function::function_obj_tag) [with FunctionObj = utils::thread::tcp_connection<shared_obj_type, thread_pool_type, void (*)(int, shared_obj_type)>, R = void, Allocator = std::allocator<boost::function_base>]' /usr/include/boost/function/function_template.hpp:298: instantiated from `void boost::detail::function::basic_vtable0<R, Allocator>::init(F) [with F = utils::thread::tcp_connection<shared_obj_type, thread_pool_type, void (*)(int, shared_obj_type)>, R = void, Allocator = std::allocator<boost::function_base>]' /usr/include/boost/function/function_template.hpp:277: instantiated from `boost::detail::function::basic_vtable0<R, Allocator>::basic_vtable0(F) [with F = utils::thread::tcp_connection<shared_obj_type, thread_pool_type, void (*)(int, shared_obj_type)>, R = void, Allocator = std::allocator<boost::function_base>]' /usr/include/boost/function/function_template.hpp:655: instantiated from `void boost::function0<R, Allocator>::assign_to(Functor) [with Functor = utils::thread::tcp_connection<shared_obj_type, thread_pool_type, void (*)(int, shared_obj_type)>, R = void, Allocator = std::allocator<boost::function_base>]' /usr/include/boost/function/function_template.hpp:513: instantiated from `boost::function0<R, Allocator>::function0(Functor, typename boost::enable_if_c< boost::type_traits::ice_not< boost::is_integral<Functor>::value>::value, int>::type) [with Functor = utils::thread::tcp_connection<shared_obj_type, thread_pool_type, void (*)(int, shared_obj_type)>, R = void, Allocator = std::allocator<boost::function_base>]' /root/cpp-utils-header-lib/include/utils/thread/tcp_server.hpp:107: instantiated from `void utils::thread::tcp_server<shared_obj_type, thread_pool_type, serverlet_type, accept_fail_policy>::operator()() [with shared_obj_type = shared_obj_type, thread_pool_type = thread_pool_type, serverlet_type = void (*)(int, shared_obj_type), accept_fail_policy = utils::thread::default_accept_fail_policy]' /usr/include/boost/function/function_template.hpp:155: instantiated from `static void boost::detail::function::void_function_obj_invoker0<FunctionObj, R>::invoke(boost::detail::function::function_buffer&) [with FunctionObj = utils::thread::tcp_server<shared_obj_type, thread_pool_type, void (*)(int, shared_obj_type), utils::thread::default_accept_fail_policy>, R = void]' /usr/include/boost/function/function_template.hpp:368: instantiated from `void boost::detail::function::basic_vtable0<R, Allocator>::init(FunctionObj, boost::detail::function::function_obj_tag) [with FunctionObj = utils::thread::tcp_server<shared_obj_type, thread_pool_type, void (*)(int, shared_obj_type), utils::thread::default_accept_fail_policy>, R = void, Allocator = std::allocator<boost::function_base>]' /usr/include/boost/function/function_template.hpp:298: instantiated from `void boost::detail::function::basic_vtable0<R, Allocator>::init(F) [with F = utils::thread::tcp_server<shared_obj_type, thread_pool_type, void (*)(int, shared_obj_type), utils::thread::default_accept_fail_policy>, R = void, Allocator = std::allocator<boost::function_base>]' /usr/include/boost/function/function_template.hpp:277: instantiated from `boost::detail::function::basic_vtable0<R, Allocator>::basic_vtable0(F) [with F = utils::thread::tcp_server<shared_obj_type, thread_pool_type, void (*)(int, shared_obj_type), utils::thread::default_accept_fail_policy>, R = void, Allocator = std::allocator<boost::function_base>]' /usr/include/boost/function/function_template.hpp:655: instantiated from `void boost::function0<R, Allocator>::assign_to(Functor) [with Functor = utils::thread::tcp_server<shared_obj_type, thread_pool_type, void (*)(int, shared_obj_type), utils::thread::default_accept_fail_policy>, R = void, Allocator = std::allocator<boost::function_base>]' /usr/include/boost/function/function_template.hpp:513: instantiated from `boost::function0<R, Allocator>::function0(Functor, typename boost::enable_if_c< boost::type_traits::ice_not< boost::is_integral<Functor>::value>::value, int>::type) [with Functor = utils::thread::tcp_server<shared_obj_type, thread_pool_type, void (*)(int, shared_obj_type), utils::thread::default_accept_fail_policy>, R = void, Allocator = std::allocator<boost::function_base>]' tests/boost_tcp_server_test.cpp:24: instantiated from here /root/cpp-utils-header-lib/include/utils/thread/tcp_connection.hpp:61: error: functional cast expression list treated as compound expression /root/cpp-utils-header-lib/include/utils/thread/tcp_connection.hpp:61: warning: left-hand operand of comma has no effect /root/cpp-utils-header-lib/include/utils/thread/tcp_connection.hpp:61: error: cannot convert `((void)((utils::thread::tcp_connection<shared_obj_type, thread_pool_type, void (*)(int, shared_obj_type)>*)this)->utils::thread::tcp_connection<shared_obj_type, thread_pool_type, void (*)(int, shared_obj_type)>::newsockfd, ((utils::thread::tcp_connection<shared_obj_type, thread_pool_type, void (*)(int, shared_obj_type)>*)this)->utils::thread::tcp_connection<shared_obj_type, thread_pool_type, void (*)(int, shared_obj_type)>::obj)' from type `shared_obj_type' to type `void (*)(int, shared_obj_type)'
participants (1)
-
Fei Liu