Use fewer pointers refactor: eliminate some pointers in DrivenEngine
This commit is contained in:
@@ -1,23 +0,0 @@
|
|||||||
{
|
|
||||||
"permissions": {
|
|
||||||
"allow": [
|
|
||||||
"WebFetch(domain:dev.epicgames.com)",
|
|
||||||
"WebFetch(domain:github.com)",
|
|
||||||
"Bash(grep:*)",
|
|
||||||
"WebSearch",
|
|
||||||
"Bash(clangd:*)",
|
|
||||||
"Bash(clangd-16:*)",
|
|
||||||
"Bash(ssh jyelon-office \"clangd --version 2>/dev/null || clangd-16 --version 2>/dev/null || clangd-18 --version 2>/dev/null || ls /usr/bin/clangd*\")",
|
|
||||||
"Bash(git check-ignore:*)",
|
|
||||||
"Bash(ls:*)",
|
|
||||||
"WebFetch(domain:ikrima.dev)",
|
|
||||||
"WebFetch(domain:indxzero.github.io)"
|
|
||||||
],
|
|
||||||
"deny": [
|
|
||||||
"Bash(git commit *)",
|
|
||||||
"Bash(git push *)",
|
|
||||||
"Bash(rm -rf *)"
|
|
||||||
],
|
|
||||||
"defaultMode": "acceptEdits"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -110,22 +110,20 @@ static DrivenEngine *make_engine(std::string_view kind) {
|
|||||||
//////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
//////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
Channel::Channel(DrivenEngine *de, int chid, int port, const eng::string &target, bool stop) {
|
Channel::Channel(int chid, int port, const eng::string &target, bool stop) {
|
||||||
chid_ = chid;
|
chid_ = chid;
|
||||||
port_ = port;
|
port_ = port;
|
||||||
closed_ = false;
|
closed_ = false;
|
||||||
target_ = target;
|
target_ = target;
|
||||||
stop_driver_ = stop;
|
stop_driver_ = stop;
|
||||||
sb_in_ = eng::make_shared<StreamBuffer>();
|
|
||||||
sb_out_ = eng::make_shared<StreamBuffer>();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string_view Channel::peek_outgoing() const {
|
std::string_view Channel::peek_outgoing() const {
|
||||||
return sb_out_->view();
|
return sb_out_.view();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Channel::sent_outgoing(int nbytes) {
|
void Channel::sent_outgoing(int nbytes) {
|
||||||
sb_out_->read_bytes(nbytes);
|
sb_out_.read_bytes(nbytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
@@ -148,7 +146,7 @@ double DrivenEngine::get_clock() {
|
|||||||
SharedChannel DrivenEngine::new_outgoing_channel(const eng::string &target) {
|
SharedChannel DrivenEngine::new_outgoing_channel(const eng::string &target) {
|
||||||
int chid = find_unused_chid();
|
int chid = find_unused_chid();
|
||||||
new_outgoing_.push_back(chid);
|
new_outgoing_.push_back(chid);
|
||||||
SharedChannel result = eng::make_shared<Channel>(this, chid, 0, target, stop_driver_);
|
SharedChannel result = eng::make_shared<Channel>(chid, 0, target, stop_driver_);
|
||||||
channels_[chid] = result;
|
channels_[chid] = result;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@@ -441,7 +439,7 @@ void DrivenEngine::drv_recv_incoming(uint32_t chid, uint32_t nbytes, const char
|
|||||||
if (nbytes > 0) {
|
if (nbytes > 0) {
|
||||||
std::string_view sbytes(bytes, nbytes);
|
std::string_view sbytes(bytes, nbytes);
|
||||||
Channel *ch = get_chid(chid);
|
Channel *ch = get_chid(chid);
|
||||||
ch->sb_in_->write_bytes(sbytes);
|
ch->sb_in_.write_bytes(sbytes);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -454,7 +452,7 @@ void DrivenEngine::drv_notify_close(uint32_t chid, uint32_t len, const char *dat
|
|||||||
|
|
||||||
uint32_t DrivenEngine::drv_notify_accept(uint32_t port) {
|
uint32_t DrivenEngine::drv_notify_accept(uint32_t port) {
|
||||||
int chid = find_unused_chid();
|
int chid = find_unused_chid();
|
||||||
channels_[chid] = eng::make_shared<Channel>(this, chid, port, "", stop_driver_);
|
channels_[chid] = eng::make_shared<Channel>(chid, port, "", stop_driver_);
|
||||||
accepted_channels_.push_back(channels_[chid]);
|
accepted_channels_.push_back(channels_[chid]);
|
||||||
return chid;
|
return chid;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -65,8 +65,8 @@ class Channel : public eng::opnew {
|
|||||||
public:
|
public:
|
||||||
// Get the buffers associated with this channel.
|
// Get the buffers associated with this channel.
|
||||||
//
|
//
|
||||||
StreamBuffer *out() { return sb_out_.get(); }
|
StreamBuffer *out() { return &sb_out_; }
|
||||||
StreamBuffer *in() { return sb_in_.get(); }
|
StreamBuffer *in() { return &sb_in_; }
|
||||||
|
|
||||||
// The channel ID. These are reused.
|
// The channel ID. These are reused.
|
||||||
//
|
//
|
||||||
@@ -96,7 +96,7 @@ public:
|
|||||||
// Channels are referenced by shared_ptr. You can
|
// Channels are referenced by shared_ptr. You can
|
||||||
// release your shared_ptr at any time.
|
// release your shared_ptr at any time.
|
||||||
//
|
//
|
||||||
Channel(DrivenEngine *de, int chid, int port, const eng::string &target, bool stop);
|
Channel(int chid, int port, const eng::string &target, bool stop);
|
||||||
~Channel() {};
|
~Channel() {};
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@@ -110,8 +110,8 @@ private:
|
|||||||
int chid_;
|
int chid_;
|
||||||
|
|
||||||
// These are the in/out buffers presented to the user.
|
// These are the in/out buffers presented to the user.
|
||||||
std::shared_ptr<StreamBuffer> sb_in_;
|
StreamBuffer sb_in_;
|
||||||
std::shared_ptr<StreamBuffer> sb_out_;
|
StreamBuffer sb_out_;
|
||||||
|
|
||||||
int port_;
|
int port_;
|
||||||
bool closed_;
|
bool closed_;
|
||||||
|
|||||||
Reference in New Issue
Block a user