[Boost.Asio] service_name/port inconsistency
Hi. When designing server-client model, one has to use boost::asio::ip::tcp::endpoint and boost::asio::ip::tcp::resolver::query respectively. What I am confused about is that query accepts std::string& service as a parameter whereas endpoint only accepts unsigned short. When writing code, it is really easy to get confused which constructor takes string and which short. I would appreciate is somebody could tell me if there is a way to create a server side component using integer as a service. - V
On Fri, 29 Aug 2008, Vjekoslav Brajkovic wrote:
Hi.
When designing server-client model, one has to use boost::asio::ip::tcp::endpoint and boost::asio::ip::tcp::resolver::query respectively. What I am confused about is that query accepts std::string& service as a parameter whereas endpoint only accepts unsigned short.
When writing code, it is really easy to get confused which constructor takes string and which short. I would appreciate is somebody could tell me if there is a way to create a server side component using integer as a service.
Sorry, not the server, but the client. Also, let extend my question. It seems if one wants to resolve a FQDN, first ip::basic_resolver<T> has to be created. Afterwards, basic_resolver.resolve() function should be called which accepts either endpoint_type or query as a parameter. So what I was wondering is: a) What is the point passing endpoint_type, when we know for sure that endpoint will only accept address which *cannot* be a FQDN. What do we achieve by doing this? b) To be more precise: How come basic_resolver_query does not take unsigned short as a parameter for service/port? I apologize if these are somewhat broad questions, however I really would like to know the rational behind some of the design decisions.
On Sat, 30 Aug 2008 23:29:20 +0200, Vjekoslav Brajkovic
[...]a) What is the point passing endpoint_type, when we know for sure that endpoint will only accept address which *cannot* be a FQDN. What do we achieve by doing this?
If I'm not mistaken it's basically a wrapper for getnameinfo().
b) To be more precise: How come basic_resolver_query does not take unsigned short as a parameter for service/port?
I don't know why but you can pass a port number by converting it to a std::string. Boris
On Sun, 31 Aug 2008, Boris wrote:
[...]a) What is the point passing endpoint_type, when we know for sure that endpoint will only accept address which *cannot* be a FQDN. What do we achieve by doing this?
If I'm not mistaken it's basically a wrapper for getnameinfo().
Maybe I haven't expressed myself correctly. resolver.resolve(endpoint) - does not resolve anything since the endpoint can only be expressed in dotted decimal form, or in hexadecimal notation.
b) To be more precise: How come basic_resolver_query does not take unsigned short as a parameter for service/port?
I don't know why but you can pass a port number by converting it to a std::string.
Yeah, that's what I'm dong (lexical cast) in order to keep the code simple and generic. Thanks! V
On Mon, 01 Sep 2008 05:20:43 +0200, Vjekoslav Brajkovic
On Sun, 31 Aug 2008, Boris wrote:
[...]a) What is the point passing endpoint_type, when we know for sure that endpoint will only accept address which *cannot* be a FQDN. What do we achieve by doing this?
If I'm not mistaken it's basically a wrapper for getnameinfo().
Maybe I haven't expressed myself correctly.
resolver.resolve(endpoint) - does not resolve anything since the endpoint can only be expressed in dotted decimal form, or in hexadecimal notation.
I think I haven't expressed myself correctly. :) If you look at asio/detail/resolver_service.hpp and search for getnameinfo you'll see that the endpoint is resolved (which means a host name and service name is returned; see http://msdn.microsoft.com/en-us/library/ms738532(VS.85).aspx). Boris
Hi,Suppose I have 2 strands, one with callbacks that read from one socketand another with callbacks writing to another socket.And, suppose I have some kind of queue structure in between.The io_service is run with 2 threads.How do I synchronize access to the queue between these two strads?Many thanksIvo
participants (3)
-
Boris
-
Ivo Andric
-
Vjekoslav Brajkovic