当我阅读libevent的源代码时, 我看到了这个评论,但我无法理解"固定"的意思?
/* Make sure that none of the chains we need to copy from is pinned. */
remaining = size - chain->off;
EVUTIL_ASSERT(remaining >= 0);
for (tmp=chain->next; tmp; tmp=tmp->next) {
if (CHAIN_PINNED(tmp))
goto done;
if (tmp->off >= (size_t)remaining)
break;
remaining -= tmp->off;
}
你可以向我解释一下吗?
答案 0 :(得分:0)
在这种情况下固定只意味着evbuffer_chain
目前正在用于阅读或写作。通过查看CHAIN_PINNED
的定义以及EVBUFFER_MEM_PINNED_ANY
,EVBUFFER_MEM_PINNED_W
和'EVBUFFER_MEM_PINNED_R'的定义,您会看到它正在检查evenbuffer_chain的标志,因为它正在用于读取或写入下面:
#define CHAIN_PINNED(ch) (((ch)->flags & EVBUFFER_MEM_PINNED_ANY) != 0)
#define EVBUFFER_MEM_PINNED_R 0x0010
#define EVBUFFER_MEM_PINNED_W 0x0020
#define EVBUFFER_MEM_PINNED_ANY (EVBUFFER_MEM_PINNED_R|EVBUFFER_MEM_PINNED_W)
您可以在here in the source for writing和here in the source for reading等代码中进一步查看这些标记的设置。