unknown
1970-01-01 00:00:00 UTC
2. I had tried this before, but ran into threading issue, it made my app
crash
3. So you suggest to use a global mutex to make sure when I am closing one
socket, no async_read or asnyc_write operation happens on it in another
thread.
4. I need to apply this mutex to all my read/write operations like this:
Sign is one connected object in my server app:
void Sign::DoWrite(boost::shared_ptr<Message> msg) {
write_msgs_.push_back(msg);
if (write_msgs_.size() == 1) {
boost::shared_ptr<vector<char> > data(new vector<char>(400, 0));
msg->Write(*data);
clientsPoolMutex.lock();
async_write(socket,
buffer(&(*data)[0], data->size()),
strand_.wrap(bind(&Sign::AfterSend, shared_from_this(), _1,
data)));
}
}
Dean Chen
Best regards
http://blog.csdn.net/csfreebird
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir="ltr">Hi, Slav:<div>
crash
3. So you suggest to use a global mutex to make sure when I am closing one
socket, no async_read or asnyc_write operation happens on it in another
thread.
4. I need to apply this mutex to all my read/write operations like this:
Sign is one connected object in my server app:
void Sign::DoWrite(boost::shared_ptr<Message> msg) {
write_msgs_.push_back(msg);
if (write_msgs_.size() == 1) {
boost::shared_ptr<vector<char> > data(new vector<char>(400, 0));
msg->Write(*data);
clientsPoolMutex.lock();
async_write(socket,
buffer(&(*data)[0], data->size()),
strand_.wrap(bind(&Sign::AfterSend, shared_from_this(), _1,
data)));
}
}
Dean Chen
Best regards
http://blog.csdn.net/csfreebird
asio::strand strand( io_service );
...
//no parallel async_read/write or handle_accept() can be called since
we're within asio::strand, but your server can start using clients so lock
clientsPoolMutex.lock();
for each client in clients
{
//multiple harmless errors can arise (connection was already
closed, connection was forced to be close and so on) - just ignoring them
is fine, but usage of overloaded function which do not accept error codes
asio::error_code shutdownErrorCode;
asio::error_code closeErrorCode;
if ( client->lastMessageReceived < currentTime - ( 60 * 60 ) )
{
client->socket.shutdown( asio::socket_base::shutdown_both,
shutdownErrorCode );
client->socket.close( closeErrorCode );
}
}
_______________________________________________
asio-users mailing list
https://lists.sourceforge.net/lists/listinfo/asio-users
_______________________________________________
Using Asio? List your project at
http://think-async.com/Asio/WhoIsUsingAsio
--f46d04428a6c4da7c204f6055fc2...
//no parallel async_read/write or handle_accept() can be called since
we're within asio::strand, but your server can start using clients so lock
clientsPoolMutex.lock();
for each client in clients
{
//multiple harmless errors can arise (connection was already
closed, connection was forced to be close and so on) - just ignoring them
is fine, but usage of overloaded function which do not accept error codes
asio::error_code shutdownErrorCode;
asio::error_code closeErrorCode;
if ( client->lastMessageReceived < currentTime - ( 60 * 60 ) )
{
client->socket.shutdown( asio::socket_base::shutdown_both,
shutdownErrorCode );
client->socket.close( closeErrorCode );
}
}
Thanks for your response. I used to create one thread to close the
connection if it's timeout. But this cause my process to crash. Because
I
cannot close one socket in another thread when there is another
async_write or async_read operation on it.
http://web.archiveorange.com/archive/v/Q0J4VefPMc2v8QYvcVr3
Most likely you have a threading issue in your program where you close a
socket from one thread while simultaneously starting another async
operation on the same socket from another thread. If you are sure this is
not the case, please attach a small, complete program that exhibits the
problem. Thanks.
Could you teach me your way, how to close the socket safely?
_______________________________________________
asio-users mailing list
https://lists.sourceforge.net/lists/listinfo/asio-users
_______________________________________________
Using Asio? List your project at
http://think-async.com/Asio/WhoIsUsingAsio
------------------------------------------------------------------------------connection if it's timeout. But this cause my process to crash. Because
I
cannot close one socket in another thread when there is another
async_write or async_read operation on it.
http://web.archiveorange.com/archive/v/Q0J4VefPMc2v8QYvcVr3
Most likely you have a threading issue in your program where you close a
socket from one thread while simultaneously starting another async
operation on the same socket from another thread. If you are sure this is
not the case, please attach a small, complete program that exhibits the
problem. Thanks.
Could you teach me your way, how to close the socket safely?
I had the same problem. Each day ~15000 users was connecting the
server but some of connections wasn't closed, so when ~500000
connections was hanging (some of them was live), server must be
restarted - it happened like each month-two.
Timers will significantly slow your server down, indeed. As was
answered to me in this mailing lists, it should be solved with
periodic iteration through all connections to kill any which hang too
much depending your inner server logic.
For my server I kick everyone who didn't sent anything to server for
an hour. Kicking process is being invoked each 5 minutes. Iteration
through 10000 connections is lightning fast: takes less time than
human can measure (so less than 80 milliseconds) so it's possible to
run it each second but not needed.
Hi,
My server needs to handle thousands of TCP connections. But I find
many connections are not closed because async_read method blocks,
it's weird!
Today my server cannot work because there are too many TCP
connections, I have to restart OS.
I read a few articles which describes how to use dead line timer
with async_read, but I have some sad experience, thousands of
timers will slow down my server.
http://stackoverflow.com/questions/22777835/is-boostasio-asyn-read-
with-timer-a-good-idea
Why does my async_read blocks?
Can I use dead line timer in this case?
Dean Chen
Best regards
http://blog.csdn.net/csfreebird
-------------------------------------------------------------------
-----------
_______________________________________________
asio-users mailing list
https://lists.sourceforge.net/lists/listinfo/asio-users
_______________________________________________
Using Asio? List your project at
http://think-async.com/Asio/WhoIsUsingAsio
------------------------------------------------------------------------------server but some of connections wasn't closed, so when ~500000
connections was hanging (some of them was live), server must be
restarted - it happened like each month-two.
Timers will significantly slow your server down, indeed. As was
answered to me in this mailing lists, it should be solved with
periodic iteration through all connections to kill any which hang too
much depending your inner server logic.
For my server I kick everyone who didn't sent anything to server for
an hour. Kicking process is being invoked each 5 minutes. Iteration
through 10000 connections is lightning fast: takes less time than
human can measure (so less than 80 milliseconds) so it's possible to
run it each second but not needed.
Hi,
My server needs to handle thousands of TCP connections. But I find
many connections are not closed because async_read method blocks,
it's weird!
Today my server cannot work because there are too many TCP
connections, I have to restart OS.
I read a few articles which describes how to use dead line timer
with async_read, but I have some sad experience, thousands of
timers will slow down my server.
http://stackoverflow.com/questions/22777835/is-boostasio-asyn-read-
with-timer-a-good-idea
Why does my async_read blocks?
Can I use dead line timer in this case?
Dean Chen
Best regards
http://blog.csdn.net/csfreebird
-------------------------------------------------------------------
-----------
_______________________________________________
asio-users mailing list
https://lists.sourceforge.net/lists/listinfo/asio-users
_______________________________________________
Using Asio? List your project at
http://think-async.com/Asio/WhoIsUsingAsio
_______________________________________________
asio-users mailing list
https://lists.sourceforge.net/lists/listinfo/asio-users
_______________________________________________
Using Asio? List your project at
http://think-async.com/Asio/WhoIsUsingAsio
------------------------------------------------------------------------------asio-users mailing list
https://lists.sourceforge.net/lists/listinfo/asio-users
_______________________________________________
Using Asio? List your project at
http://think-async.com/Asio/WhoIsUsingAsio
_______________________________________________
asio-users mailing list
https://lists.sourceforge.net/lists/listinfo/asio-users
_______________________________________________
Using Asio? List your project at
http://think-async.com/Asio/WhoIsUsingAsio
_______________________________________________
asio-users mailing list
https://lists.sourceforge.net/lists/listinfo/asio-users
_______________________________________________
Using Asio? List your project at
http://think-async.com/Asio/WhoIsUsingAsio
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir="ltr">Hi, Slav:<div>