memchunk: Rename append_cstr as append

We may later add append(const T &), where we require T for .size() and
.data().  We can coexist former append_cstr and new one.  If we pass
string literal, append(const (&)[N]) is selected.
This commit is contained in:
Tatsuhiro Tsujikawa 2015-01-22 23:54:30 +09:00
parent 5a93bedf72
commit d174ffeb00
4 changed files with 14 additions and 14 deletions

View File

@ -156,7 +156,7 @@ template <typename Memchunk> struct Memchunks {
return all; return all;
} }
template <size_t N> size_t append_cstr(const char (&s)[N]) { template <size_t N> size_t append(const char (&s)[N]) {
return append(s, N - 1); return append(s, N - 1);
} }
size_t remove(void *data, size_t count) { size_t remove(void *data, size_t count) {

View File

@ -88,14 +88,14 @@ void test_memchunks_append(void) {
MemchunkPool16 pool; MemchunkPool16 pool;
Memchunks16 chunks(&pool); Memchunks16 chunks(&pool);
chunks.append_cstr("012"); chunks.append("012");
auto m = chunks.tail; auto m = chunks.tail;
CU_ASSERT(3 == m->len()); CU_ASSERT(3 == m->len());
CU_ASSERT(13 == m->left()); CU_ASSERT(13 == m->left());
chunks.append_cstr("3456789abcdef@"); chunks.append("3456789abcdef@");
CU_ASSERT(16 == m->len()); CU_ASSERT(16 == m->len());
CU_ASSERT(0 == m->left()); CU_ASSERT(0 == m->left());
@ -129,7 +129,7 @@ void test_memchunks_drain(void) {
MemchunkPool16 pool; MemchunkPool16 pool;
Memchunks16 chunks(&pool); Memchunks16 chunks(&pool);
chunks.append_cstr("0123456789"); chunks.append("0123456789");
size_t nread; size_t nread;

View File

@ -363,13 +363,13 @@ int HttpDownstreamConnection::push_upload_data_chunk(const uint8_t *data,
if (chunked) { if (chunked) {
auto chunk_size_hex = util::utox(datalen); auto chunk_size_hex = util::utox(datalen);
output->append(chunk_size_hex.c_str(), chunk_size_hex.size()); output->append(chunk_size_hex.c_str(), chunk_size_hex.size());
output->append_cstr("\r\n"); output->append("\r\n");
} }
output->append(data, datalen); output->append(data, datalen);
if (chunked) { if (chunked) {
output->append_cstr("\r\n"); output->append("\r\n");
} }
signal_write(); signal_write();
@ -383,7 +383,7 @@ int HttpDownstreamConnection::end_upload_data() {
} }
auto output = downstream_->get_request_buf(); auto output = downstream_->get_request_buf();
output->append_cstr("0\r\n\r\n"); output->append("0\r\n\r\n");
signal_write(); signal_write();

View File

@ -587,16 +587,16 @@ void HttpsUpstream::error_reply(unsigned int status_code) {
auto output = downstream->get_response_buf(); auto output = downstream->get_response_buf();
output->append_cstr("HTTP/1.1 "); output->append("HTTP/1.1 ");
auto status_str = http2::get_status_string(status_code); auto status_str = http2::get_status_string(status_code);
output->append(status_str.c_str(), status_str.size()); output->append(status_str.c_str(), status_str.size());
output->append_cstr("\r\nServer: "); output->append("\r\nServer: ");
output->append(get_config()->server_name, strlen(get_config()->server_name)); output->append(get_config()->server_name, strlen(get_config()->server_name));
output->append_cstr("\r\nContent-Length: "); output->append("\r\nContent-Length: ");
auto cl = util::utos(html.size()); auto cl = util::utos(html.size());
output->append(cl.c_str(), cl.size()); output->append(cl.c_str(), cl.size());
output->append_cstr("\r\nContent-Type: text/html; " output->append("\r\nContent-Type: text/html; "
"charset=UTF-8\r\nConnection: close\r\n\r\n"); "charset=UTF-8\r\nConnection: close\r\n\r\n");
output->append(html.c_str(), html.size()); output->append(html.c_str(), html.size());
downstream->add_response_sent_bodylen(html.size()); downstream->add_response_sent_bodylen(html.size());
@ -770,7 +770,7 @@ int HttpsUpstream::on_downstream_body(Downstream *downstream,
downstream->add_response_sent_bodylen(len); downstream->add_response_sent_bodylen(len);
if (downstream->get_chunked_response()) { if (downstream->get_chunked_response()) {
output->append_cstr("\r\n"); output->append("\r\n");
} }
return 0; return 0;
} }
@ -778,7 +778,7 @@ int HttpsUpstream::on_downstream_body(Downstream *downstream,
int HttpsUpstream::on_downstream_body_complete(Downstream *downstream) { int HttpsUpstream::on_downstream_body_complete(Downstream *downstream) {
if (downstream->get_chunked_response()) { if (downstream->get_chunked_response()) {
auto output = downstream->get_response_buf(); auto output = downstream->get_response_buf();
output->append_cstr("0\r\n\r\n"); output->append("0\r\n\r\n");
} }
if (LOG_ENABLED(INFO)) { if (LOG_ENABLED(INFO)) {
DLOG(INFO, downstream) << "HTTP response completed"; DLOG(INFO, downstream) << "HTTP response completed";