Lots of work on removing malloc from driver
This commit is contained in:
@@ -95,11 +95,13 @@
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <ostream>
|
||||
#include "streambuffer.hpp"
|
||||
#include "util.hpp"
|
||||
|
||||
class DrivenEngine;
|
||||
using UniqueDrivenEngine = std::unique_ptr<DrivenEngine>;
|
||||
using DrivenEngineMaker = UniqueDrivenEngine (*)();
|
||||
|
||||
class Channel {
|
||||
public:
|
||||
@@ -299,36 +301,41 @@ 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.
|
||||
//
|
||||
void drv_get_listen_ports(std::set<int> &ports);
|
||||
const std::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.
|
||||
//
|
||||
void drv_get_new_outgoing(std::set<int> &closed);
|
||||
const std::vector<int> &drv_get_new_outgoing() const;
|
||||
|
||||
// Clear the list of recently-opened channels that were created using
|
||||
// drv_new_outgoing_channel.
|
||||
//
|
||||
void drv_clear_new_outgoing();
|
||||
|
||||
// Get the target of a channel. A target is a string like
|
||||
// "www.whatever.com:80". It indicates the host and port that the channel
|
||||
// is supposed to be talking to. Non-socket channels and incoming channels
|
||||
// have empty targets.
|
||||
//
|
||||
const std::string &drv_get_target(int chid);
|
||||
const std::string &drv_get_target(int chid) const;
|
||||
|
||||
// Return true if the outgoing buffer is empty.
|
||||
//
|
||||
bool drv_outgoing_empty(int chid);
|
||||
bool drv_outgoing_empty(int chid) const;
|
||||
|
||||
// Return true if the user has released all references to this channel.
|
||||
// In this case, the driver should initiate shutdown of the channel,
|
||||
// and the driver should eventually call drv_notify_close.
|
||||
//
|
||||
bool drv_get_channel_released(int chid);
|
||||
bool drv_get_channel_released(int chid) const;
|
||||
|
||||
// Get a pointer to the bytes in the outgoing buffer. The pointer returned
|
||||
// here is naturally only valid until the buffer is changed. This function
|
||||
// is used for all channels, including sockets and stdio.
|
||||
//
|
||||
void drv_peek_outgoing(int chid, int *nbytes, const char **bytes);
|
||||
void drv_peek_outgoing(int chid, int *nbytes, const char **bytes) const;
|
||||
|
||||
// Notifies the channel that some bytes were transmitted. This causes those
|
||||
// bytes to be removed from the outgoing buffer. This function is used for
|
||||
@@ -349,7 +356,7 @@ public:
|
||||
// delete it. Closing a channel prevents it from showing up in
|
||||
// 'drv_list_channels'.
|
||||
//
|
||||
void drv_notify_close(int chid, const std::string &err);
|
||||
void drv_notify_close(int chid, std::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
|
||||
@@ -359,11 +366,17 @@ public:
|
||||
//
|
||||
int drv_notify_accept(int port);
|
||||
|
||||
|
||||
// Clear the lua source code.
|
||||
//
|
||||
void drv_clear_lua_source();
|
||||
|
||||
// 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(const char *fn, const char *data);
|
||||
void drv_set_lua_source(util::LuaSourcePtr source);
|
||||
|
||||
|
||||
// Invoke the init or update event.
|
||||
//
|
||||
void drv_invoke_event_init(int argc, char *argv[]);
|
||||
@@ -374,11 +387,11 @@ public:
|
||||
// When the driver sees this flag, it should rescan the source and call
|
||||
// drv_set_source.
|
||||
//
|
||||
bool drv_get_rescan_lua_source();
|
||||
bool drv_get_rescan_lua_source() const;
|
||||
|
||||
// If true, the engine is done. Stop the driver.
|
||||
//
|
||||
bool drv_get_stop_driver();
|
||||
bool drv_get_stop_driver() const;
|
||||
|
||||
//////////////////////////////////////////////////////////////
|
||||
//
|
||||
@@ -409,29 +422,39 @@ public:
|
||||
static void set(DrivenEngine *de);
|
||||
static DrivenEngine *get();
|
||||
|
||||
public:
|
||||
//////////////////////////////////////////////////////////////
|
||||
//
|
||||
// The Registry of DrivenEngineMakers.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
static void register_maker(const char *kind, DrivenEngineMaker maker);
|
||||
|
||||
static void print_usage(std::ostream &strm, const char *progname);
|
||||
|
||||
static UniqueDrivenEngine make(const char *kind);
|
||||
|
||||
private:
|
||||
// Find a currently-unused channel ID. Channel IDs
|
||||
// are small integers that are reused.
|
||||
int find_unused_chid();
|
||||
|
||||
// Get the channel associated with the specified channel ID.
|
||||
Channel *get_chid(int chid);
|
||||
Channel *get_chid(int chid) const;
|
||||
|
||||
private:
|
||||
SharedChannel channels_[MAX_CHAN];
|
||||
int next_unused_chid_;
|
||||
SharedChannel stdio_channel_;
|
||||
std::vector<SharedChannel> accepted_channels_;
|
||||
std::set<int> new_outgoing_;
|
||||
std::vector<int> new_outgoing_;
|
||||
util::LuaSourcePtr lua_source_;
|
||||
std::set<int> listen_ports_;
|
||||
std::vector<int> listen_ports_;
|
||||
bool rescan_lua_source_;
|
||||
double clock_;
|
||||
bool stop_driver_;
|
||||
friend class Channel;
|
||||
};
|
||||
|
||||
using UniqueDrivenEngine = std::unique_ptr<DrivenEngine>;
|
||||
using DrivenEngineMaker = UniqueDrivenEngine (*)();
|
||||
|
||||
#endif // DRIVENENGINE_HPP
|
||||
|
||||
Reference in New Issue
Block a user