nghttpx: Convert memcached op to enum class
This commit is contained in:
parent
571404c6e8
commit
0c4e9fef29
|
@ -445,7 +445,7 @@ int MemcachedConnection::parse_packet() {
|
|||
}
|
||||
++in;
|
||||
|
||||
parse_state_.op = *in++;
|
||||
parse_state_.op = static_cast<MemcachedOp>(*in++);
|
||||
parse_state_.keylen = util::get_uint16(in);
|
||||
in += 2;
|
||||
parse_state_.extralen = *in++;
|
||||
|
@ -463,7 +463,8 @@ int MemcachedConnection::parse_packet() {
|
|||
if (req->op != parse_state_.op) {
|
||||
MCLOG(WARN, this)
|
||||
<< "opcode in response does not match to the request: want "
|
||||
<< static_cast<uint32_t>(req->op) << ", got " << parse_state_.op;
|
||||
<< static_cast<uint32_t>(req->op) << ", got "
|
||||
<< static_cast<uint32_t>(parse_state_.op);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -479,7 +480,7 @@ int MemcachedConnection::parse_packet() {
|
|||
return -1;
|
||||
}
|
||||
|
||||
if (parse_state_.op == MEMCACHED_OP_GET &&
|
||||
if (parse_state_.op == MemcachedOp::GET &&
|
||||
parse_state_.status_code == 0 && parse_state_.extralen == 0) {
|
||||
MCLOG(WARN, this) << "response for GET does not have extra";
|
||||
return -1;
|
||||
|
@ -661,9 +662,9 @@ void MemcachedConnection::drain_send_queue(size_t nwrite) {
|
|||
|
||||
size_t MemcachedConnection::serialized_size(MemcachedRequest *req) {
|
||||
switch (req->op) {
|
||||
case MEMCACHED_OP_GET:
|
||||
case MemcachedOp::GET:
|
||||
return 24 + req->key.size();
|
||||
case MEMCACHED_OP_ADD:
|
||||
case MemcachedOp::ADD:
|
||||
default:
|
||||
return 24 + 8 + req->key.size() + req->value.size();
|
||||
}
|
||||
|
@ -676,14 +677,14 @@ void MemcachedConnection::make_request(MemcachedSendbuf *sendbuf,
|
|||
std::fill(std::begin(headbuf.buf), std::end(headbuf.buf), 0);
|
||||
|
||||
headbuf[0] = MEMCACHED_REQ_MAGIC;
|
||||
headbuf[1] = req->op;
|
||||
headbuf[1] = static_cast<uint8_t>(req->op);
|
||||
switch (req->op) {
|
||||
case MEMCACHED_OP_GET:
|
||||
case MemcachedOp::GET:
|
||||
util::put_uint16be(&headbuf[2], req->key.size());
|
||||
util::put_uint32be(&headbuf[8], req->key.size());
|
||||
headbuf.write(24);
|
||||
break;
|
||||
case MEMCACHED_OP_ADD:
|
||||
case MemcachedOp::ADD:
|
||||
util::put_uint16be(&headbuf[2], req->key.size());
|
||||
headbuf[4] = 8;
|
||||
util::put_uint32be(&headbuf[8], 8 + req->key.size() + req->value.size());
|
||||
|
|
|
@ -43,6 +43,7 @@ using namespace nghttp2;
|
|||
namespace shrpx {
|
||||
|
||||
struct MemcachedRequest;
|
||||
enum class MemcachedOp : uint8_t;
|
||||
|
||||
enum class MemcachedParseState {
|
||||
HEADER24,
|
||||
|
@ -70,7 +71,7 @@ struct MemcachedParseContext {
|
|||
// status_code in response
|
||||
int status_code;
|
||||
// op in response
|
||||
int op;
|
||||
MemcachedOp op;
|
||||
};
|
||||
|
||||
struct MemcachedSendbuf {
|
||||
|
|
|
@ -35,9 +35,9 @@
|
|||
|
||||
namespace shrpx {
|
||||
|
||||
enum {
|
||||
MEMCACHED_OP_GET = 0x00,
|
||||
MEMCACHED_OP_ADD = 0x02,
|
||||
enum class MemcachedOp : uint8_t {
|
||||
GET = 0x00,
|
||||
ADD = 0x02,
|
||||
};
|
||||
|
||||
struct MemcachedRequest;
|
||||
|
@ -50,7 +50,7 @@ struct MemcachedRequest {
|
|||
std::vector<uint8_t> value;
|
||||
MemcachedResultCallback cb;
|
||||
uint32_t expiry;
|
||||
int op;
|
||||
MemcachedOp op;
|
||||
bool canceled;
|
||||
};
|
||||
|
||||
|
|
|
@ -330,7 +330,7 @@ int tls_session_new_cb(SSL *ssl, SSL_SESSION *session) {
|
|||
}
|
||||
|
||||
auto req = std::make_unique<MemcachedRequest>();
|
||||
req->op = MEMCACHED_OP_ADD;
|
||||
req->op = MemcachedOp::ADD;
|
||||
req->key = MEMCACHED_SESSION_CACHE_KEY_PREFIX.str();
|
||||
req->key +=
|
||||
util::format_hex(balloc, StringRef{id, static_cast<size_t>(idlen)});
|
||||
|
@ -398,7 +398,7 @@ SSL_SESSION *tls_session_get_cb(SSL *ssl,
|
|||
}
|
||||
|
||||
auto req = std::make_unique<MemcachedRequest>();
|
||||
req->op = MEMCACHED_OP_GET;
|
||||
req->op = MemcachedOp::GET;
|
||||
req->key = MEMCACHED_SESSION_CACHE_KEY_PREFIX.str();
|
||||
req->key +=
|
||||
util::format_hex(balloc, StringRef{id, static_cast<size_t>(idlen)});
|
||||
|
|
|
@ -272,7 +272,7 @@ void memcached_get_ticket_key_cb(struct ev_loop *loop, ev_timer *w,
|
|||
|
||||
auto req = std::make_unique<MemcachedRequest>();
|
||||
req->key = "nghttpx:tls-ticket-key";
|
||||
req->op = MEMCACHED_OP_GET;
|
||||
req->op = MemcachedOp::GET;
|
||||
req->cb = [conn_handler, w](MemcachedRequest *req, MemcachedResult res) {
|
||||
switch (res.status_code) {
|
||||
case MEMCACHED_ERR_NO_ERROR:
|
||||
|
|
Loading…
Reference in New Issue