Darren Cook | 10 Feb 10:47

ip::address::from_string() not working

ip::address's from_string() function does not seem to be working; it
gives me 0.0.0.0 whatever string I pass.

A very minimal reproducible example below, it outputs:
  Set host to 0.0.0.0

I'm using boost 1.40 (ubuntu 10.04). Google is strangely quiet; so I
guess I'm doing something wrong??

Darren

//Compile and run with "g++ test.cpp -lboost_system;./a.out"

#include <iostream>
#include <boost/asio.hpp>

int main(int argc, char* argv[])
{
    boost::asio::ip::address host;
    host.from_string("127.0.0.1");
    std::cout<<"Set host to "<<host<<"\n";
    return 0;
}

--

-- 
Darren Cook, Software Researcher/Developer

http://dcook.org/work/ (About me and my work)
http://dcook.org/blogs.html (My blogs and articles)

(Continue reading)

joakim | 6 Feb 15:20
Picon
Gravatar

SSL ip address

How do I get the ip address of the remote endpoint of a socket of type boost::asio::ssl::stream<boost::asio::ip::tcp::socket> ?
 
Regards,
Jocke
------------------------------------------------------------------------------
Try before you buy = See our experts in action!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-dev2
_______________________________________________
asio-users mailing list
asio-users@...
https://lists.sourceforge.net/lists/listinfo/asio-users
_______________________________________________
Using Asio? List your project at
http://think-async.com/Asio/WhoIsUsingAsio
Pierre Belzile | 27 Jan 03:06
Favicon
Gravatar

Working in boost 1.47.0, broken in 1.48?

Hi,

I build an HTTP 1.1 client and servers starting from the example in HTTP3. I added a timer in the server to close a connection inactive for 60 seconds. My code stopped working after upgrading to 1.48: It seems that some connections just don't die. Here is the tcpdump and some comments. Reverted to 1.47 and working fine. I should
add for completeness that in 1.47, we're linking with non thread safe boost libraries and switched to thread safe ones in 1.48 but I can't see how that impacts asio.

As anyone encountered a similar issue?

Thanks,

Pierre

-----

This sequence shows that the client (za11) attempts to close a connection
established from port 45508 to port 18085, acknowledged by
the server (daffy), and ack-ack by the client.

A minute later, the server sends a reset for port 45511. That's the server closing the socket
because of no activity. But socket should have been closed already.

Also that seems to "unlock" the client that now sends another transaction. Why was
the client locked given that it had ack-ack the FIN?

19:34:33.020597 IP za11.idilia.net.45508 > daffy.idilia.net.18085: Flags [F.], seq 453, ack 2027, win 69, options [nop,nop,TS val 525744130 ecr 18797391], length 0
        0x0000:  4500 0034 cbd7 4000 4006 eaef c0a8 016f  E..4.. <at> . <at> ......o
        0x0010:  c0a8 013d b1c4 46a5 9509 fdf1 36b8 5502  ...=..F.....6.U.
        0x0020:  8011 0045 af94 0000 0101 080a 1f56 3802  ...E.........V8.
        0x0030:  011e d34f                                ...O
19:34:33.020725 IP daffy.idilia.net.18085 > za11.idilia.net.45508: Flags [F.], seq 2027, ack 454, win 54, options [nop,nop,TS val 18797391 ecr 525744130], length 0
        0x0000:  4500 0034 9e57 4000 4006 1870 c0a8 013d  E..4.W <at> . <at> ..p...=
        0x0010:  c0a8 016f 46a5 b1c4 36b8 5502 9509 fdf2  ...oF...6.U.....
        0x0020:  8011 0036 afa2 0000 0101 080a 011e d34f  ...6...........O
        0x0030:  1f56 3802                                .V8.
19:34:33.020820 IP za11.idilia.net.45508 > daffy.idilia.net.18085: Flags [.], ack 2028, win 69, options [nop,nop,TS val 525744131 ecr 18797391], length 0
        0x0000:  4500 0034 cbd8 4000 4006 eaee c0a8 016f  E..4.. <at> . <at> ......o
        0x0010:  c0a8 013d b1c4 46a5 9509 fdf2 36b8 5503  ...=..F.....6.U.
        0x0020:  8010 0045 af92 0000 0101 080a 1f56 3803  ...E.........V8.
        0x0030:  011e d34f                                ...O
