[Boost-users] [asio] Disable nagle algorithm on Windows XP

98 views
Skip to first unread message

Tobias Jähnel

unread,
Mar 25, 2009, 8:28:33 AM3/25/09
to boost...@lists.boost.org
Hi,

I'm developing a TCP-Client using boost::asio and discovered that ACKs
to responses from the server are sent with some delay (~200ms) and I
get the data not before this ACK has been sent.

When I disable nagle in registry as described by Microsoft it works fine.
(See: http://support.microsoft.com/kb/823764)

To avoid those registry hacks I want to find another way to get rid of
this latency.
I'm already using blocking sockets as suggest in above document.

I also tried to set the no_delay option but this has no effect at all.
boost::asio::ip::tcp::no_delay option(true);
socket.set_option(option);

== Code Snippets ==
I use the boost asio library as follows:

// open connection (from synchronous TCP daytime client example)
boost::asio::io_service io_service;
tcp::resolver resolver(io_service);
tcp::resolver::query query(ipaddress, port);
tcp::resolver::iterator endpoint_iterator = resolver.resolve(query);
tcp::resolver::iterator end;
boost::system::error_code error = boost::asio::error::host_not_found;
while (error && endpoint_iterator != end)
{
socket.close();
socket.connect(*endpoint_iterator++, error);
}

// send some data
boost::asio::write(socket, boost::asio::buffer(package, size));

// reception is done inside a thread
while(true)
{
// receive data
size_t length = socket.read_some(boost::asio::buffer(resp), error);
if (error == boost::asio::error::eof)
{ // Connection closed cleanly by peer.
// ... do sth. }
else if (error)
{ // Some error has happened
// ... do sth.
}
// ... process received data and notify main thread to send the
next piece of data
}
=======

Thank you for all suggestions.

Tobias
_______________________________________________
Boost-users mailing list
Boost...@lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/boost-users

Igor R

unread,
Mar 25, 2009, 10:07:44 AM3/25/09
to boost...@lists.boost.org
> I'm already using blocking sockets as suggest in above document.

According to that document, you should not enocounter this problem
when using blocking sockets. Probably your socket is not blocking?
To make a socket blocking you should write something like this:
boost::asio::socket_base::non_blocking_io command(true);
socket.io_control(command);

Tobias Jähnel

unread,
Mar 25, 2009, 10:58:17 AM3/25/09
to boost...@lists.boost.org
Hi Igor,

thanks for your reply.
I guess you mean setting non_blocking_io to false.
Tried to enter those lines, but still have no change:
boost::asio::socket_base::non_blocking_io command(false);
socket.io_control(command);

Tobias

张亚霏

unread,
Mar 25, 2009, 11:18:54 AM3/25/09
to boost-users
try native WSA API "setsockopt" with the TCP_NODELAY option.
if it still does not work, there may be something wrong with your windows xp. or debug the asio

------------------
best wishes to you
张亚霏
 
 
 
------------------ Original ------------------
From:  "Tobias J?hnel"<tjae...@gmail.com>;
Date:  Wed, Mar 25, 2009 10:58 PM
To:  "boost-users"<boost...@lists.boost.org>;
Subject:  Re: [Boost-users] [asio] Disable nagle algorithm on Windows XP

Tobias Jähnel

unread,
Mar 25, 2009, 11:40:10 AM3/25/09
to boost...@lists.boost.org
Hi,

I inserted.
int on=1;
setsockopt(socket.native(), IPPROTO_TCP, TCP_NODELAY, (char *)&on,
sizeof(on) );
right after I open the connection. Still no change :(

Tobias

2009/3/25 张亚霏 <kimi67...@qq.com>:

Reply all
Reply to author
Forward
0 new messages