nghttpx: Convert MemcachedParseState to enum class

This commit is contained in:
Tatsuhiro Tsujikawa 2018-10-17 11:25:29 +09:00
parent 4d562b773b
commit 571404c6e8
2 changed files with 13 additions and 13 deletions

View File

@ -424,7 +424,7 @@ int MemcachedConnection::parse_packet() {
auto busy = false; auto busy = false;
switch (parse_state_.state) { switch (parse_state_.state) {
case MEMCACHED_PARSE_HEADER24: { case MemcachedParseState::HEADER24: {
if (recvbuf_.last - in < 24) { if (recvbuf_.last - in < 24) {
recvbuf_.drain_reset(in - recvbuf_.pos); recvbuf_.drain_reset(in - recvbuf_.pos);
return 0; return 0;
@ -494,17 +494,17 @@ int MemcachedConnection::parse_packet() {
} }
if (parse_state_.extralen) { if (parse_state_.extralen) {
parse_state_.state = MEMCACHED_PARSE_EXTRA; parse_state_.state = MemcachedParseState::EXTRA;
parse_state_.read_left = parse_state_.extralen; parse_state_.read_left = parse_state_.extralen;
} else { } else {
parse_state_.state = MEMCACHED_PARSE_VALUE; parse_state_.state = MemcachedParseState::VALUE;
parse_state_.read_left = parse_state_.totalbody - parse_state_.keylen - parse_state_.read_left = parse_state_.totalbody - parse_state_.keylen -
parse_state_.extralen; parse_state_.extralen;
} }
busy = true; busy = true;
break; break;
} }
case MEMCACHED_PARSE_EXTRA: { case MemcachedParseState::EXTRA: {
// We don't use extra for now. Just read and forget. // We don't use extra for now. Just read and forget.
auto n = std::min(static_cast<size_t>(recvbuf_.last - in), auto n = std::min(static_cast<size_t>(recvbuf_.last - in),
parse_state_.read_left); parse_state_.read_left);
@ -515,7 +515,7 @@ int MemcachedConnection::parse_packet() {
recvbuf_.reset(); recvbuf_.reset();
return 0; return 0;
} }
parse_state_.state = MEMCACHED_PARSE_VALUE; parse_state_.state = MemcachedParseState::VALUE;
// since we require keylen == 0, totalbody - extralen == // since we require keylen == 0, totalbody - extralen ==
// valuelen // valuelen
parse_state_.read_left = parse_state_.read_left =
@ -523,7 +523,7 @@ int MemcachedConnection::parse_packet() {
busy = true; busy = true;
break; break;
} }
case MEMCACHED_PARSE_VALUE: { case MemcachedParseState::VALUE: {
auto n = std::min(static_cast<size_t>(recvbuf_.last - in), auto n = std::min(static_cast<size_t>(recvbuf_.last - in),
parse_state_.read_left); parse_state_.read_left);

View File

@ -44,14 +44,14 @@ namespace shrpx {
struct MemcachedRequest; struct MemcachedRequest;
enum { enum class MemcachedParseState {
MEMCACHED_PARSE_HEADER24, HEADER24,
MEMCACHED_PARSE_EXTRA, EXTRA,
MEMCACHED_PARSE_VALUE, VALUE,
}; };
// Stores state when parsing response from memcached server // Stores state when parsing response from memcached server
struct MemcachedParseState { struct MemcachedParseContext {
// Buffer for value, dynamically allocated. // Buffer for value, dynamically allocated.
std::vector<uint8_t> value; std::vector<uint8_t> value;
// cas in response // cas in response
@ -66,7 +66,7 @@ struct MemcachedParseState {
// Number of bytes left to read variable length field. // Number of bytes left to read variable length field.
size_t read_left; size_t read_left;
// Parser state; see enum above // Parser state; see enum above
int state; MemcachedParseState state;
// status_code in response // status_code in response
int status_code; int status_code;
// op in response // op in response
@ -138,7 +138,7 @@ private:
StringRef sni_name_; StringRef sni_name_;
tls::TLSSessionCache tls_session_cache_; tls::TLSSessionCache tls_session_cache_;
ConnectBlocker connect_blocker_; ConnectBlocker connect_blocker_;
MemcachedParseState parse_state_; MemcachedParseContext parse_state_;
const Address *addr_; const Address *addr_;
SSL_CTX *ssl_ctx_; SSL_CTX *ssl_ctx_;
// Sum of the bytes to be transmitted in sendbufv_. // Sum of the bytes to be transmitted in sendbufv_.