Migrated engine to using dlmalloc through eng::

This commit is contained in:
2022-02-24 02:17:41 -05:00
parent acc00289fb
commit f467944095
61 changed files with 631 additions and 590 deletions

View File

@@ -101,7 +101,7 @@
#include "streambuffer.hpp"
class DrivenEngine;
using UniqueDrivenEngine = std::unique_ptr<DrivenEngine>;
using UniqueDrivenEngine = eng::unique_ptr<DrivenEngine>;
using DrivenEngineMaker = UniqueDrivenEngine (*)();
class Channel {
@@ -120,7 +120,7 @@ public:
int port() { return port_; }
// If this is an outgoing socket connection, get the target host.
const std::string &target() { return target_; }
const eng::string &target() { return target_; }
// True if the remote closed the connection, or a failure occurred.
//
@@ -131,18 +131,18 @@ public:
// If this is an empty string, there is no error. If this is set,
// then the channel is also closed.
//
std::string error() const { return error_; }
eng::string error() const { return error_; }
// Set the prompt for readline mode.
//
void set_prompt(const std::string &prompt);
void set_prompt(const eng::string &prompt);
// Do not construct your own Channels. Instead,
// use methods of class DrivenEngine like new_outgoing_channel.
// Channels are referenced by shared_ptr. You can
// release your shared_ptr at any time.
//
Channel(DrivenEngine *de, int chid, int port, const std::string &target, bool stop);
Channel(DrivenEngine *de, int chid, int port, const eng::string &target, bool stop);
~Channel() {};
private:
@@ -162,31 +162,31 @@ private:
int chid_;
// These are the in/out buffers presented to the user.
std::shared_ptr<StreamBuffer> sb_in_;
std::shared_ptr<StreamBuffer> sb_out_;
eng::shared_ptr<StreamBuffer> sb_in_;
eng::shared_ptr<StreamBuffer> sb_out_;
// If this is stdio, we inject tty echoes into the output stream.
// This buffer holds the users output interleaved with the tty echoes.
// In any other channel, this is just another pointer to sb_out.
std::shared_ptr<StreamBuffer> sb_drvout_;
eng::shared_ptr<StreamBuffer> sb_drvout_;
int port_;
bool closed_;
std::string error_;
std::string target_;
eng::string error_;
eng::string target_;
bool stop_driver_;
// Readline stuff. Only used on channel 0 (stdio).
std::string desired_command_;
std::string current_command_;
std::string desired_prompt_;
std::string current_prompt_;
eng::string desired_command_;
eng::string current_command_;
eng::string desired_prompt_;
eng::string current_prompt_;
char readline_lastc_;
friend class DrivenEngine;
};
using SharedChannel = std::shared_ptr<Channel>;
using SharedChannel = eng::shared_ptr<Channel>;
class DrivenEngine {
public:
@@ -228,7 +228,7 @@ public:
// actually opening the connection and relaying data into the channel using
// drv_get_target, drv_peek_outgoing, drv_sent_outgoing, drv_recv_incoming.
//
SharedChannel new_outgoing_channel(const std::string &target);
SharedChannel new_outgoing_channel(const eng::string &target);
// Create a new channel from any pending incoming connection. If there is no
// incoming connection, returns nullptr.
@@ -254,7 +254,7 @@ public:
// Obtain the output buffer of the stdio channel as an ostream.
//
std::ostream &stdostream() { return get_stdio_channel()->out()->ostream(); }
eng::ostream &stdostream() { return get_stdio_channel()->out()->ostream(); }
// Fetches the lua source, and takes ownership of it. The DrivenEngine
// no longer contains the source after calling this.
@@ -288,13 +288,13 @@ public:
// Get a list of all the listening ports. The driver is expected
// to fetch this set shortly after the event_init callback is invoked.
//
const std::vector<int> &drv_get_listen_ports() const;
const eng::vector<int> &drv_get_listen_ports() const;
// Get a list of all recently-opened channels that were created using
// drv_new_outgoing_channel. The driver should initiate outgoing
// connections for these channels.
//
const std::vector<int> &drv_get_new_outgoing() const;
const eng::vector<int> &drv_get_new_outgoing() const;
// Clear the list of recently-opened channels that were created using
// drv_new_outgoing_channel.
@@ -306,7 +306,7 @@ public:
// is supposed to be talking to. Non-socket channels and incoming channels
// have empty targets.
//
const std::string &drv_get_target(int chid) const;
const eng::string &drv_get_target(int chid) const;
// Return true if the outgoing buffer is empty.
//
@@ -343,7 +343,7 @@ public:
// delete it. Closing a channel prevents it from showing up in
// 'drv_list_channels'.
//
void drv_notify_close(int chid, std::string_view err);
void drv_notify_close(int chid, eng::string_view err);
// Notify the DrivenEngine that somebody connected to an incoming port.
// This will cause the DrivenEngine to allocate a new channel and put the
@@ -361,7 +361,7 @@ public:
// Set the lua source code. The driver is expected to read the lua source
// code and store it (using this function) once before invoking
//
void drv_add_lua_source(std::string_view fn, std::string_view data);
void drv_add_lua_source(eng::string_view fn, eng::string_view data);
// Invoke the init or update event.
//
@@ -417,7 +417,7 @@ public:
static void register_maker(const char *kind, DrivenEngineMaker maker);
static void print_usage(std::ostream &strm, const char *progname);
static void print_usage(eng::ostream &strm, const char *progname);
static UniqueDrivenEngine make(const char *kind);
@@ -433,10 +433,10 @@ private:
SharedChannel channels_[MAX_CHAN];
int next_unused_chid_;
SharedChannel stdio_channel_;
std::vector<SharedChannel> accepted_channels_;
std::vector<int> new_outgoing_;
eng::vector<SharedChannel> accepted_channels_;
eng::vector<int> new_outgoing_;
util::LuaSourcePtr lua_source_;
std::vector<int> listen_ports_;
eng::vector<int> listen_ports_;
bool rescan_lua_source_;
double clock_;
bool stop_driver_;