Tricky RPC code using bind()

All, I've written what I thought was a pretty clever RPC server using bind and templated functions to make server callbacks typesafe. It all resolves around this one function: class rpc_server { ... template <class A, class R> void set_handler(int prog, int vers, int proc, bool_t (*arg_fn)(XDR *, A*), bool_t (*res_fn)(XDR *, R*), function<void(A*,function<void(R*)>)> req_cb) { ... } } The idea being that you pass it the program, version, and procedure numbers, pointers to the xdr_ functions that encode/decode the argument and response types, and a function object that takes a pointer to the argument type and a callback to call with the result. It should be really nice to use, as it makes sure your callback handles the same types as the relevant encoding/decoding functions. Currently, however, I can't get it to compile. The error from gcc 4.0.1 on OS X Tiger is: g++ -c -g -I/usr/local/include/boost-1_33_1 -I.. rpc_server.cpp rpc_server.cpp: In member function 'void rpc_server::set_handler(int, int, int, int (*)(XDR*, A*), int (*)(XDR*, R*), boost::function<void ()(A*, boost::function<void ()(R*), std::allocator<void> >), std::allocator<void> >) [with A = example_args, R = example_res]': rpc_server.cpp:277: instantiated from here rpc_server.cpp:171: error: cannot resolve overloaded function 'call_req' based on conversion to type 'int' make: *** [rpc_server.o] Error 1 I've attached rpc_server.cpp. Can anyone tell me why the compiler doesn't have the information it needs? It seems to have figured out what types A and R are. What else does it need to resolve call_req? Thanks for your time, Sean -- When I see the price that you pay / I don't wanna grow up -- Tom Waits

Sean Rhea wrote:
Currently, however, I can't get it to compile. The error from gcc 4.0.1 on OS X Tiger is:
g++ -c -g -I/usr/local/include/boost-1_33_1 -I.. rpc_server.cpp rpc_server.cpp: In member function 'void rpc_server::set_handler(int, int, int, int (*)(XDR*, A*), int (*)(XDR*, R*), boost::function<void ()(A*, boost::function<void ()(R*), std::allocator<void> >), std::allocator<void> >) [with A = example_args, R = example_res]': rpc_server.cpp:277: instantiated from here rpc_server.cpp:171: error: cannot resolve overloaded function 'call_req' based on conversion to type 'int' make: *** [rpc_server.o] Error 1
I've attached rpc_server.cpp.
Can anyone tell me why the compiler doesn't have the information it needs? It seems to have figured out what types A and R are. What else does it need to resolve call_req?
The A and R parameters of set_handler have been resolved, but the A and R parameters of call_req haven't. Try bind( &rpc_server::call_req<A, R>, ... ), and similarly for the other binds.

On Feb 14, 2006, at 4:30 PM, Peter Dimov wrote:
The A and R parameters of set_handler have been resolved, but the A and R parameters of call_req haven't. Try bind( &rpc_server::call_req<A, R>, ... ), and similarly for the other binds.
That did the trick. Thanks! Sean -- Everyone chooses his or her own instrument for rebellion. I don't know what my son's will be, but my only hope for him is this: That by sharing my passions with him, I have planted the seeds of defiance that will someday be turned against me. -- Soo Lee Young
participants (2)
-
Peter Dimov
-
Sean Rhea