19:35:33.034112 IP daffy.idilia.net.18085 > za11.idilia.net.45511: Flags [R.], seq 3153132260, ack 2716375525, win 54, options [nop,nop,TS val 18857405 ecr 525744143], length 0
        0x0000:  4500 0034 29b9 4000 4006 8d0e c0a8 013d  E..4). <at> . <at> ......=
        0x0010:  c0a8 016f 46a5 b1c7 bbf0 fae4 a1e8 99e5  ...oF...........
        0x0020:  8014 0036 f133 0000 0101 080a 011f bdbd  ...6.3..........
        0x0030:  1f56 380f                                .V8.
19:35:33.035527 IP za11.idilia.net.45512 > daffy.idilia.net.18085: Flags [S], seq 4169269143, win 5840, options [mss 1460,sackOK,TS val 525804145 ecr 0,nop,wscale 7], length 0
        0x0000:  4500 003c dde6 4000 4006 d8d8 c0a8 016f  E..<.. <at> . <at> ......o
        0x0010:  c0a8 013d b1c8 46a5 f881 ff97 0000 0000  ...=..F.........
        0x0020:  a002 16d0 7ae3 0000 0204 05b4 0402 080a  ....z...........
        0x0030:  1f57 2271 0000 0000 0103 0307            .W"q........


I tried to compile to whole program with BOOST_ASIO_ENABLE_HANDLER_TRACKING
but that seems to prevent the client from sending any data at all:
asio|1327626817.367757|0*1|strand-/y82dPhOAVgdihUtLtKXqnIPMjoJpjVV@public.gmane.org
<at> asio|1327626817.367962|>1|
<at> asio|1327626817.370260|1*2|socket-s6Ba4tmTa2bCmzY1457ogQ@public.gmane.org_connect
<at> asio|1327626817.370443|<1|

We see the async_connect after resolving endpoints sync. But no traffic
captured by tcpdump. And server just waits.


------------------------------------------------------------------------------
Try before you buy = See our experts in action!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-dev2
_______________________________________________
asio-users mailing list
asio-users@...
https://lists.sourceforge.net/lists/listinfo/asio-users
_______________________________________________
Using Asio? List your project at
http://think-async.com/Asio/WhoIsUsingAsio
Lijo Antony | 24 Jan 15:41
Picon
Favicon
Gravatar

Using asio along with libcurl in windows

Hello,

I am developing a cross platform(linux, windows & mac) application which uses libcurl for network transfers(HTTP & HTTPS).
I am using the multi interface exposed by libcurl for asynchronous mode, and asio to asynchronously watch the sockets created by the libcurl.

I have successfully implemented this design in linux and mac, where I am assigning the native socket created by the libcurl to a
boost::asio::posix::stream_descriptor object and issuing null buffer reads and writes on this object.

In windows I am trying to achieve the same by using a boost::asio::windows::stream_handle object.
But I am not able to assign the native socket created by libcurl (of type SOCKET) to the stream_handle object where
the assign method expects a handle of type HANDLE.

Does any one know how to achieve this in windows?
Any help would be highly appreciated.

Thanks,
-lijo


------------------------------------------------------------------------------
Keep Your Developer Skills Current with LearnDevNow!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-d2d
_______________________________________________
asio-users mailing list
asio-users@...
https://lists.sourceforge.net/lists/listinfo/asio-users
_______________________________________________
Using Asio? List your project at
http://think-async.com/Asio/WhoIsUsingAsio
Carlos Guimarães | 22 Jan 19:10
Picon
Gravatar

Multicast multiple interfaces

Hi,

Is there any portable way (by using boost) to send multicast messages through all network interfaces available on the host?
I have managed to do it by setting outbound_interface option on the socket. However, how can I know which if_index are available?
Also, it only works for IPv6. If I set a IPv4 address it always use the same interface even if I set different interfaces by using the outbound_interface option.

Any suggestion?

Next is the code I'm using:

// DATA HERE...

ip::udp::socket sock(io);
sock.open(ip::udp::v6());

// Set socket flags
    sock.set_option(boost::asio::socket_base::reuse_address(true));
if (strcmp(dst_ip, "ff02::1") == 0) {
boost::asio::socket_base::broadcast option(true);
sock.set_option(option);
}

sock.bind(ip::udp::endpoint(ip::address_v6::any(), src_port));

