Commit ec0bb779 authored by Dan Melnic's avatar Dan Melnic Committed by Facebook Github Bot

Expose the IOBuf SharedInfo::userData

Summary:
Expose the IOBuf SharedInfo::userData

(Note: this ignores all push blocking failures!)

Reviewed By: yfeldblum

Differential Revision: D13577451

fbshipit-source-id: b52ebbf77d00594a04c26e629d5c208e92801d93
parent d5f9c13d
......@@ -912,6 +912,17 @@ class IOBuf {
}
}
/**
*
* Returns the SharedInfo::userData if sharedInfo()
* is not nullptr, nullptr otherwise
*
**/
void* getUserData() const {
SharedInfo* info = sharedInfo();
return info ? info->userData : nullptr;
}
/**
* Return true if all IOBufs in this chain are managed by the usual
* refcounting mechanism (and so the lifetime of the underlying memory
......
......@@ -165,6 +165,33 @@ TEST(IOBuf, TakeOwnership) {
EXPECT_EQ(1, deleteCount);
}
TEST(IOBuf, GetUserData) {
{
const uint32_t size = 1234;
uint8_t data[size];
unique_ptr<IOBuf> buf1(IOBuf::wrapBuffer(data, size));
EXPECT_EQ(buf1->getUserData(), nullptr);
}
{
size_t val = 0;
uint32_t size = 4321;
uint8_t* data = static_cast<uint8_t*>(malloc(size));
unique_ptr<IOBuf> buf2(IOBuf::takeOwnership(
data,
size,
[](void* buf, void* userData) {
EXPECT_EQ(*static_cast<size_t*>(userData), 400);
free(buf);
},
&val));
EXPECT_EQ(buf2->getUserData(), &val);
val = 200;
EXPECT_EQ(*static_cast<size_t*>(buf2->getUserData()), 200);
val = 400;
}
}
TEST(IOBuf, WrapBuffer) {
const uint32_t size1 = 1234;
uint8_t buf1[size1];
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment