Small overhaul using string_view
This commit is contained in:
@@ -86,7 +86,9 @@ void Channel::set_prompt(const eng::string &p) {
|
||||
desired_prompt_ = p;
|
||||
}
|
||||
|
||||
void Channel::feed_readline(int nbytes, const char *bytes) {
|
||||
void Channel::feed_readline(std::string_view data) {
|
||||
int nbytes = data.size();
|
||||
const char *bytes = data.data();
|
||||
for (int i = 0; i < nbytes; i++) {
|
||||
char c = bytes[i];
|
||||
if ((c == '\n') && (readline_lastc_ == '\r')) {
|
||||
@@ -115,9 +117,8 @@ void Channel::feed_readline(int nbytes, const char *bytes) {
|
||||
}
|
||||
}
|
||||
|
||||
void Channel::peek_outgoing(int *nbytes, const char **bytes) const {
|
||||
*nbytes = sb_drvout_->fill();
|
||||
*bytes = sb_drvout_->data();
|
||||
std::string_view Channel::peek_outgoing() const {
|
||||
return sb_drvout_->view();
|
||||
}
|
||||
|
||||
void Channel::pump_readline() {
|
||||
@@ -215,30 +216,29 @@ const eng::string &DrivenEngine::drv_get_target(int chid) const {
|
||||
}
|
||||
|
||||
bool DrivenEngine::drv_outgoing_empty(int chid) const {
|
||||
int nbytes; const char *bytes;
|
||||
drv_peek_outgoing(chid, &nbytes, &bytes);
|
||||
return (nbytes == 0);
|
||||
std::string_view view = drv_peek_outgoing(chid);
|
||||
return (view.size() == 0);
|
||||
}
|
||||
|
||||
bool DrivenEngine::drv_get_channel_released(int chid) const {
|
||||
return channels_[chid].use_count() == 1;
|
||||
}
|
||||
|
||||
void DrivenEngine::drv_peek_outgoing(int chid, int *nbytes, const char **bytes) const {
|
||||
return get_chid(chid)->peek_outgoing(nbytes, bytes);
|
||||
std::string_view DrivenEngine::drv_peek_outgoing(int chid) const {
|
||||
return get_chid(chid)->peek_outgoing();
|
||||
}
|
||||
|
||||
void DrivenEngine::drv_sent_outgoing(int chid, int nbytes) {
|
||||
return get_chid(chid)->sent_outgoing(nbytes);
|
||||
}
|
||||
|
||||
void DrivenEngine::drv_recv_incoming(int chid, int nbytes, const char *bytes) {
|
||||
if (nbytes > 0) {
|
||||
void DrivenEngine::drv_recv_incoming(int chid, std::string_view data) {
|
||||
if (data.size() > 0) {
|
||||
Channel *ch = get_chid(chid);
|
||||
if (ch->sb_drvout_ != ch->sb_out_) {
|
||||
ch->feed_readline(nbytes, bytes);
|
||||
ch->feed_readline(data);
|
||||
} else {
|
||||
ch->sb_in_->write_bytes(bytes, nbytes);
|
||||
ch->sb_in_->write_bytes(data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user