Class: Puma::IOBuffer
| Relationships & Source Files | |
| Inherits: | Object |
| Defined in: | ext/puma_http11/io_buffer.c |
Instance Method Summary
Instance Method Details
#<<(str)
[ GitHub ]# File 'ext/puma_http11/io_buffer.c', line 34
static VALUE buf_append(VALUE self, VALUE str) {
struct buf_int* b;
size_t used, str_len, new_size;
Data_Get_Struct(self, struct buf_int, b);
used = b->cur - b->top;
StringValue(str);
str_len = RSTRING_LEN(str);
new_size = used + str_len;
if(new_size > b->size) {
size_t n = b->size + (b->size / 2);
uint8_t* top;
uint8_t* old;
new_size = (n > new_size ? n : new_size + BUF_TOLERANCE);
top = ALLOC_N(uint8_t, new_size);
old = b->top;
memcpy(top, old, used);
b->top = top;
b->cur = top + used;
b->size = new_size;
xfree(old);
}
memcpy(b->cur, RSTRING_PTR(str), str_len);
b->cur += str_len;
return self;
}
#append(*args)
[ GitHub ]# File 'ext/puma_http11/io_buffer.c', line 69
static VALUE buf_append2(int argc, VALUE* argv, VALUE self) {
struct buf_int* b;
size_t used, new_size;
int i;
VALUE str;
Data_Get_Struct(self, struct buf_int, b);
used = b->cur - b->top;
new_size = used;
for(i = 0; i < argc; i++) {
StringValue(argv[i]);
str = argv[i];
new_size += RSTRING_LEN(str);
}
if(new_size > b->size) {
size_t n = b->size + (b->size / 2);
uint8_t* top;
uint8_t* old;
new_size = (n > new_size ? n : new_size + BUF_TOLERANCE);
top = ALLOC_N(uint8_t, new_size);
old = b->top;
memcpy(top, old, used);
b->top = top;
b->cur = top + used;
b->size = new_size;
xfree(old);
}
for(i = 0; i < argc; i++) {
long str_len;
str = argv[i];
str_len = RSTRING_LEN(str);
memcpy(b->cur, RSTRING_PTR(str), str_len);
b->cur += str_len;
}
return self;
}
#capacity
[ GitHub ]# File 'ext/puma_http11/io_buffer.c', line 129
static VALUE buf_capa(VALUE self) {
struct buf_int* b;
Data_Get_Struct(self, struct buf_int, b);
return INT2FIX(b->size);
}
#reset
[ GitHub ]# File 'ext/puma_http11/io_buffer.c', line 136
static VALUE buf_reset(VALUE self) {
struct buf_int* b;
Data_Get_Struct(self, struct buf_int, b);
b->cur = b->top;
return self;
}
#to_s Also known as: #to_str
[ GitHub ]# File 'ext/puma_http11/io_buffer.c', line 115
static VALUE buf_to_str(VALUE self) {
struct buf_int* b;
Data_Get_Struct(self, struct buf_int, b);
return rb_str_new((const char*)(b->top), b->cur - b->top);
}
#to_str
Alias for #to_s.
#used
[ GitHub ]# File 'ext/puma_http11/io_buffer.c', line 122
static VALUE buf_used(VALUE self) {
struct buf_int* b;
Data_Get_Struct(self, struct buf_int, b);
return INT2FIX(b->cur - b->top);
}