Listening channels implemented
This commit is contained in:
@@ -108,6 +108,10 @@ public:
|
||||
StreamBuffer *out() { return sb_out_.get(); }
|
||||
StreamBuffer *in() { return sb_in_.get(); }
|
||||
|
||||
// The channel ID. These are reused.
|
||||
//
|
||||
int chid() { return chid_; }
|
||||
|
||||
// If this is a socket connection, the receiver's port number.
|
||||
//
|
||||
int port() { return port_; }
|
||||
@@ -140,6 +144,7 @@ private:
|
||||
std::string target_;
|
||||
friend class DrivenEngine;
|
||||
};
|
||||
using UniqueChannel = std::unique_ptr<Channel>;
|
||||
|
||||
class DrivenEngine {
|
||||
public:
|
||||
@@ -155,6 +160,11 @@ public:
|
||||
virtual void event_init() {}
|
||||
virtual void event_update() {}
|
||||
|
||||
// Specify the set of listening ports.
|
||||
// This can only be used during the init routine.
|
||||
//
|
||||
void listen_port(int port);
|
||||
|
||||
// Get the current time.
|
||||
//
|
||||
// DRIVER: This returns the time most recently stored by the driver
|
||||
@@ -169,7 +179,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.
|
||||
//
|
||||
std::unique_ptr<Channel> new_outgoing_channel(const std::string &target);
|
||||
UniqueChannel new_outgoing_channel(const std::string &target);
|
||||
|
||||
// Create a new channel from any pending incoming connection. If there is no
|
||||
// incoming connection, returns nullptr.
|
||||
@@ -182,7 +192,7 @@ public:
|
||||
// using drv_get_target, drv_peek_outgoing, drv_sent_outgoing,
|
||||
// drv_recv_incoming.
|
||||
//
|
||||
std::unique_ptr<Channel> new_incoming_channel();
|
||||
UniqueChannel new_incoming_channel();
|
||||
|
||||
// Obtain the stdio channel. There is only one stdio channel. It is owned
|
||||
// by the DrivenEngine. It is an error to delete the stdio channel.
|
||||
@@ -223,6 +233,11 @@ public:
|
||||
//
|
||||
static const int MAX_CHAN = 256;
|
||||
|
||||
// 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);
|
||||
|
||||
// Get a list of all recently-closed channels. The driver should
|
||||
// discard all socket information associated with these channels.
|
||||
// Caution: this may contain channels that the driver has never
|
||||
@@ -348,11 +363,12 @@ private:
|
||||
private:
|
||||
Channel *channels_[MAX_CHAN];
|
||||
int next_unused_chid_;
|
||||
std::unique_ptr<Channel> stdio_channel_;
|
||||
std::vector<std::unique_ptr<Channel>> accepted_channels_;
|
||||
UniqueChannel stdio_channel_;
|
||||
std::vector<UniqueChannel> accepted_channels_;
|
||||
std::set<int> new_closed_;
|
||||
std::set<int> new_outgoing_;
|
||||
util::LuaSourcePtr lua_source_;
|
||||
std::set<int> listen_ports_;
|
||||
bool rescan_lua_source_;
|
||||
double clock_;
|
||||
bool stop_driver_;
|
||||
|
||||
Reference in New Issue
Block a user