Vjekoslav Brajkovic | 30 Aug 01:45
Favicon

[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
Vjekoslav Brajkovic | 30 Aug 23:29
Favicon

Re: [Boost.Asio] service_name/port inconsistency

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.
(Continue reading)

Boris | 31 Aug 00:40

Re: [Boost.Asio] service_name/port inconsistency

On Sat, 30 Aug 2008 23:29:20 +0200, Vjekoslav Brajkovic  
<balkan <at> cs.washington.edu> 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().

> 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
Favicon

Re: [Boost.Asio] service_name/port inconsistency

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
Boris | 1 Sep 13:19

Re: [Boost.Asio] service_name/port inconsistency

On Mon, 01 Sep 2008 05:20:43 +0200, Vjekoslav Brajkovic  
<balkan <at> cs.washington.edu> wrote:

> 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
Ivo Andric | 2 Sep 21:24

[Boost.Asio] strands sharing an object

Hi,

Suppose I have 2 strands, one with callbacks that read from one socket

and 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 thanks

Ivo


_______________________________________________
Boost-users mailing list
Boost-users <at> lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/boost-users

Gmane