Boost.Asio server application close get "This application has requested the Runtime to terminate it in an unusual way."
Boost.Asio server application close get "This application has
requested the Runtime to terminate it in an unusual way."
My code is too mush!
std.hpp:
/*
** author: ylj
** create: 2009/08/27
*/
#ifndef STD_HPP
#define STD_HPP
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <strstream>
#include <utility>
#include <vector>
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cwchar>
#include <cwctype>
#endif // STD_HPP
tcontainer.hpp:
/*
** author: ylj
** create: 2010/02/10
*/
#ifndef TCONTAINER_HPP
#define TCONTAINER_HPP
#include <deque>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#if 0
#include
AMDG l.jay Yuan wrote:
Boost.Asio server application close get "This application has requested the Runtime to terminate it in an unusual way."
My code is too mush!
<snip>
If anyone conneted server and not close, I type "exit" to close server then got "This application has requested the Runtime to terminate it in an unusual way." I have check and check and check. I cannot find out why. Anyone can help me?
Can you run it under a debugger to find where it's crashing. In Christ, Steven Watanabe
in msvcrt.dll
2010/3/7 Steven Watanabe
AMDG
l.jay Yuan wrote:
Boost.Asio server application close get "This application has requested the Runtime to terminate it in an unusual way."
My code is too mush!
<snip>
If anyone conneted server and not close, I type "exit" to close server then got "This application has requested the Runtime to terminate it in an unusual way." I have check and check and check. I cannot find out why. Anyone can help me?
Can you run it under a debugger to find where it's crashing.
In Christ, Steven Watanabe
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
On Sun, Mar 7, 2010 at 5:58 PM, l.jay Yuan
in msvcrt.dll
But in the callstack at that point, what is your last code that is called, better to just past the callstack here, or even better, post a complete compilable example that demonstrates your problem. Also, please do not top-post.
There is a sample base on Boost.Asio example --> chat.
Most changes on chat_server.cpp
chat_message.hpp:
//
// chat_message.hpp
// ~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2008 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef CHAT_MESSAGE_HPP
#define CHAT_MESSAGE_HPP
#include <cstdio>
#include <cstdlib>
#include <cstring>
class chat_message
{
public:
enum { header_length = 4 };
enum { max_body_length = 512 };
chat_message()
: body_length_(0)
{
}
const char* data() const
{
return data_;
}
char* data()
{
return data_;
}
size_t length() const
{
return header_length + body_length_;
}
const char* body() const
{
return data_ + header_length;
}
char* body()
{
return data_ + header_length;
}
size_t body_length() const
{
return body_length_;
}
void body_length(size_t length)
{
body_length_ = length;
if (body_length_ > max_body_length)
body_length_ = max_body_length;
}
bool decode_header()
{
using namespace std; // For strncat and atoi.
char header[header_length + 1] = "";
strncat(header, data_, header_length);
body_length_ = atoi(header);
if (body_length_ > max_body_length)
{
body_length_ = 0;
return false;
}
return true;
}
void encode_header()
{
using namespace std; // For sprintf and memcpy.
char header[header_length + 1] = "";
sprintf(header, "%4d", body_length_);
memcpy(data_, header, header_length);
}
private:
char data_[header_length + max_body_length];
size_t body_length_;
};
#endif // CHAT_MESSAGE_HPP
chat_client.cpp:
//
// chat_client.cpp
// ~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2008 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#include <cstdlib>
#include <deque>
#include <iostream>
#include
On Sun, Mar 7, 2010 at 5:58 PM, l.jay Yuan
wrote: in msvcrt.dll
But in the callstack at that point, what is your last code that is called, better to just past the callstack here, or even better, post a complete compilable example that demonstrates your problem.
Also, please do not top-post. _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
If I understand correctly, you work with MSVC. Then you can use its IDE/Debugger to run and debug your server. Just compile your project in "debug" mode, i.e. without optimizations. Remove SEH __try/__except filters/handlers from your code. Go to Debug-->Exceptions menu. In the "Thrown" column select all the list. Now run your server in the IDE and try reproducing the issue. When it occurs and an exception is thrown, the IDE stops and you can analyze the problem. I guess you've got some invalid memory access, so a general recommendation is to avoid the manual control over objects life-time -- instead, use smart-pointers (shared_ptr, shared_from_this idiom); also avoid using c-style arrays -- stick with std::vector instead.
...
step 1: start server step 2: start client, connect to server step 3: on server, type "exit" result: server crashed "This application has requested the Runtime to terminate it in an unusual way. Please contact the application's support team for more information."
Please do not top post (again). Also, no I will not read your code, as its a few hundred lines, so please only post to the list your changes, or the change that triggers your error. regards, Jens Weller -- GRATIS für alle GMX-Mitglieder: Die maxdome Movie-FLAT! Jetzt freischalten unter http://portal.gmx.net/de/go/maxdome01
thanks everyone, i solved my problem.
just use io_service.stop() instead of acceptor.close() and socket.close().
maybe i must to research the implementation.
2010/3/10 Jens Weller
...
step 1: start server step 2: start client, connect to server step 3: on server, type "exit" result: server crashed "This application has requested the Runtime to terminate it in an unusual way. Please contact the application's support team for more information."
Please do not top post (again).
Also, no I will not read your code, as its a few hundred lines, so please only post to the list your changes, or the change that triggers your error.
regards,
Jens Weller -- GRATIS für alle GMX-Mitglieder: Die maxdome Movie-FLAT! Jetzt freischalten unter http://portal.gmx.net/de/go/maxdome01 _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
thanks everyone, i solved my problem. just use io_service.stop() instead of acceptor.close() and socket.close(). maybe i must to research the implementation.
It's not a solution but just a "dirty" workaround: by stopping io_service you prevent the further invocation of handlers. I guess some of your handlers used to get called after destruction of the object they were bound to. You can avoid this situation by binding the handlers to shared_from_this().
can you code the Boost.Asio chat server example for exit by a command?
if you can, my problem solved.
2010/3/10 Igor R
thanks everyone, i solved my problem. just use io_service.stop() instead of acceptor.close() and socket.close(). maybe i must to research the implementation.
It's not a solution but just a "dirty" workaround: by stopping io_service you prevent the further invocation of handlers. I guess some of your handlers used to get called after destruction of the object they were bound to. You can avoid this situation by binding the handlers to shared_from_this(). _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
int main(int argc, char* argv[])
{
try
{
if (argc < 2)
{
std::cerr << "Usage: chat_server <port> [<port> ...]\n";
return 1;
}
boost::asio::io_service io_service;
chat_server_list servers;
for (int i = 1; i < argc; ++i)
{
using namespace std; // For atoi.
tcp::endpoint endpoint(tcp::v4(), atoi(argv[i]));
chat_server_ptr server(new chat_server(io_service, endpoint));
servers.push_back(server);
}
io_service.run();
/**************
just like this, so io_service.run(); is not needed.
boost::thread io_thread(boost::bind(&boost::asio::io_service::run,
&io_service));
std::string line;
while(getline(std::cin, line)) {
if (line == "exit") {
/* do what? now i am using io_service.stop(); */
break;
}
}
io_thread.join();
***************/
}
catch (std::exception& e)
{
std::cerr << "Exception: " << e.what() << "\n";
}
return 0;
}
2010/3/11 l.jay Yuan
can you code the Boost.Asio chat server example for exit by a command? if you can, my problem solved.
2010/3/10 Igor R
: thanks everyone, i solved my problem. just use io_service.stop() instead of acceptor.close() and socket.close(). maybe i must to research the implementation.
It's not a solution but just a "dirty" workaround: by stopping io_service you prevent the further invocation of handlers. I guess some of your handlers used to get called after destruction of the object they were bound to. You can avoid this situation by binding the handlers to shared_from_this(). _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
l.jay Yuan wrote:
can you code the Boost.Asio chat server example for exit by a command? if you can, my problem solved.
Please do not top post: http://www.boost.org/community/policy.html#quoting regards - michael -- ---------------------------------- Michael Caisse Object Modeling Designs www.objectmodelingdesigns.com
participants (6)
-
Igor R
-
Jens Weller
-
l.jay Yuan
-
Michael Caisse
-
OvermindDL1
-
Steven Watanabe