当我读到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;
}
你能给我解释一下吗?
最佳答案
在本例中,Pinned仅表示evbuffer_chain
当前正用于读取或写入。通过查看CHAIN_PINNED
的定义和EVBUFFER_MEM_PINNED_ANY
、EVBUFFER_MEM_PINNED_W
和'EVBUFFER_MEM_PINNED_R'的定义,您将看到它正在检查evenbuffer_链的标志,以确定它是否正在用于读取或写入,如下所示:
buffer.c:
#define CHAIN_PINNED(ch) (((ch)->flags & EVBUFFER_MEM_PINNED_ANY) != 0)
evbuffer-internal.h:
#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。
关于c - 在这种情况下,“固定”是什么意思?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/34783996/