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

View File

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