Skip to content

Commit

Permalink
can reconnect at attach-detach after attach
Browse files Browse the repository at this point in the history
  • Loading branch information
satoren committed Feb 2, 2017
1 parent f243312 commit 8fbfcc9
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 29 deletions.
4 changes: 3 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ include(cmake/FindLua.cmake)
include_directories(SYSTEM ${LUA_INCLUDE_DIRS})
link_directories(${LUA_LIBRARY_DIRS})

file(GLOB HEADER_FILE RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} include/lrdb/*.hpp)
file(GLOB HEADER_FILE RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} include/lrdb/*.hpp)
file(GLOB HEADER_FILE_SERVER RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} include/lrdb/server/*.hpp)
set(HEADER_FILE ${HEADER_FILE} ${HEADER_FILE_SERVER})

if(LRDB_USE_BOOST_ASIO)
add_definitions(-DLRDB_USE_BOOST_ASIO)
Expand Down
11 changes: 8 additions & 3 deletions include/lrdb/debugger.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#pragma once


#if __cplusplus >= 201103L || (defined(_MSC_VER) && _MSC_VER >= 1800)

#include <cstdio>
Expand All @@ -17,7 +16,6 @@ extern "C" {
#include <lualib.h>
}


namespace lrdb {
namespace json {
using namespace ::picojson;
Expand Down Expand Up @@ -671,7 +669,7 @@ class debugger {
}
}
/// @brief pause
void pause() { pause_ = true; }
void pause() { step_type_ = STEP_PAUSE; }
/// @brief unpause(continue)
void unpause() {
pause_ = false;
Expand All @@ -693,6 +691,8 @@ class debugger {
return "step_in";
} else if (step_type_ == STEP_OUT) {
return "step_out";
} else if (step_type_ == STEP_PAUSE) {
return "pause";
}
return "exception";
}
Expand Down Expand Up @@ -852,6 +852,10 @@ class debugger {
if (step_callstack_size_ > callstack.size()) {
pause_ = true;
}
break;
case STEP_PAUSE:
pause_ = true;
break;
case STEP_NONE:
break;
}
Expand Down Expand Up @@ -896,6 +900,7 @@ class debugger {
STEP_OVER,
STEP_IN,
STEP_OUT,
STEP_PAUSE,
};

lua_State* state_;
Expand Down
9 changes: 5 additions & 4 deletions include/lrdb/server.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
#include <utility>
#include <vector>

#include "debug_command.hpp"
#include "debugger.hpp"
#include "message.hpp"
#include "server/debug_command.hpp"

#ifdef EMSCRIPTEN
#include "command_stream_socket_emscripten.hpp"
#include "server/command_stream_socket_emscripten.hpp"
#else
#include "command_stream_socket.hpp"
#include "server/command_stream_socket.hpp"
#endif

namespace lrdb {
Expand Down Expand Up @@ -111,7 +111,8 @@ class basic_server {
const json::value& param = message::get_param(req);
const json::value& reqid = message::get_id(req);

typedef json::value (*exec_cmd_fn)(debugger & debugger, const json::value& param, bool& error);
typedef json::value (*exec_cmd_fn)(debugger & debugger,
const json::value& param, bool& error);
static const std::map<std::string, exec_cmd_fn> cmd_map = {
#define LRDB_DEBUG_COMMAND_TABLE(NAME) \
{ #NAME, &command::exec_##NAME }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@
#include <asio.hpp>
#endif

#include "debug_command.hpp"
#include "debugger.hpp"
#include "message.hpp"

namespace lrdb {
#ifdef LRDB_USE_BOOST_ASIO
namespace asio {
Expand All @@ -37,16 +33,7 @@ class command_stream_socket {
: endpoint_(asio::ip::tcp::v4(), port),
acceptor_(io_service_, endpoint_),
socket_(io_service_) {
acceptor_.async_accept(socket_, [&](const asio::error_code& ec) {
if (!ec) {
connected_done();
} else {
if (on_error) {
on_error(ec.message());
}
close();
}
});
async_accept();
}

~command_stream_socket() {
Expand All @@ -60,6 +47,10 @@ class command_stream_socket {
on_close();
}
}
void reconnect() {
close();
async_accept();
}

std::function<void(const std::string& data)> on_data;
std::function<void()> on_connection;
Expand All @@ -84,13 +75,28 @@ class command_stream_socket {
if (on_error) {
on_error(ec.message());
}
close();
return true;
reconnect();
return false;
}
return false;
return true;
}

private:

void async_accept()
{
acceptor_.async_accept(socket_, [&](const asio::error_code& ec) {
if (!ec) {
connected_done();
}
else {
if (on_error) {
on_error(ec.message());
}
reconnect();
}
});
}
void connected_done() {
if (on_connection) {
on_connection();
Expand All @@ -112,7 +118,7 @@ class command_stream_socket {
if (on_error) {
on_error(ec.message());
}
close();
reconnect();
}
});
}
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once

#include "debugger.hpp"
#include "message.hpp"
#include "lrdb/debugger.hpp"
#include "lrdb/message.hpp"

namespace lrdb {

Expand Down
2 changes: 1 addition & 1 deletion vscode_extension/src/lrdbDebug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -642,7 +642,7 @@ class LuaDebugSession extends DebugSession {

protected disconnectRequest(response: DebugProtocol.DisconnectResponse, args: DebugProtocol.DisconnectArguments): void {
if (this._debug_server_process) {
this._debug_server_process.disconnect();
this._debug_server_process.kill();
delete this._debug_server_process;
}
if (this._debug_client) {
Expand Down

0 comments on commit 8fbfcc9

Please sign in to comment.