polyphony 0.86 → 0.87

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b87dae4e2c17055e8206c820a4281774cdf3127195173948c97df4eb09a2bd13
4
- data.tar.gz: 2e7bd958ec7435569423398069223eda41e9c2d89f580627bc22e9054276dd1c
3
+ metadata.gz: 938f929b8373ea094ae045c5acc830f6b848a5018bc5604eab280c740e72f56f
4
+ data.tar.gz: e0806785ca3b5ea6101640b8bbfba9ece96f5c614e13267e07a1f15c33efeb1f
5
5
  SHA512:
6
- metadata.gz: 48f6489939da965463735c83acb4372263eb44b48b5a16da1e704a15e3af971a5d43abd7da5e44f2455b40d880413c6fa8159794e663176c83a11eddebdebc7d
7
- data.tar.gz: 3ada5f9041041e91b6b2a7f31ec609352752317e87c51df090517c9e2b556d9ef69ef8842babd15f25b2257c4226431520ff15df505748cb38bb4a1d5a19063c
6
+ metadata.gz: db4f627ab9fd78899711f8eb12c359e038835ada7d43e494cf0377a2a7f6795746a1e877987f32934e94700cb536c27b58e53d7a5cf77161863a4d26c55abcb5
7
+ data.tar.gz: f7ac358243a16baa8e83923cf46ac7d8ce422a9e0faeea28faa3e0dd523b6b666180fcf1f5182e86c534ced64cfe680895bcdf7bdc9f16e77b641940f439d992
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## 0.87 2022-03-17
2
+
3
+ - Fix compilation on non-Linux OSes
4
+
1
5
  ## 0.86 2022-03-14
2
6
 
