Get rid of wrap-string-view

This commit is contained in:
2022-02-24 13:50:43 -05:00
parent eb6cbebd20
commit 08f6aa2092
10 changed files with 53 additions and 68 deletions

View File

@@ -37,30 +37,30 @@ static void if_error_print_and_exit(const drv::string &str) {
}
}
static drv::string_view read_file(const char *fn, char *buf, int bufsize, drv::string &err) {
static std::string_view read_file(const char *fn, char *buf, int bufsize, drv::string &err) {
FILE *f = fopen(fn, "r");
if (f == 0) {
err = drv::string("cannot read file") + fn;
buf[0] = 0;
return drv::string_view(buf, 0);
return std::string_view(buf, 0);
}
int nread = fread(buf, 1, bufsize, f);
if (nread < 0) {
err = drv::string("cannot read file: ") + fn;
buf[0] = 0;
return drv::string_view(buf, 0);
return std::string_view(buf, 0);
}
if (nread == bufsize) {
err = drv::string("file too large: ") + fn;
buf[0] = 0;
return drv::string_view(buf, 0);
return std::string_view(buf, 0);
}
err = "";
return drv::string_view(buf, nread);
return std::string_view(buf, nread);
}
static SSL_CTX *new_ssl_context(bool server_cert, bool root_certs, drv::string_view require_cert) {
static SSL_CTX *new_ssl_context(bool server_cert, bool root_certs, std::string_view require_cert) {
SSL_CTX *ctx = SSL_CTX_new(TLS_method());
SSL_CTX_set_mode(ctx, SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER);
SSL_CTX_set_mode(ctx, SSL_MODE_ENABLE_PARTIAL_WRITE);
@@ -158,20 +158,20 @@ public:
void handle_lua_source() {
if (driven_->drv_get_rescan_lua_source()) {
drv::string err;
drv::string_view ctrl = read_file("lua/control.lst", chbuf.get(), CHBUF_SIZE, err);
std::string_view ctrl = read_file("lua/control.lst", chbuf.get(), CHBUF_SIZE, err);
if_error_print_and_exit(err);
drv::vector<drv::string> names = drv::parse_control_lst(ctrl);
driven_->drv_clear_lua_source();
for (const drv::string &str : names) {
drv::string lfn = drv::string("lua/") + str;
drv::string_view data = read_file(lfn.c_str(), chbuf.get(), CHBUF_SIZE, err);
std::string_view data = read_file(lfn.c_str(), chbuf.get(), CHBUF_SIZE, err);
if_error_print_and_exit(err);
driven_->drv_add_lua_source(str, data);
}
}
}
void close_channel(ChanInfo &chan, drv::string_view err) {
void close_channel(ChanInfo &chan, std::string_view err) {
// std::cerr << "Closing channel " << chan.chid << std::endl;
assert(chan.state != CHAN_INACTIVE);
// Close and release the SSL channel.