Use fewer pointers refactor: eliminate some pointers in DrivenEngine
This commit is contained in:
@@ -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;
|
||||
port_ = port;
|
||||
closed_ = false;
|
||||
target_ = target;
|
||||
stop_driver_ = stop;
|
||||
sb_in_ = eng::make_shared<StreamBuffer>();
|
||||
sb_out_ = eng::make_shared<StreamBuffer>();
|
||||
}
|
||||
|
||||
std::string_view Channel::peek_outgoing() const {
|
||||
return sb_out_->view();
|
||||
return sb_out_.view();
|
||||
}
|
||||
|
||||
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) {
|
||||
int chid = find_unused_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;
|
||||
return result;
|
||||
}
|
||||
@@ -441,7 +439,7 @@ void DrivenEngine::drv_recv_incoming(uint32_t chid, uint32_t nbytes, const char
|
||||
if (nbytes > 0) {
|
||||
std::string_view sbytes(bytes, nbytes);
|
||||
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) {
|
||||
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]);
|
||||
return chid;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user