for(int i = 1; i <= 5; i++) {
try {
sock.set_option(ip::multicast::outbound_interface(i));
sock.set_option(ip::multicast::enable_loopback(false));

ip::udp::endpoint ep(ip::address::from_string(dst_ip), dst_port);
sock.async_send_to(boost::asio::buffer(sbuff, slen),
   ep,
   boost::bind((&send_handler),
   placeholders::error));
} catch(...) {
return;
}
}
------------------------------------------------------------------------------
Try before you buy = See our experts in action!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-dev2
_______________________________________________
asio-users mailing list
asio-users@...
https://lists.sourceforge.net/lists/listinfo/asio-users
_______________________________________________
Using Asio? List your project at
http://think-async.com/Asio/WhoIsUsingAsio
Ross MacGregor | 3 Jan 22:30
Picon

When to post completion handlers?

We've been using ASIO for some time now and an interesting 
problem just appeared. While stress testing with 1000 clients 
we encountered a stack overflow situation.

The root cause of the problem is many completion handlers 
being called directly, resulting in many asynchronous processors 
being invoked and pushed onto the stack. We can address this 
particular bug by selecting a few of our completion handlers and 
posting them to the IO service rather than calling them directly, 
but how do I generally address the problem?

One suggestion is that we simply always post completion handers 
to the IO service rather than calling them directly. This seems a 
little heavy handed, but is guaranteed to work.

Has anyone formulated guidelines to avoid stack overflow of your 
asynchronous processors*? 

When do you do this: 
  ioService.post(bind_handler(completionHandler, error));

Rather than this:    
  completionHandler(error);

* When I say "asynchronous processors" I am referring to function 
objects that are passed as completion handlers to async methods. 
These objects are used to serialize multiple async calls. We are 
using the Chris's coroutine stuff to compose higher level async 
methods from lower level methods.

------------------------------------------------------------------------------
Write once. Port to many.
Get the SDK and tools to simplify cross-platform app development. Create 
new or port existing apps to sell to consumers worldwide. Explore the 
Intel AppUpSM program developer opportunity. appdeveloper.intel.com/join
http://p.sf.net/sfu/intel-appdev
_______________________________________________
asio-users mailing list
asio-users@...
https://lists.sourceforge.net/lists/listinfo/asio-users
_______________________________________________
Using Asio? List your project at
http://think-async.com/Asio/WhoIsUsingAsio

Jason Aubrey | 31 Dec 00:24

deadline_timer and handler lifetimes

Overview:

I'm trying to use a deadline_timer in an RAII context as shown below.

 

Details:

When a deadline_timer goes out of scope, it would be nice (at least I think so) if it encapsulated the cleanup logic by implicitly canceling queued handlers and ensuring pending handlers are completed.  Since this is not the case, I need to explicitly synchronize the cleanup as shown below.

 

//--------------------------------------------------------------------------------

struct foo
{
    foo(boost::asio::io_service& io_service)

        : m_timer(io_service)

    {

        schedule_timer();
    }
    ~foo()
    {
        m_timer.cancel();

        m_event.wait();
    }

 

    void schedule_timer()

    {

        m_timer.expires_at(boost::posix_time::microsecond_clock() + boost::posix_time::seconds(1));
        m_timer.async_wait(boost::bind(&foo::on_timer, this, boost::asio::placeholders::error));

    }

 

    void on_timer(const boost::system::error_code& code)

    {

        if(code == boost::asio::error::operation_aborted)

        {

            m_event.signal();

            return;

        }

        // TODO: Handle spurious wake-ups (omitted for brevity)

        // TODO: Modify this instance (omitted for brevity)

        schedule_timer();
    }


    boost::asio::deadline_timer m_timer;

    manual_reset_event m_event; // An abstraction based on condition_variable, mutex, and a bool
};

//--------------------------------------------------------------------------------

 

Analysis:

Reasons I don't like the code above:

*) Not sure it is correct - any idea?

*) Prone to a deadlock if an exception is thrown in on_timer before schedule_timer is called again

*) Need an event for every timer to ensure cleanup

 

The only alternatives I've come across are:

1) Use static functions for the handlers to avoid lifetime issues

2) Have the handler self-manage its lifetime (e.g. have it call 'delete this')

3) Couple the timer and io_service lifetimes so the io_service is stopped while the handler is still in scope

 

A problem I have with each alternative:

1) Even if the handler is static, the handler is modifying an instance which has the same lifetime issues

2) If I need multiple timers in foo then I don't see how 'delete this' is possible where 'this' is an instance of foo.

