tmm1-em-http-request 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,625 @@
1
+ /*
2
+ * Copyright (C) 2007 Tony Arcieri
3
+ * You may redistribute this under the terms of the Ruby license.
4
+ * See LICENSE for details
5
+ */
6
+
7
+ #include "ruby.h"
8
+ #include "rubyio.h"
9
+
10
+ #include <assert.h>
11
+
12
+ #include <string.h>
13
+ #include <time.h>
14
+ #include <unistd.h>
15
+ #include <errno.h>
16
+
17
+ /* Default number of bytes in each node's buffer */
18
+ #define DEFAULT_NODE_SIZE 16384
19
+
20
+ /* Maximum age of a buffer node in a memory pool, in seconds */
21
+ #define MAX_AGE 60
22
+
23
+ /* How often to scan the pool for old nodes */
24
+ #define PURGE_INTERVAL 10
25
+
26
+ struct buffer {
27
+ time_t last_purged_at;
28
+ unsigned size, node_size;
29
+ struct buffer_node *head, *tail;
30
+ struct buffer_node *pool_head, *pool_tail;
31
+
32
+ };
33
+
34
+ struct buffer_node {
35
+ time_t last_used_at;
36
+ unsigned start, end;
37
+ struct buffer_node *next;
38
+ unsigned char data[0];
39
+ };
40
+
41
+ static VALUE mEm = Qnil;
42
+ static VALUE cEm_Buffer = Qnil;
43
+
44
+ static VALUE Em_Buffer_allocate(VALUE klass);
45
+ static void Em_Buffer_mark(struct buffer *);
46
+ static void Em_Buffer_free(struct buffer *);
47
+
48
+ static VALUE Em_Buffer_initialize(int argc, VALUE *argv, VALUE self);
49
+ static VALUE Em_Buffer_clear(VALUE self);
50
+ static VALUE Em_Buffer_size(VALUE self);
51
+ static VALUE Em_Buffer_empty(VALUE self);
52
+ static VALUE Em_Buffer_append(VALUE self, VALUE data);
53
+ static VALUE Em_Buffer_prepend(VALUE self, VALUE data);
54
+ static VALUE Em_Buffer_read(int argc, VALUE *argv, VALUE self);
55
+ static VALUE Em_Buffer_to_str(VALUE self);
56
+ static VALUE Em_Buffer_read_from(VALUE self, VALUE io);
57
+ static VALUE Em_Buffer_write_to(VALUE self, VALUE io);
58
+
59
+ static struct buffer *buffer_new(void);
60
+ static void buffer_clear(struct buffer *buf);
61
+ static void buffer_free(struct buffer *buf);
62
+ static void buffer_gc(struct buffer *buf);
63
+ static void buffer_prepend(struct buffer *buf, char *str, unsigned len);
64
+ static void buffer_append(struct buffer *buf, char *str, unsigned len);
65
+ static void buffer_read(struct buffer *buf, char *str, unsigned len);
66
+ static void buffer_copy(struct buffer *buf, char *str, unsigned len);
67
+ static int buffer_read_from(struct buffer *buf, int fd);
68
+ static int buffer_write_to(struct buffer *buf, int fd);
69
+
70
+ /*
71
+ * High speed buffering geared towards non-blocking I/O.
72
+ *
73
+ * Data is stored in a byte queue implemented as a linked list of equal size
74
+ * chunks. Since every node in the list is the same size they are easily
75
+ * memory pooled. Routines are provided for high speed non-blocking reads
76
+ * and writes from Ruby IO objects.
77
+ */
78
+ void Init_em_buffer()
79
+ {
80
+ mEm = rb_define_module("EventMachine");
81
+ cEm_Buffer = rb_define_class_under(mEm, "Buffer", rb_cObject);
82
+ rb_define_alloc_func(cEm_Buffer, Em_Buffer_allocate);
83
+
84
+ rb_define_method(cEm_Buffer, "initialize", Em_Buffer_initialize, -1);
85
+ rb_define_method(cEm_Buffer, "clear", Em_Buffer_clear, 0);
86
+ rb_define_method(cEm_Buffer, "size", Em_Buffer_size, 0);
87
+ rb_define_method(cEm_Buffer, "empty?", Em_Buffer_empty, 0);
88
+ rb_define_method(cEm_Buffer, "<<", Em_Buffer_append, 1);
89
+ rb_define_method(cEm_Buffer, "append", Em_Buffer_append, 1);
90
+ rb_define_method(cEm_Buffer, "prepend", Em_Buffer_prepend, 1);
91
+ rb_define_method(cEm_Buffer, "read", Em_Buffer_read, -1);
92
+ rb_define_method(cEm_Buffer, "to_str", Em_Buffer_to_str, 0);
93
+ rb_define_method(cEm_Buffer, "read_from", Em_Buffer_read_from, 1);
94
+ rb_define_method(cEm_Buffer, "write_to", Em_Buffer_write_to, 1);
95
+ }
96
+
97
+ static VALUE Em_Buffer_allocate(VALUE klass)
98
+ {
99
+ return Data_Wrap_Struct(klass, Em_Buffer_mark, Em_Buffer_free, buffer_new());
100
+ }
101
+
102
+ static void Em_Buffer_mark(struct buffer *buf)
103
+ {
104
+ /* Walks the pool of unused chunks and frees any that are beyond a certain age */
105
+ buffer_gc(buf);
106
+ }
107
+
108
+ static void Em_Buffer_free(struct buffer *buf)
109
+ {
110
+ buffer_free(buf);
111
+ }
112
+
113
+ /**
114
+ * call-seq:
115
+ * EventMachine::Buffer.new(size = DEFAULT_NODE_SIZE) -> EventMachine::Buffer
116
+ *
117
+ * Create a new EventMachine::Buffer with linked segments of the given size
118
+ */
119
+ static VALUE Em_Buffer_initialize(int argc, VALUE *argv, VALUE self)
120
+ {
121
+ VALUE node_size_obj;
122
+ int node_size;
123
+ struct buffer *buf;
124
+
125
+ if(rb_scan_args(argc, argv, "01", &node_size_obj) == 1) {
126
+ node_size = NUM2INT(node_size_obj);
127
+
128
+ if(node_size < 1) rb_raise(rb_eArgError, "invalid buffer size");
129
+
130
+ Data_Get_Struct(self, struct buffer, buf);
131
+
132
+ /* Make sure we're not changing the buffer size after data has been allocated */
133
+ assert(!buf->head);
134
+ assert(!buf->pool_head);
135
+
136
+ buf->node_size = node_size;
137
+ }
138
+
139
+ return Qnil;
140
+ }
141
+
142
+ /**
143
+ * call-seq:
144
+ * EventMachine::Buffer#clear -> nil
145
+ *
146
+ * Clear all data from the EventMachine::Buffer
147
+ */
148
+ static VALUE Em_Buffer_clear(VALUE self)
149
+ {
150
+ struct buffer *buf;
151
+ Data_Get_Struct(self, struct buffer, buf);
152
+
153
+ buffer_clear(buf);
154
+
155
+ return Qnil;
156
+ }
157
+
158
+ /**
159
+ * call-seq:
160
+ * EventMachine::Buffer#size -> Integer
161
+ *
162
+ * Return the size of the buffer in bytes
163
+ */
164
+ static VALUE Em_Buffer_size(VALUE self)
165
+ {
166
+ struct buffer *buf;
167
+ Data_Get_Struct(self, struct buffer, buf);
168
+
169
+ return INT2NUM(buf->size);
170
+ }
171
+
172
+ /**
173
+ * call-seq:
174
+ * EventMachine::Buffer#empty? -> Boolean
175
+ *
176
+ * Is the buffer empty?
177
+ */
178
+ static VALUE Em_Buffer_empty(VALUE self)
179
+ {
180
+ struct buffer *buf;
181
+ Data_Get_Struct(self, struct buffer, buf);
182
+
183
+ return buf->size > 0 ? Qfalse : Qtrue;
184
+ }
185
+
186
+ /**
187
+ * call-seq:
188
+ * EventMachine::Buffer#append(data) -> String
189
+ *
190
+ * Append the given data to the end of the buffer
191
+ */
192
+ static VALUE Em_Buffer_append(VALUE self, VALUE data)
193
+ {
194
+ struct buffer *buf;
195
+ Data_Get_Struct(self, struct buffer, buf);
196
+
197
+ /* Is this needed? Never seen anyone else do it... */
198
+ data = rb_convert_type(data, T_STRING, "String", "to_str");
199
+ buffer_append(buf, RSTRING_PTR(data), RSTRING_LEN(data));
200
+
201
+ return data;
202
+ }
203
+
204
+ /**
205
+ * call-seq:
206
+ * EventMachine::Buffer#prepend(data) -> String
207
+ *
208
+ * Prepend the given data to the beginning of the buffer
209
+ */
210
+ static VALUE Em_Buffer_prepend(VALUE self, VALUE data)
211
+ {
212
+ struct buffer *buf;
213
+ Data_Get_Struct(self, struct buffer, buf);
214
+
215
+ data = rb_convert_type(data, T_STRING, "String", "to_str");
216
+ buffer_prepend(buf, RSTRING_PTR(data), RSTRING_LEN(data));
217
+
218
+ return data;
219
+ }
220
+
221
+ /**
222
+ * call-seq:
223
+ * EventMachine::Buffer#read(length = nil) -> String
224
+ *
225
+ * Read the specified abount of data from the buffer. If no value
226
+ * is given the entire contents of the buffer are returned. Any data
227
+ * read from the buffer is cleared.
228
+ */
229
+ static VALUE Em_Buffer_read(int argc, VALUE *argv, VALUE self)
230
+ {
231
+ VALUE length_obj, str;
232
+ int length;
233
+ struct buffer *buf;
234
+
235
+ Data_Get_Struct(self, struct buffer, buf);
236
+
237
+ if(rb_scan_args(argc, argv, "01", &length_obj) == 1) {
238
+ length = NUM2INT(length_obj);
239
+ } else {
240
+ if(buf->size == 0)
241
+ return rb_str_new2("");
242
+
243
+ length = buf->size;
244
+ }
245
+
246
+ if(length > buf->size)
247
+ length = buf->size;
248
+
249
+ if(length < 1)
250
+ rb_raise(rb_eArgError, "length must be greater than zero");
251
+
252
+ str = rb_str_new(0, length);
253
+ buffer_read(buf, RSTRING_PTR(str), length);
254
+
255
+ return str;
256
+ }
257
+
258
+ /**
259
+ * call-seq:
260
+ * EventMachine::Buffer#to_str -> String
261
+ *
262
+ * Convert the Buffer to a String. The original buffer is unmodified.
263
+ */
264
+ static VALUE Em_Buffer_to_str(VALUE self) {
265
+ VALUE str;
266
+ struct buffer *buf;
267
+
268
+ Data_Get_Struct(self, struct buffer, buf);
269
+
270
+ str = rb_str_new(0, buf->size);
271
+ buffer_copy(buf, RSTRING_PTR(str), buf->size);
272
+
273
+ return str;
274
+ }
275
+
276
+ /**
277
+ * call-seq:
278
+ * EventMachine::Buffer#read_from(io) -> Integer
279
+ *
280
+ * Perform a nonblocking read of the the given IO object and fill
281
+ * the buffer with any data received. The call will read as much
282
+ * data as it can until the read would block.
283
+ */
284
+ static VALUE Em_Buffer_read_from(VALUE self, VALUE io) {
285
+ struct buffer *buf;
286
+ #if HAVE_RB_IO_T
287
+ rb_io_t *fptr;
288
+ #else
289
+ OpenFile *fptr;
290
+ #endif
291
+
292
+ Data_Get_Struct(self, struct buffer, buf);
293
+ GetOpenFile(rb_convert_type(io, T_FILE, "IO", "to_io"), fptr);
294
+ rb_io_set_nonblock(fptr);
295
+
296
+ return INT2NUM(buffer_read_from(buf, FPTR_TO_FD(fptr)));
297
+ }
298
+
299
+ /**
300
+ * call-seq:
301
+ * EventMachine::Buffer#write_to(io) -> Integer
302
+ *
303
+ * Perform a nonblocking write of the buffer to the given IO object.
304
+ * As much data as possible is written until the call would block.
305
+ * Any data which is written is removed from the buffer.
306
+ */
307
+ static VALUE Em_Buffer_write_to(VALUE self, VALUE io) {
308
+ struct buffer *buf;
309
+ #if HAVE_RB_IO_T
310
+ rb_io_t *fptr;
311
+ #else
312
+ OpenFile *fptr;
313
+ #endif
314
+
315
+ Data_Get_Struct(self, struct buffer, buf);
316
+ GetOpenFile(rb_convert_type(io, T_FILE, "IO", "to_io"), fptr);
317
+ rb_io_set_nonblock(fptr);
318
+
319
+ return INT2NUM(buffer_write_to(buf, FPTR_TO_FD(fptr)));
320
+ }
321
+
322
+ /*
323
+ * Ruby bindings end here. Below is the actual implementation of
324
+ * the underlying data structures.
325
+ */
326
+
327
+ /* Create a new buffer */
328
+ static struct buffer *buffer_new(void)
329
+ {
330
+ struct buffer *buf;
331
+
332
+ buf = (struct buffer *)xmalloc(sizeof(struct buffer));
333
+ buf->head = buf->tail = buf->pool_head = buf->pool_tail = 0;
334
+ buf->size = 0;
335
+ buf->node_size = DEFAULT_NODE_SIZE;
336
+ time(&buf->last_purged_at);
337
+
338
+ return buf;
339
+ }
340
+
341
+ /* Clear all data from a buffer */
342
+ static void buffer_clear(struct buffer *buf)
343
+ {
344
+ struct buffer_node *tmp;
345
+
346
+ /* Move everything into the buffer pool */
347
+ if(!buf->pool_tail)
348
+ buf->pool_head = buf->pool_tail = buf->head;
349
+ else
350
+ buf->pool_tail->next = buf->head;
351
+
352
+ buf->head = buf->tail = 0;
353
+ buf->size = 0;
354
+ }
355
+
356
+ /* Free a buffer */
357
+ static void buffer_free(struct buffer *buf)
358
+ {
359
+ struct buffer_node *tmp;
360
+
361
+ buffer_clear(buf);
362
+
363
+ while(buf->pool_head) {
364
+ tmp = buf->pool_head;
365
+ buf->pool_head = tmp->next;
366
+ free(tmp);
367
+ }
368
+
369
+ free(buf);
370
+ }
371
+
372
+ /* Run through the pool and find elements that haven't been used for awhile */
373
+ static void buffer_gc(struct buffer *buf)
374
+ {
375
+ struct buffer_node *cur, *tmp;
376
+ time_t now;
377
+ time(&now);
378
+
379
+ /* Only purge if we've passed the purge interval */
380
+ if(now - buf->last_purged_at < PURGE_INTERVAL)
381
+ return;
382
+
383
+ buf->last_purged_at = now;
384
+
385
+ while(buf->pool_head && now - buf->pool_head->last_used_at >= MAX_AGE) {
386
+ tmp = buf->pool_head;
387
+ buf->pool_head = buf->pool_head->next;
388
+ free(tmp);
389
+ }
390
+
391
+ if(!buf->pool_head)
392
+ buf->pool_tail = 0;
393
+ }
394
+
395
+ /* Create a new buffer_node (or pull one from the memory pool) */
396
+ static struct buffer_node *buffer_node_new(struct buffer *buf)
397
+ {
398
+ struct buffer_node *node;
399
+
400
+ /* Pull from the memory pool if available */
401
+ if(buf->pool_head) {
402
+ node = buf->pool_head;
403
+ buf->pool_head = node->next;
404
+
405
+ if(node->next)
406
+ node->next = 0;
407
+ else
408
+ buf->pool_tail = 0;
409
+ } else {
410
+ node = (struct buffer_node *)xmalloc(sizeof(struct buffer_node) + buf->node_size);
411
+ node->next = 0;
412
+ }
413
+
414
+ node->start = node->end = 0;
415
+ return node;
416
+ }
417
+
418
+ /* Free a buffer node (i.e. return it to the memory pool) */
419
+ static void buffer_node_free(struct buffer *buf, struct buffer_node *node)
420
+ {
421
+ /* Store when the node was freed */
422
+ time(&node->last_used_at);
423
+
424
+ node->next = buf->pool_head;
425
+ buf->pool_head = node;
426
+
427
+ if(!buf->pool_tail)
428
+ buf->pool_tail = node;
429
+ }
430
+
431
+ /* Prepend data to the front of the buffer */
432
+ static void buffer_prepend(struct buffer *buf, char *str, unsigned len)
433
+ {
434
+ struct buffer_node *node, *tmp;
435
+ buf->size += len;
436
+
437
+ /* If it fits in the beginning of the head */
438
+ if(buf->head && buf->head->start >= len) {
439
+ buf->head->start -= len;
440
+ memcpy(buf->head->data + buf->head->start, str, len);
441
+ } else {
442
+ node = buffer_node_new(buf);
443
+ node->next = buf->head;
444
+ buf->head = node;
445
+ if(!buf->tail) buf->tail = node;
446
+
447
+ while(len > buf->node_size) {
448
+ memcpy(node->data, str, buf->node_size);
449
+ node->end = buf->node_size;
450
+
451
+ tmp = buffer_node_new(buf);
452
+ tmp->next = node->next;
453
+ node->next = tmp;
454
+
455
+ if(buf->tail == node) buf->tail = tmp;
456
+ node = tmp;
457
+
458
+ str += buf->node_size;
459
+ len -= buf->node_size;
460
+ }
461
+
462
+ if(len > 0) {
463
+ memcpy(node->data, str, len);
464
+ node->end = len;
465
+ }
466
+ }
467
+ }
468
+
469
+ /* Append data to the front of the buffer */
470
+ static void buffer_append(struct buffer *buf, char *str, unsigned len)
471
+ {
472
+ unsigned nbytes;
473
+ buf->size += len;
474
+
475
+ /* If it fits in the remaining space in the tail */
476
+ if(buf->tail && len <= buf->node_size - buf->tail->end) {
477
+ memcpy(buf->tail->data + buf->tail->end, str, len);
478
+ buf->tail->end += len;
479
+ return;
480
+ }
481
+
482
+ /* Empty list needs initialized */
483
+ if(!buf->head) {
484
+ buf->head = buffer_node_new(buf);
485
+ buf->tail = buf->head;
486
+ }
487
+
488
+ /* Build links out of the data */
489
+ while(len > 0) {
490
+ nbytes = buf->node_size - buf->tail->end;
491
+ if(len < nbytes) nbytes = len;
492
+
493
+ memcpy(buf->tail->data + buf->tail->end, str, nbytes);
494
+ str += nbytes;
495
+ len -= nbytes;
496
+
497
+ buf->tail->end += nbytes;
498
+
499
+ if(len > 0) {
500
+ buf->tail->next = buffer_node_new(buf);
501
+ buf->tail = buf->tail->next;
502
+ }
503
+ }
504
+ }
505
+
506
+ /* Read data from the buffer (and clear what we've read) */
507
+ static void buffer_read(struct buffer *buf, char *str, unsigned len)
508
+ {
509
+ unsigned nbytes;
510
+ struct buffer_node *tmp;
511
+
512
+ while(buf->size > 0 && len > 0) {
513
+ nbytes = buf->head->end - buf->head->start;
514
+ if(len < nbytes) nbytes = len;
515
+
516
+ memcpy(str, buf->head->data + buf->head->start, nbytes);
517
+ str += nbytes;
518
+ len -= nbytes;
519
+
520
+ buf->head->start += nbytes;
521
+ buf->size -= nbytes;
522
+
523
+ if(buf->head->start == buf->head->end) {
524
+ tmp = buf->head;
525
+ buf->head = tmp->next;
526
+ buffer_node_free(buf, tmp);
527
+
528
+ if(!buf->head) buf->tail = 0;
529
+ }
530
+ }
531
+ }
532
+
533
+ /* Copy data from the buffer without clearing it */
534
+ static void buffer_copy(struct buffer *buf, char *str, unsigned len)
535
+ {
536
+ unsigned nbytes;
537
+ struct buffer_node *node;
538
+
539
+ node = buf->head;
540
+ while(node && len > 0) {
541
+ nbytes = node->end - node->start;
542
+ if(len < nbytes) nbytes = len;
543
+
544
+ memcpy(str, node->data + node->start, nbytes);
545
+ str += nbytes;
546
+ len -= nbytes;
547
+
548
+ if(node->start + nbytes == node->end)
549
+ node = node->next;
550
+ }
551
+ }
552
+
553
+ /* Write data from the buffer to a file descriptor */
554
+ static int buffer_write_to(struct buffer *buf, int fd)
555
+ {
556
+ int bytes_written, total_bytes_written = 0;
557
+ struct buffer_node *tmp;
558
+
559
+ while(buf->head) {
560
+ bytes_written = write(fd, buf->head->data + buf->head->start, buf->head->end - buf->head->start);
561
+
562
+ /* If the write failed... */
563
+ if(bytes_written < 0) {
564
+ if(errno != EAGAIN)
565
+ rb_sys_fail("write");
566
+
567
+ return total_bytes_written;
568
+ }
569
+
570
+ total_bytes_written += bytes_written;
571
+ buf->size -= bytes_written;
572
+
573
+ /* If the write blocked... */
574
+ if(bytes_written < buf->head->end - buf->head->start) {
575
+ buf->head->start += bytes_written;
576
+ return total_bytes_written;
577
+ }
578
+
579
+ /* Otherwise we wrote the whole buffer */
580
+ tmp = buf->head;
581
+ buf->head = tmp->next;
582
+ buffer_node_free(buf, tmp);
583
+
584
+ if(!buf->head) buf->tail = 0;
585
+ }
586
+
587
+ return total_bytes_written;
588
+ }
589
+
590
+ /* Read data from a file descriptor to a buffer */
591
+ /* Append data to the front of the buffer */
592
+ static int buffer_read_from(struct buffer *buf, int fd)
593
+ {
594
+ int bytes_read, total_bytes_read = 0;
595
+ unsigned nbytes;
596
+
597
+ /* Empty list needs initialized */
598
+ if(!buf->head) {
599
+ buf->head = buffer_node_new(buf);
600
+ buf->tail = buf->head;
601
+ }
602
+
603
+ do {
604
+ nbytes = buf->node_size - buf->tail->end;
605
+ bytes_read = read(fd, buf->tail->data + buf->tail->end, nbytes);
606
+
607
+ if(bytes_read < 1) {
608
+ if(errno != EAGAIN)
609
+ rb_sys_fail("read");
610
+
611
+ return total_bytes_read;
612
+ }
613
+
614
+ total_bytes_read += bytes_read;
615
+ buf->tail->end += nbytes;
616
+ buf->size += nbytes;
617
+
618
+ if(buf->tail->end == buf->node_size) {
619
+ buf->tail->next = buffer_node_new(buf);
620
+ buf->tail = buf->tail->next;
621
+ }
622
+ } while(bytes_read == nbytes);
623
+
624
+ return total_bytes_read;
625
+ }
@@ -0,0 +1,53 @@
1
+ require 'mkmf'
2
+
3
+ libs = []
4
+
5
+ $defs << "-DRUBY_VERSION_CODE=#{RUBY_VERSION.gsub(/\D/, '')}"
6
+
7
+ if have_func('rb_thread_blocking_region')
8
+ $defs << '-DHAVE_RB_THREAD_BLOCKING_REGION'
9
+ end
10
+
11
+ if have_func('rb_str_set_len')
12
+ $defs << '-DHAVE_RB_STR_SET_LEN'
13
+ end
14
+
15
+ if have_header('sys/select.h')
16
+ $defs << '-DEV_USE_SELECT'
17
+ end
18
+
19
+ if have_header('poll.h')
20
+ $defs << '-DEV_USE_POLL'
21
+ end
22
+
23
+ if have_header('sys/epoll.h')
24
+ $defs << '-DEV_USE_EPOLL'
25
+ end
26
+
27
+ if have_header('sys/event.h') and have_header('sys/queue.h')
28
+ $defs << '-DEV_USE_KQUEUE'
29
+ end
30
+
31
+ if have_header('port.h')
32
+ $defs << '-DEV_USE_PORT'
33
+ end
34
+
35
+ if have_header('openssl/ssl.h')
36
+ $defs << '-DHAVE_OPENSSL_SSL_H'
37
+ libs << '-lssl -lcrypto'
38
+ end
39
+
40
+ # ncpu detection specifics
41
+ case RUBY_PLATFORM
42
+ when /linux/
43
+ $defs << '-DHAVE_LINUX_PROCFS'
44
+ else
45
+ if have_func('sysctlbyname', ['sys/param.h', 'sys/sysctl.h'])
46
+ $defs << '-DHAVE_SYSCTLBYNAME'
47
+ end
48
+ end
49
+
50
+ $LIBS << ' ' << libs.join(' ')
51
+
52
+ dir_config('em_buffer')
53
+ create_makefile('em_buffer')
@@ -0,0 +1,14 @@
1
+ #ifndef ext_help_h
2
+ #define ext_help_h
3
+
4
+ #define RAISE_NOT_NULL(T) if(T == NULL) rb_raise(rb_eArgError, "NULL found for " # T " when shouldn't be.");
5
+ #define DATA_GET(from,type,name) Data_Get_Struct(from,type,name); RAISE_NOT_NULL(name);
6
+ #define REQUIRE_TYPE(V, T) if(TYPE(V) != T) rb_raise(rb_eTypeError, "Wrong argument type for " # V " required " # T);
7
+
8
+ #ifdef DEBUG
9
+ #define TRACE() fprintf(stderr, "> %s:%d:%s\n", __FILE__, __LINE__, __FUNCTION__)
10
+ #else
11
+ #define TRACE()
12
+ #endif
13
+
14
+ #endif
@@ -0,0 +1,6 @@
1
+ require 'mkmf'
2
+
3
+ dir_config("http11_client")
4
+ have_library("c", "main")
5
+
6
+ create_makefile("http11_client")