3
7
  - Fix gemspec
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- polyphony (0.86)
4
+ polyphony (0.87)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/setup'
4
+ require 'polyphony'
5
+
6
+ require 'polyphony'
7
+
8
+ IO.http1_splice_chunked(STDIN, STDOUT, 16384)
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/setup'
4
+
5
+ require 'polyphony'
6
+ require 'h1p'
7
+
8
+ server = Polyphony::Net.tcp_listen('localhost', 1234,
9
+ reuse_addr: true, reuse_port: true, dont_linger: true
10
+ )
11
+ puts 'Serving HTTP on port 1234'
12
+
13
+ def respond_default(conn)
14
+ conn << "HTTP/1.1 204\r\n\r\n"
15
+ end
16
+
17
+ def respond_splice(conn, path)
18
+ f = File.open(path, 'r') do |f|
19
+ conn << "HTTP/1.1 200\r\nTransfer-Encoding: chunked\r\n\r\n"
20
+ IO.http1_splice_chunked(f, conn, 16384)
21
+ end
22
+ rescue => e
23
+ p e
24
+ # conn << "HTTP/1.1 500\r\nContent-Length: 0\r\n\r\n"
25
+ end
26
+
27
+ def handle_client(conn)
28
+ parser = H1P::Parser.new(conn, :server)
29
+ while true
30
+ headers = parser.parse_headers
31
+ break unless headers
32
+
33
+ case headers[':path']
34
+ when /^\/splice\/(.+)$/
35
+ respond_splice(conn, $1)
36
+ else
37
+ respond_default(conn)
38
+ end
39
+ end
40
+ rescue Errno::ECONNRESET
41
+ # ignore
42
+ end
43
+
44
+ server.accept_loop do |conn|
45
+ handle_client(conn)
46
+ end
@@ -1645,6 +1645,9 @@ void Init_Backend() {
1645
1645
 
1646
1646
  rb_define_method(cBackend, "splice", Backend_splice, 3);
1647
1647
  rb_define_method(cBackend, "splice_to_eof", Backend_splice_to_eof, 3);
1648
+ #ifdef POLYPHONY_LINUX
1649
+ rb_define_method(cBackend, "tee", Backend_tee, 3);
1650
+ #endif
1648
1651
 
1649
1652
  rb_define_method(cBackend, "timeout", Backend_timeout, -1);
1650
1653
  rb_define_method(cBackend, "timer_loop", Backend_timer_loop, 1);
@@ -526,12 +526,44 @@ VALUE IO_inflate(VALUE self, VALUE src, VALUE dest) {
526
526
  return INT2FIX(ctx.out_total);
527
527
  }
528
528
 
529
+ VALUE IO_http1_splice_chunked(VALUE self, VALUE src, VALUE dest, VALUE maxlen) {
530
+ enum write_method method = detect_write_method(dest);
531
+ VALUE backend = BACKEND();
532
+ VALUE pipe = rb_funcall(cPipe, ID_new, 0);
533
+ unsigned char out[128];
534
+ struct raw_buffer buffer = { out, 0 };
535
+
536
+ while (1) {
537
+ int len = FIX2INT(Backend_splice(backend, src, pipe, maxlen));
538
+ if (!len) break;
539
+
540
+ // write chunk header
541
+ buffer.len += sprintf(buffer.ptr + buffer.len, "%x\r\n", len);
542
+ write_from_raw_buffer(backend, dest, method, &buffer);
543
+ buffer.len = 0;
544
+ while (len) {
545
+ int spliced = FIX2INT(Backend_splice(backend, pipe, dest, INT2FIX(len)));
546
+ len -= spliced;
547
+ }
548
+ buffer.len += sprintf(buffer.ptr + buffer.len, "\r\n");
549
+ }
550
+ buffer.len += sprintf(buffer.ptr + buffer.len, "0\r\n\r\n");
551
+ write_from_raw_buffer(backend, dest, method, &buffer);
552
+
553
+ Pipe_close(pipe);
554
+ RB_GC_GUARD(pipe);
555
+
556
+ return self;
557
+ }
558
+
529
559
  void Init_IOExtensions() {
530
560
  rb_define_singleton_method(rb_cIO, "gzip", IO_gzip, -1);
531
561
  rb_define_singleton_method(rb_cIO, "gunzip", IO_gunzip, -1);
532
562
  rb_define_singleton_method(rb_cIO, "deflate", IO_deflate, 2);
533
563
  rb_define_singleton_method(rb_cIO, "inflate", IO_inflate, 2);
534
564
 
565
+ rb_define_singleton_method(rb_cIO, "http1_splice_chunked", IO_http1_splice_chunked, 3);
566
+
535
567
  ID_at = rb_intern("at");
536
568
  ID_read_method = rb_intern("__read_method__");
537
569
  ID_readpartial = rb_intern("readpartial");
@@ -94,9 +94,11 @@ VALUE Polyphony_backend_splice_to_eof(VALUE self, VALUE src, VALUE dest, VALUE c
94
94
  return Backend_splice_to_eof(BACKEND(), src, dest, chunksize);
95
95
  }
96
96
 
97
+ #ifdef POLYPHONY_LINUX
97
98
  VALUE Polyphony_backend_tee(VALUE self, VALUE src, VALUE dest, VALUE chunksize) {
98
99
  return Backend_tee(BACKEND(), src, dest, chunksize);
99
100
  }
101
+ #endif
100
102
 
101
103
  VALUE Polyphony_backend_timeout(int argc,VALUE *argv, VALUE self) {
102
104
  return Backend_timeout(argc, argv, BACKEND());
@@ -190,7 +192,11 @@ void Init_Polyphony() {
190
192
  rb_define_singleton_method(mPolyphony, "backend_sleep", Polyphony_backend_sleep, 1);
191
193
  rb_define_singleton_method(mPolyphony, "backend_splice", Polyphony_backend_splice, 3);
192
194
  rb_define_singleton_method(mPolyphony, "backend_splice_to_eof", Polyphony_backend_splice_to_eof, 3);
195
+
196
+ #ifdef POLYPHONY_LINUX
193
197
  rb_define_singleton_method(mPolyphony, "backend_tee", Polyphony_backend_tee, 3);
198
+ #endif
199
+
194
200
  rb_define_singleton_method(mPolyphony, "backend_timeout", Polyphony_backend_timeout, -1);
195
201
  rb_define_singleton_method(mPolyphony, "backend_timer_loop", Polyphony_backend_timer_loop, 1);
196
202
  rb_define_singleton_method(mPolyphony, "backend_wait_event", Polyphony_backend_wait_event, 1);
@@ -90,6 +90,7 @@ int Runqueue_should_poll_nonblocking(VALUE self);
90
90
 
91
91
  void Pipe_verify_blocking_mode(VALUE self, VALUE blocking);
92
92
  int Pipe_get_fd(VALUE self, int write_mode);
93
+ VALUE Pipe_close(VALUE self);
93
94
 
94
95
  #ifdef POLYPHONY_BACKEND_LIBEV
95
96
  #define Backend_recv_loop Backend_read_loop
@@ -112,7 +113,11 @@ VALUE Backend_sendv(VALUE self, VALUE io, VALUE ary, VALUE flags);
112
113
  VALUE Backend_sleep(VALUE self, VALUE duration);
113
114
  VALUE Backend_splice(VALUE self, VALUE src, VALUE dest, VALUE maxlen);
114
115
  VALUE Backend_splice_to_eof(VALUE self, VALUE src, VALUE dest, VALUE chunksize);
116
+
117
+ #ifdef POLYPHONY_LINUX
115
118
  VALUE Backend_tee(VALUE self, VALUE src, VALUE dest, VALUE maxlen);
119
+ #endif
120
+
116
121
  VALUE Backend_timeout(int argc,VALUE *argv, VALUE self);
117
122
  VALUE Backend_timer_loop(VALUE self, VALUE interval);
118
123
  VALUE Backend_wait_event(VALUE self, VALUE raise);
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Polyphony
4
- VERSION = '0.86'
4
+ VERSION = '0.87'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: polyphony
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.86'
4
+ version: '0.87'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sharon Rosner
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-03-14 00:00:00.000000000 Z
11
+ date: 2022-03-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake-compiler
@@ -262,6 +262,7 @@ files:
262
262
  - examples/io/echo_stdin.rb
263
263
  - examples/io/gzip.rb
264
264
  - examples/io/happy-eyeballs.rb
265
+ - examples/io/http1_splice_chunked.rb
265
266
  - examples/io/httparty.rb
266
267
  - examples/io/https_server.rb
267
268
  - examples/io/irb.rb
@@ -274,6 +275,7 @@ files:
274
275
  - examples/io/reline.rb
275
276
  - examples/io/splice_chunks.rb
276
277
  - examples/io/splice_echo_server.rb
278
+ - examples/io/static_web_server.rb
277
279
  - examples/io/stdio.rb
278
280
  - examples/io/system.rb
279
281
  - examples/io/tcp_proxy.rb