3) Doesn't fit the situation where timers with independent lifetimes share the same io_service

 

Please show me something obvious I've missed here!

 

Thanks,

Jason Aubrey

 

------------------------------------------------------------------------------
Ridiculously easy VDI. With Citrix VDI-in-a-Box, you don't need a complex
infrastructure or vast IT resources to deliver seamless, secure access to
virtual desktops. With this all-in-one solution, easily deploy virtual 
desktops for less than the cost of PCs and save 60% on VDI infrastructure 
costs. Try it free! http://p.sf.net/sfu/Citrix-VDIinabox
_______________________________________________
asio-users mailing list
asio-users@...
https://lists.sourceforge.net/lists/listinfo/asio-users
_______________________________________________
Using Asio? List your project at
http://think-async.com/Asio/WhoIsUsingAsio
Joseph M Link | 27 Dec 03:54

async_read_some() with null_buffers affects non_blocking state

Hello,

I am integrating a third party library into an ASIO event loop.  I've 
wrapped the file descriptor with a posix::stream_descriptor() and made 
async_read_some(null_buffer(), ...) calls.  I am receiving these events 
fine.

The problem is that ASIO appears to be changing the fd to non-blocking 
mode (using ioctl(FIONBIO)).  This is not compatible with the third 
party library.  This library uses the MSG_DONTWAIT flag to the recv() 
system call to ensure it never blocks, and it performs blocking write() 
calls in a worker thread.  It is those writes that are now failing (with 
EAGAIN), which the library is not prepared for.

I am not sure it makes sense for ASIO to modify descriptor attributes 
when it just being used as an alternative select() (specifically, when 
making an async_read_some() call with null_buffers).  As far as I know, 
epoll/select use does not require the non-blocking setting.

I see this occurring with Boost 1.46.1 on Fedora 14, kernel 2.6.35.  I 
don't notice any changes in the relevant code for the latest release, 
1.48.0.  Is this a bug?  If so, should I wait for it to be fixed, or is 
there already a work-around that is consistent with ASIO's design 
philosophy and would be expected to be stable.

Thank you,
Joe

------------------------------------------------------------------------------
Write once. Port to many.
Get the SDK and tools to simplify cross-platform app development. Create 
new or port existing apps to sell to consumers worldwide. Explore the 
Intel AppUpSM program developer opportunity. appdeveloper.intel.com/join
http://p.sf.net/sfu/intel-appdev
_______________________________________________
asio-users mailing list
asio-users@...
https://lists.sourceforge.net/lists/listinfo/asio-users
_______________________________________________
Using Asio? List your project at
http://think-async.com/Asio/WhoIsUsingAsio

Isidor Zeuner | 20 Dec 18:34
Picon
Favicon

running code before ssl initialization

Hi,

boost::asio::ssl::detail::openssl_init<true>::do_init initializes the
SSL library using the static initialization hook, thereby preventing
code being ran from main() which must be run before SSL initalization
(for example custom allocators being set using
CRYPTO_set_mem_functions). Is there an intended way to do so when
using boost::asio::ssl?

Best regards,

Isidor

------------------------------------------------------------------------------
Write once. Port to many.
Get the SDK and tools to simplify cross-platform app development. Create 
new or port existing apps to sell to consumers worldwide. Explore the 
Intel AppUpSM program developer opportunity. appdeveloper.intel.com/join
http://p.sf.net/sfu/intel-appdev
_______________________________________________
asio-users mailing list
asio-users@...
https://lists.sourceforge.net/lists/listinfo/asio-users
_______________________________________________
Using Asio? List your project at
http://think-async.com/Asio/WhoIsUsingAsio

Picon
Gravatar

Help for debugging or asio.

Hello, I created an http proxy, but I have a problem.
I'm testing, and after some time, the traffic back to zero and then go
up, and returns to zero, etc.

I would like some help to get some information out what the problem.

The proxy uses io_service by a thread, but removed all the threads and
used only a io_service and the problem continued.

--

-- 
osmano807
Joaquim Pedro

------------------------------------------------------------------------------
10 Tips for Better Server Consolidation
Server virtualization is being driven by many needs.  
But none more important than the need to reduce IT complexity 
while improving strategic productivity.  Learn More! 
http://www.accelacomm.com/jaw/sdnl/114/51507609/
_______________________________________________
asio-users mailing list
asio-users@...
https://lists.sourceforge.net/lists/listinfo/asio-users
_______________________________________________
Using Asio? List your project at
http://think-async.com/Asio/WhoIsUsingAsio

