Class: Puma::IOBuffer

Inherits:
Object
  • Object
show all
Defined in:
ext/puma_http11/io_buffer.c

Instance Method Summary collapse

Instance Method Details

#<<(str) ⇒ Object


34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# 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) ⇒ Object


69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# 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;
}

#capacityObject


129
130
131
132
133
134
# 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);
}

#resetObject


136
137
138
139
140
141
142
# 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_sObject


115
116
117
118
119
120
# 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_strObject


115
116
117
118
119
120
# 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);
}

#usedObject


122
123
124
125
126
127
# 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);
}