Small overhaul using string_view

This commit is contained in:
2022-03-04 16:45:47 -05:00
parent b17b34924e
commit cfeeb2eaf3
6 changed files with 60 additions and 39 deletions

View File

@@ -199,10 +199,9 @@ public:
void handle_console_output() {
while (true) {
int nbytes; const char *bytes;
driven_->drv_peek_outgoing(0, &nbytes, &bytes);
if (nbytes == 0) break;
int nwrote = console_write(bytes, nbytes);
std::string_view s = driven_->drv_peek_outgoing(0);
if (s.size() == 0) break;
int nwrote = console_write(s.data(), s.size());
if (nwrote <= 0) break;
driven_->drv_sent_outgoing(0, nwrote);
}
@@ -215,7 +214,7 @@ public:
int nread = console_read(buffer, 256);
if (nread <= 0) break;
read_console_recently_ = true;
driven_->drv_recv_incoming(0, nread, buffer);
driven_->drv_recv_incoming(0, std::string_view(buffer, nread));
}
}
@@ -279,13 +278,11 @@ public:
}
// Try to write plaintext to the channel.
int nbytes; const char *bytes;
driven_->drv_peek_outgoing(chan.chid, &nbytes, &bytes);
if (nbytes > 0) {
int sbytes = nbytes;
std::string_view s = driven_->drv_peek_outgoing(chan.chid);
if (s.size() > 0) {
int sbytes = s.size();
if (sbytes > 65536) sbytes = 65536;
int wbytes = socket_send(chan.socket, bytes, sbytes, err);
// std::cerr << "send.bytes="<< wbytes << ".errno=" << errno << " ";
int wbytes = socket_send(chan.socket, s.data(), sbytes, err);
if (wbytes < 0) {
close_channel(chan, err);
} else {
@@ -296,11 +293,10 @@ public:
// Try to read plaintext from the channel.
// Someday, find a way to avoid this copy.
int nrecv = socket_recv(chan.socket, chbuf.get(), 65536, err);
// std::cerr << "recv.bytes="<< nrecv << ".errno=" << errno << " ";
if (nrecv < 0) {
close_channel(chan, err);
} else {
driven_->drv_recv_incoming(chan.chid, nrecv, chbuf.get());
driven_->drv_recv_incoming(chan.chid, std::string_view(chbuf.get(), nrecv));
}
// Update the ready-flags for next time.
@@ -350,7 +346,7 @@ public:
// Try to read data.
int read_result = SSL_read(chan.ssl, chbuf.get(), 65536);
if (read_result > 0) {
driven_->drv_recv_incoming(chan.chid, read_result, chbuf.get());
driven_->drv_recv_incoming(chan.chid, std::string_view(chbuf.get(), read_result));
chan.ready_now = true;
} else {
process_ssl_error(chan, read_result);
@@ -411,7 +407,9 @@ public:
// Peek output buffers and determine channel release flags.
for (ChanInfo &chan : chans_) {
driven_->drv_peek_outgoing(chan.chid, &chan.nbytes, &chan.bytes);
std::string_view s = driven_->drv_peek_outgoing(chan.chid);
chan.nbytes = s.size();
chan.bytes = s.data();
chan.just_released = false;
if ((chan.nbytes == 0)&&(!chan.released)) {
chan.released = driven_->drv_get_channel_released(chan.chid);