Andrey Kulikov | 11 Dec 21:23
Picon

asio and async SSL stream: how to detect end of data/connection close?

Hello,

I'm trying to make asio and SSL friends.
Everything going well, but one thing is causing inconvenience: how to
detect if peer close connection, and distinguish it from situation
when peer just take a short break in sending data, aming to continue
it few seconds later?

boost 1.48
OpenSSL 1.0.0e
Compiled to 32-bit code using VS10
Working on W7 x64.

My confusion comes from the fact, that asio behaviour is different for
ordinary socjket and SSL-stream.
If I use tcp::socket - I receive EOF error when peer close connection.
But for boost::asio::ssl::stream<boost::asio::ip::tcp::socket> - it is
not hte case. Instead, async_read_some returns 0 as bytes transfered,
and if I try to continue to read from SSL stream - returns short_error
( http://www.boost.org/doc/libs/1_47_0/doc/h...re/streams.html ).

So, the questions is: is it expected behaviour, or I misconfigure anything?

Client code  snippet:
    class client
    {
    public:

         // bla-bla-bla-bla-bla ....
         //
        void handle_write(const boost::system::error_code& error)
        {
            if (!error)
            {
                socket_.async_read_some(boost::asio::buffer(reply_, max_length),
                    boost::bind(&client::handle_read, this,
                    boost::asio::placeholders::error,
                    boost::asio::placeholders::bytes_transferred));
            }
            else
            {
                std::cout << "Write failed: " << error.message() << "\n";
            }
        }

        void handle_read(const boost::system::error_code& error,
                        size_t bytes_transferred)
        {

            std::cout << "Bytes transfered: " << bytes_transferred << "\n";
            if (!error)
            {
                std::cout << "Reply: ";
                std::cout.write(reply_, bytes_transferred);
                std::cout << "\n";

                std::cout << "Reading...\n";
                socket_.async_read_some(boost::asio::buffer(reply_, max_length),
                    boost::bind(&client::handle_read, this,
                    boost::asio::placeholders::error,
                    boost::asio::placeholders::bytes_transferred));
            }
            else if (0 != bytes_transferred)
            {
                std::cout << "Read failed: " << error.message() << ":"
<< error.value() << "\n";
            }
        }

    private:
        boost::asio::ssl::stream<boost::asio::ip::tcp::socket> socket_;
        boost::asio::streambuf request_;
        char reply_[max_length];
    };

If we remove if (0 != bytes_transferred), we'll get "short read" :(.

If we'll use code as-ai, output will be something like this:

=====================
Request is:
GET / HTTP/1.0
Cookie: Nama-nama=Vala-vala

Bytes transfered: 1024

Reply: HTTP/1.0 200 ok
Content-type: text/html

<HTML><BODY BGCOLOR="#ffffff">
..... bla-bla-bla ....

Reading...
Bytes transfered: 1024

..... bla-bla-bla ....
..... bla-bla-bla ....
Reading...
Bytes transfered: 482

..... bla-bla-bla ....
</BODY></HTML>

Reading...
Bytes transfered: 0
=====================

At the same time, if instead async_read_some  we write code, what for
ordinary socket will return EOF:
              boost::asio::async_read(socket_, response_,
                  boost::asio::transfer_at_least(1),
                  boost::bind(&client::handle_read_content, this,
                  boost::asio::placeholders::error));

then for SSL-socket we'll get 0 as bytes transfered, and then short_read.

I know that there is not way to detect disconnect in case if peer, for
example, was just unplugged from the network.
But how to detect explicit clean peer disconnect from situation when
peer just do not send data for a some time, but may be will do it
little bit later?

Or, may be I do not understant something?

WBR,
Andrey

------------------------------------------------------------------------------
Learn Windows Azure Live!  Tuesday, Dec 13, 2011
Microsoft is holding a special Learn Windows Azure training event for 
developers. It will provide a great way to learn Windows Azure and what it 
provides. You can attend the event by watching it streamed LIVE online.  
Learn more at http://p.sf.net/sfu/ms-windowsazure
_______________________________________________
asio-users mailing list
asio-users@...
https://lists.sourceforge.net/lists/listinfo/asio-users
_______________________________________________
Using Asio? List your project at
http://think-async.com/Asio/WhoIsUsingAsio


Gmane