Skip to content

Commit b55a3c3

Browse files
trondndaverigby
authored andcommitted
Remove CookieIface::validate
It doesn't belong in the CookieIface interface as the one in the old MockCookie class tried to validate that the cookie was in fact a MockCookie, and the one in Cookie validated the input packet (and was used next to execute which would execute the packet etc). Now that we no longer use "const void*" to represent our cookies and dynamic_cast to down-cast from CookieIface the method in MockCookie is no longer needed (as dynamic_cast does this check) Change-Id: If7154e47d9cda2259bafeb70a1b6e38a00c48f6a Reviewed-on: http://review.couchbase.org/c/kv_engine/+/156622 Tested-by: Build Bot <[email protected]> Reviewed-by: Dave Rigby <[email protected]>
1 parent 88a26d6 commit b55a3c3

File tree

5 files changed

+16
-24
lines changed

5 files changed

+16
-24
lines changed

daemon/cookie.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,14 @@ class Cookie : public CookieIface {
7070
return !packet;
7171
}
7272

73-
cb::mcbp::Status validate() override;
73+
/**
74+
* Validates the packet content, and (possibly) set the error
75+
* state and reason.
76+
*
77+
* @return Success if the packet was correctly encoded
78+
* @throw std::runtime_error if an unsupported packet is encountered
79+
*/
80+
cb::mcbp::Status validate();
7481

7582
/**
7683
* Reset the Cookie object to allow it to be reused in the same

include/memcached/cookie_iface.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,6 @@ enum class Status : uint16_t;
2525
*/
2626
class CookieIface : public cb::tracing::Traceable {
2727
public:
28-
/**
29-
* Validates the packet content, and (possibly) set the error
30-
* state and reason.
31-
*
32-
* @return Success if the packet was correctly encoded
33-
* @throw std::runtime_error if an unsupported packet is encountered
34-
*/
35-
virtual cb::mcbp::Status validate() = 0;
36-
3728
/// Is the current cookie blocked?
3829
virtual bool isEwouldblock() const = 0;
3930

programs/engine_testapp/mock_cookie.cc

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,6 @@ MockCookie::~MockCookie() {
2121
}
2222
}
2323

24-
cb::mcbp::Status MockCookie::validate() {
25-
if (magic != MAGIC) {
26-
throw std::runtime_error("MockCookie::validate(): Invalid magic");
27-
}
28-
return cb::mcbp::Status::Success;
29-
}
30-
3124
MockCookie* create_mock_cookie(EngineIface* engine) {
3225
return new MockCookie(engine);
3326
}
@@ -43,7 +36,6 @@ void destroy_mock_cookie(CookieIface* cookie) {
4336
"destroy_mock_cookie: Provided cookie is not a MockCookie");
4437
}
4538

46-
c->validate();
4739
c->disconnect();
4840
if (c->getRefcount() == 0) {
4941
delete c;
@@ -152,7 +144,10 @@ void MockCookie::handleIoComplete(cb::engine_errc completeStatus) {
152144
MockCookie* cookie_to_mock_cookie(const CookieIface* cookie) {
153145
auto* ret =
154146
const_cast<MockCookie*>(dynamic_cast<const MockCookie*>(cookie));
155-
ret->validate();
147+
if (ret == nullptr) {
148+
throw std::runtime_error(
149+
"cookie_to_mock_cookie(): provided cookie is not a MockCookie");
150+
}
156151
return ret;
157152
}
158153

programs/engine_testapp/mock_cookie.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,6 @@ class MockCookie : public CookieIface {
4242

4343
~MockCookie() override;
4444

45-
cb::mcbp::Status validate() override;
46-
4745
bool isEwouldblock() const override {
4846
return handle_ewouldblock;
4947
}
@@ -123,7 +121,6 @@ class MockCookie : public CookieIface {
123121
void waitForNotifications(std::unique_lock<std::mutex>& lock);
124122

125123
private:
126-
const uint64_t magic{MAGIC};
127124
void* engine_data{nullptr};
128125
int sfd{};
129126
cb::engine_errc status{cb::engine_errc::success};

programs/engine_testapp/mock_server.cc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,11 +237,13 @@ struct MockServerCookieApi : public ServerCookieIface {
237237
}
238238

239239
void set_priority(const CookieIface& cookie, ConnectionPriority) override {
240-
const_cast<CookieIface&>(cookie).validate();
240+
// Just verify the cookie type
241+
cookie_to_mock_cookie(cookie);
241242
}
242243

243244
ConnectionPriority get_priority(const CookieIface& cookie) override {
244-
const_cast<CookieIface&>(cookie).validate();
245+
// Just verify the cookie type
246+
cookie_to_mock_cookie(cookie);
245247
return ConnectionPriority::Medium;
246248
}
247249

0 commit comments

Comments
 (0)