本文整理汇总了C++中IOBuffer::used方法的典型用法代码示例。如果您正苦于以下问题:C++ IOBuffer::used方法的具体用法?C++ IOBuffer::used怎么用?C++ IOBuffer::used使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IOBuffer
的用法示例。
在下文中一共展示了IOBuffer::used方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: test_io_read_into_buffer
void test_io_read_into_buffer() {
int fds[2];
TS_ASSERT(!pipe(fds));
TestChannelObject chan(state);
event::Read* read = new event::Read(state, &chan, fds[0]);
IOBuffer *buf = IOBuffer::create(state, 12);
read->into_buffer(buf, 1);
TS_ASSERT_EQUALS(buf->used(), Fixnum::from(0));
TS_ASSERT_EQUALS(buf->start(), Fixnum::from(0));
state->events->start(read);
TS_ASSERT(!chan.called);
state->events->poll();
TS_ASSERT(!chan.called);
/* Write some garbage into the buffer to be sure it's overridden */
char* str = buf->byte_address();
str[0] = str[1] = 47;
TS_ASSERT_EQUALS(write(fds[1], "!", 1),1);
state->events->poll();
TS_ASSERT(chan.called);
TS_ASSERT_EQUALS(chan.value, Fixnum::from(1));
TS_ASSERT_EQUALS(buf->used(), Fixnum::from(1));
TS_ASSERT_EQUALS(buf->start(), Fixnum::from(0));
TS_ASSERT_EQUALS(str[0], '!');
TS_ASSERT_EQUALS(str[1], 0);
close(fds[0]);
close(fds[1]);
}
示例2: test_create_buffer
void test_create_buffer() {
IOBuffer* buf = IOBuffer::create(state, 10);
Fixnum* zero = Fixnum::from(0);
TS_ASSERT_EQUALS(zero, buf->start());
TS_ASSERT_EQUALS(zero, buf->used());
TS_ASSERT_EQUALS(Fixnum::from(10), buf->total());
TS_ASSERT_EQUALS(10U, buf->left());
TS_ASSERT_EQUALS(cFalse, buf->eof());
}