/* * TheUnhandledExceptionFilter * Logs an unhandled exception */ static LONG CALLBACK TheUnhandledExceptionFilter(LPEXCEPTION_POINTERS pException) { // Logs exception into buffer and calls the callback auto Log = [pException](char* buffer, size_t size, bool reg, bool stack, bool trace) { if (LogException(buffer, size, (LPEXCEPTION_POINTERS)pException, reg, stack, trace)) ExceptionCallback(buffer); }; // Try to make a very descriptive exception, for that we need to malloc a huge buffer... if (auto buffer = (char*)malloc(max_logsize_ever)) { Log(buffer, max_logsize_ever, true, true, true); free(buffer); } else { // Use a static buffer, no need for any allocation static const auto size = max_logsize_basic + max_logsize_regs + max_logsize_stackdump; static char static_buf[size]; static_assert(size <= max_static_buffer, "Static buffer is too big"); Log(buffer = static_buf, sizeof(static_buf), true, true, false); } // Continue exception propagation return (PrevFilter ? PrevFilter(pException) : EXCEPTION_CONTINUE_SEARCH); // I'm not really sure about this return }
void TcpConnectionImpl::handle_write(const boost::system::error_code& error) { if(!error && !m_isClosing) { // write next message m_messages.pop_front(); if (!m_messages.empty()) { //ci::app::console() << "Client message:" << m_messages.front() << std::endl; boost::asio::async_write(m_socket, boost::asio::buffer(m_messages.front()), boost::bind(&TcpConnectionImpl::handle_write, this, boost::asio::placeholders::error)); } else { // restart heartbeat timer (optional) restartHeartbeatTimer(); } } else if (error) { ExceptionCallback(error); } }
void TcpConnectionImpl::handle_connect(const boost::system::error_code& error) { if(m_isClosing) return; if (!error) { // we are connected! m_isConnected = true; // let listeners know ConnectedCallback(m_endPoint); // start heartbeat timer (optional) restartHeartbeatTimer(); // await the first message read(); } else { // there was an error :( m_isConnected = false; ExceptionCallback(error); // schedule a timer to reconnect after 5 seconds restartReconnectTimer(); } }
bool Test() { bool fail = Test2(); int number = 0; asIScriptEngine *engine = asCreateScriptEngine(ANGELSCRIPT_VERSION); RegisterScriptArray(engine, true); RegisterScriptString_Generic(engine); // Test GetTypeIdByDecl if( engine->GetTypeIdByDecl("int") != engine->GetTypeIdByDecl("const int") ) TEST_FAILED; if( engine->GetTypeIdByDecl("string") != engine->GetTypeIdByDecl("const string") ) TEST_FAILED; // A handle to a const is different from a handle to a non-const if( engine->GetTypeIdByDecl("string@") == engine->GetTypeIdByDecl("const string@") ) TEST_FAILED; // Test debugging engine->RegisterGlobalProperty("int number", &number); COutStream out; engine->SetMessageCallback(asMETHOD(COutStream,Callback), &out, asCALL_THISCALL); asIScriptModule *mod = engine->GetModule("Module1", asGM_ALWAYS_CREATE); mod->AddScriptSection(":1", script1, strlen(script1), 0); mod->Build(); mod = engine->GetModule("Module2", asGM_ALWAYS_CREATE); mod->AddScriptSection(":2", script2, strlen(script2), 0); mod->Build(); // Bind all functions that the module imports mod = engine->GetModule("Module1"); mod->BindAllImportedFunctions(); asIScriptContext *ctx = engine->CreateContext(); ctx->SetLineCallback(asFUNCTION(LineCallback), 0, asCALL_CDECL); ctx->SetExceptionCallback(asFUNCTION(ExceptionCallback), 0, asCALL_CDECL); ctx->Prepare(mod->GetFunctionByDecl("void main()")); int r = ctx->Execute(); if( r == asEXECUTION_EXCEPTION ) { // It is possible to examine the callstack even after the Execute() method has returned ExceptionCallback(ctx, 0); } ctx->Release(); engine->Release(); if( printBuffer != correct ) { TEST_FAILED; printf("%s", printBuffer.c_str()); } // Success return fail; }
void TcpConnectionImpl::handle_read(const boost::system::error_code& error) { if (!error) { std::string msg; std::istream is(&m_buffer); std::getline(is, msg); // TODO: you could do some message processing here, like breaking it up // into smaller parts, rejecting unknown messages or handling the message protocol while (!msg.empty()) { // create function to notify listeners MessageCallback(msg); std::getline(is, msg); } // restart heartbeat timer (optional) restartHeartbeatTimer(); // wait for the next message read(); } else { ExceptionCallback(error); // try to reconnect if external host disconnects if(error.value() != 0) { m_isConnected = false; // let listeners know DisconnectedCallback(m_endPoint); // schedule a timer to reconnect after 5 seconds restartReconnectTimer(); } else { do_close(); } } }