spinel-spinner 0.1.0.pre.1 → 0.1.0.pre.4

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 192df4472958ec515d42c017b8aae2423e10a3ada0e2fc81a665d8a517b47246
4
- data.tar.gz: 471ef455c84ff680da6f725d2ac78664fc22b147f65259e32cd1924b4aefd8dc
3
+ metadata.gz: 6f8c7c3a35455ba43dc00f13c624c70cec966c6be71868cce9b8fa8c632e8a7f
4
+ data.tar.gz: 6f3e4f5a7a2230aa798d5dc07a6ca75c021784c6ff18b069325721540899f613
5
5
  SHA512:
6
- metadata.gz: c1abf1727775dec5fde5f46b967b895e0d1d246d62a746bd6d628b96962ad84ce06dd414df21471b1cc618e8eb6957c7d3a9813a74054af87fecb3dff63bbcf0
7
- data.tar.gz: 225b0564014e7a341506c71db3d66c8f753fee28558fccb01dd19af4c54890b1becd6946e08a0aae0ffca177bd4d83931e477eb32f98c77ae0f3e50ada11afd3
6
+ metadata.gz: e62d7591ac5bc0548bcc9a1feae8106c1bb347bbc6ade4be707477bfae0ff30ed95238f2d8cba0f9d12e256715ed23c3e79c771f2f994c3a9c74a7666dbe3920
7
+ data.tar.gz: 115b2c8a2e6cd69344c1ea49b341040fa063f872075ac019feadba491557f03b549f6a57683121e67403a014b3c7d604f3d609181acd682c617fe1518b7f526b
data/CHANGELOG.md CHANGED
@@ -1,5 +1,20 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.1.0.pre.4] - 2026-11-01
4
+
5
+ - Preserve embedded NULs and all byte values across buffered, streaming, and
6
+ WebSocket socket writes, including boxed application dispatch under Spinel
7
+ `10f112c51`. Normalize at the native write boundary and close each short-lived
8
+ duplicated IO handle in ensure. This adds one descriptor duplication/close per
9
+ plain native write; CRuby retains its ordinary socket path. TLS pending buffers,
10
+ retry rules, locks, and the separate transport deadlines are preserved.
11
+
12
+ - Avoid applying TCP_NODELAY to Unix listeners when the compiler reports a TCP
13
+ peer family for their accepted sockets.
14
+ - Wake the reactor when workers return reusable connections or free connection
15
+ capacity, removing the dependency on the 50 ms housekeeping poll.
16
+ - Disable Nagle's algorithm on accepted TCP sockets to reduce delays between
17
+ separate response header and body writes.
3
18
  - Rename the distribution to `spinel-spinner` while retaining `require "spinner"`
4
19
  and the `Spinner` namespace.
5
20
 
data/README.md CHANGED
@@ -136,7 +136,7 @@ installed library path. Spinel is a separate compiler prerequisite:
136
136
 
137
137
  ```sh
138
138
  gem build spinel-spinner.gemspec
139
- gem install --local spinel-spinner-0.1.0.pre.1.gem
139
+ gem install --local spinel-spinner-0.1.0.pre.4.gem
140
140
  spinel app.rb --require-gate -I "$(ruby -e 'puts Gem::Specification.find_by_name("spinel-spinner").full_gem_path')/lib" -o app
141
141
  ```
142
142
 
@@ -162,3 +162,20 @@ compiler, OpenSSL, and Nginx on `PATH`. `KEEP_SPINNER_TEST_ARTIFACTS=1` retains
162
162
  build and process artifacts; failed startup/process logs are retained
163
163
  automatically. See
164
164
  [test/COVERAGE.md](test/COVERAGE.md) for evidence and remaining release gates.
165
+
166
+ ### Binary transport and the pinned compiler
167
+
168
+ Spinner `0.1.0.pre.4` preserves binary bodies for buffered responses, enumerable
169
+ streams, and WebSockets. Spinel `10f112c51666e7ffd308e0ab90a69c2184870c06`
170
+ can emit null-terminated native writes when socket or string arguments become
171
+ boxed during whole-program compilation. Spinner normalizes a typed binary
172
+ String immediately before writing through a typed `IO.for_fd` handle.
173
+
174
+ In that compiler, `IO.for_fd(fd, "wb", autoclose: false)` owns a duplicated
175
+ file descriptor. Each plain native write attempt duplicates and closes a handle,
176
+ including partial writes and exceptions; it never caches handles across socket
177
+ reuse. This costs a descriptor duplication and close per attempt. CRuby keeps
178
+ its ordinary socket write path because explicitly closing its non-owning handle
179
+ would close the original descriptor. TLS continues to use its pending FFI buffer
180
+ and retry checks under the same mutex. Buffered/activity and stream deadlines
181
+ remain separate in Transport. File serving and authorization belong to the app.
@@ -15,8 +15,15 @@ module Spinner
15
15
  @storage_status = 503
16
16
  @storage = nil
17
17
  @close_lock = Mutex.new
18
- @peer = socket.respond_to?(:peeraddr) ? socket.peeraddr[3] : ""
18
+ peer = socket.respond_to?(:peeraddr) ? socket.peeraddr : nil
19
+ @peer = peer.nil? ? "" : peer[3]
19
20
  @peer = "" if @peer.nil?
21
+ # Spinel can label an accepted Unix socket as AF_INET. A unix_path
22
+ # listener explicitly supplies port "0"; never set TCP options on it.
23
+ if port != "0" && !peer.nil? && (peer[0] == "AF_INET" || peer[0] == "AF_INET6")
24
+ # Separate small header and body writes can stall behind delayed ACKs.
25
+ socket.setsockopt(Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1)
26
+ end
20
27
  @socket = TLS::Socket.new(socket, tls_context)
21
28
  @port = port
22
29
  @scheme = tls_context.nil? ? "http" : "https"
@@ -111,11 +118,13 @@ module Spinner
111
118
  def queued!
112
119
  @state = :queued
113
120
  @queued_at = Transport.now
121
+ @trace[:queued] = @queued_at if @trace
114
122
  @deadline = @queued_at + @queue_timeout
115
123
  end
116
124
 
117
125
  def claim!
118
126
  @state = :worker
127
+ @trace[:worker_start] = Transport.now if @trace
119
128
  @queue_wait_ms = ((Transport.now - @queued_at) * 1000).round
120
129
  end
121
130
 
@@ -147,7 +156,10 @@ module Spinner
147
156
  elsif !@storage_error.nil?
148
157
  reject(@storage_status)
149
158
  else
150
- @state = :ready if @body_complete
159
+ if @body_complete
160
+ @state = :ready
161
+ @trace[:ready] = Transport.now if @trace
162
+ end
151
163
  finish_continue
152
164
  end
153
165
  end
@@ -155,7 +167,10 @@ module Spinner
155
167
  def store_chunk(chunk)
156
168
  if @body_size + chunk.bytesize <= @options[:body_memory_bytes] && @chunk_decoder.nil?
157
169
  append_body(chunk)
158
- @state = :ready if @body_complete
170
+ if @body_complete
171
+ @state = :ready
172
+ @trace[:ready] = Transport.now if @trace
173
+ end
159
174
  finish_continue
160
175
  return
161
176
  end
@@ -206,6 +221,8 @@ module Spinner
206
221
 
207
222
  def next_request!
208
223
  @requests_served += 1
224
+ @trace = nil
225
+ @trace_id = nil
209
226
  bytes = @remainder
210
227
  @remainder = "".b
211
228
  cleanup_body
@@ -245,6 +262,12 @@ module Spinner
245
262
  end
246
263
  if @state == :headers
247
264
  if @parser.feed(chunk)
265
+ trace_id = @parser.headers["x-spinner-trace"]
266
+ unless trace_id.nil? || trace_id.empty? || trace_id.bytesize > 200 || trace_id.match?(/[^a-zA-Z0-9_.-]/)
267
+ @trace_id = trace_id
268
+ @request_sequence = @requests_served + 1
269
+ @trace = {}
270
+ end
248
271
  @state = :body
249
272
  @body_deadline = Transport.now + @body_timeout
250
273
  @deadline = @body_deadline
@@ -316,6 +339,7 @@ module Spinner
316
339
  @wait_direction = :read
317
340
  @deadline = @body_deadline
318
341
  else
342
+ @trace[:response_write_done] = Transport.now if @trace
319
343
  close
320
344
  end
321
345
  rescue IO::WaitWritable
@@ -352,6 +376,8 @@ module Spinner
352
376
  end
353
377
  end
354
378
 
379
+ attr_reader :trace, :trace_id, :request_sequence
380
+
355
381
  end
356
382
 
357
383
  class Reactor
@@ -388,8 +414,15 @@ module Spinner
388
414
  @reserve_fd = File.open("/dev/null", "r")
389
415
  @reserve_reopen_count = nil
390
416
  @last_heartbeat = Transport.now
417
+ @wakeup = ReactorWakeup.new
391
418
  @pool = ThreadPool.new(application, threads, queue_capacity, header_limit,
392
- read_timeout, write_timeout, body_timeout, port, @capacity, @options)
419
+ read_timeout, write_timeout, body_timeout, port, @capacity, @options, @wakeup)
420
+ rescue Exception # rubocop:disable Lint/RescueException -- clean up after interrupted or failed pool startup
421
+ # ThreadPool stops any partially started workers before its constructor
422
+ # raises. Storage workers are lazy and cannot have started here yet.
423
+ @wakeup.close unless @wakeup.nil?
424
+ @reserve_fd.close unless @reserve_fd.nil? || @reserve_fd.closed?
425
+ raise
393
426
  end
394
427
 
395
428
  def shutdown!(graceful = false)
@@ -400,6 +433,10 @@ module Spinner
400
433
 
401
434
  def run
402
435
  loop do
436
+ # Drain BEFORE inspecting completions/capacity. A later publication
437
+ # leaves a readable token for select, including when the pipe was full.
438
+ # Draining after the final state check could lose that wakeup.
439
+ @wakeup.drain
403
440
  now = Transport.now
404
441
  if @reactor_heartbeat && now - @last_heartbeat >= 1.0
405
442
  warn "SPINNER_METRIC event=reactor pid=#{Process.pid} connections=#{@capacity.count} clients=#{@clients.length} queued=#{@queued.length} app_active=#{@pool.active_count}"
@@ -459,6 +496,22 @@ module Spinner
459
496
  @pool.maintain(@application, @header_limit, @read_timeout,
460
497
  @write_timeout, @body_timeout, @port) unless @draining
461
498
  @pool.completed.each do |client|
499
+ if client.trace
500
+ client.trace[:reactor_collection] = Transport.now
501
+ trace = client.trace
502
+ total_ms = (trace[:reactor_collection] - trace[:ready]) * 1000.0
503
+ if total_ms > 5.0
504
+ ms = ->(from, to) { (trace[to] && trace[from] ? (trace[to] - trace[from]) * 1000.0 : nil) }
505
+ line = "SPINNER_TRACE trace_id=#{client.trace_id} connection_id=#{client.id} request_sequence=#{client.request_sequence} pid=#{Process.pid} total_ms=#{format('%.3f', total_ms)} ready_to_queue_ms=#{format('%.3f', ms.call(:ready, :queued) || 0)} queue_ms=#{format('%.3f', ms.call(:queued, :worker_start) || 0)} worker_to_app_ms=#{format('%.3f', ms.call(:worker_start, :app_start) || 0)} app_ms=#{format('%.3f', ms.call(:app_start, :app_return) || 0)} write_ms=#{format('%.3f', ms.call(:app_return, :response_write_done) || 0)} completion_to_reactor_ms=#{format('%.3f', ms.call(:completion_publication, :reactor_collection) || 0)}"
506
+ if ENV["SPINNER_TRACE_OUTPUT"] == "discard"
507
+ nil
508
+ elsif ENV["SPINNER_TRACE_LOG"]
509
+ File.open(ENV["SPINNER_TRACE_LOG"], "a") { |file| file.puts(line) }
510
+ else
511
+ warn line
512
+ end
513
+ end
514
+ end
462
515
  if @draining || client.closed?
463
516
  client.close
464
517
  else
@@ -475,7 +528,7 @@ module Spinner
475
528
  @clients.each do |client|
476
529
  read_client(client) if !client.closed? && client.buffered_tls_data?
477
530
  end
478
- reads = []
531
+ reads = [@wakeup.reader]
479
532
  reads << @listener unless @draining || @capacity.full? || now < @accept_backoff_until
480
533
  writes = []
481
534
  deadline = nil
@@ -490,12 +543,15 @@ module Spinner
490
543
  next if @draining
491
544
  deadline = client.deadline if deadline.nil? || client.deadline < deadline
492
545
  end
493
- timeout = deadline.nil? ? 0.05 : [[deadline - Transport.now, 0.0].max, 0.05].min
546
+ timeout = deadline.nil? ? poll_interval : [[deadline - Transport.now, 0.0].max, poll_interval].min
494
547
  timeout = [timeout, 0.001].min if @clients.any?(&:storage_pending?)
495
548
  selected = IO.select(reads, writes, nil, timeout)
496
549
  next if selected.nil?
497
550
  selected[0].each do |socket|
498
- if socket == @listener
551
+ if socket == @wakeup.reader
552
+ # The next iteration drains notifications and checks shared state.
553
+ next
554
+ elsif socket == @listener
499
555
  accept_ready
500
556
  else
501
557
  client = @clients.find { |candidate| candidate.socket.to_io == socket }
@@ -508,15 +564,32 @@ module Spinner
508
564
  end
509
565
  end
510
566
  ensure
511
- warn "SPINNER_METRIC event=shutdown_complete pid=#{Process.pid} remaining=#{@capacity.count} outcome=#{@capacity.count == 0 ? 'drained' : 'forced'}"
512
- @clients.each(&:close)
513
- @queued.each do |client|
514
- client.close if @pool.cancel(client)
567
+ begin
568
+ warn "SPINNER_METRIC event=shutdown_complete pid=#{Process.pid} remaining=#{@capacity.count} outcome=#{@capacity.count == 0 ? 'drained' : 'forced'}"
569
+ @clients.each(&:close)
570
+ @queued.each do |client|
571
+ client.close if @pool.cancel(client)
572
+ end
573
+ ensure
574
+ begin
575
+ @pool.stop
576
+ ensure
577
+ begin
578
+ @options[:storage_pool].stop
579
+ ensure
580
+ begin
581
+ @reserve_fd.close unless @reserve_fd.nil? || @reserve_fd.closed?
582
+ @pool.completed.each(&:close)
583
+ ensure
584
+ @wakeup.close
585
+ end
586
+ end
587
+ end
515
588
  end
516
- @pool.stop
517
- @options[:storage_pool].stop
518
- @reserve_fd.close unless @reserve_fd.nil? || @reserve_fd.closed?
519
- @pool.completed.each(&:close)
589
+ end
590
+
591
+ def poll_interval
592
+ 0.005
520
593
  end
521
594
 
522
595
  def accept_ready
@@ -535,7 +608,6 @@ module Spinner
535
608
  @capacity.release
536
609
  raise
537
610
  end
538
- warn "SPINNER_METRIC event=accept id=#{@next_id} connections=#{@capacity.count} pid=#{Process.pid}"
539
611
  rescue IO::WaitReadable
540
612
  nil
541
613
  rescue Errno::EMFILE, Errno::ENFILE, Errno::ECONNABORTED => error
@@ -0,0 +1,42 @@
1
+ module Spinner
2
+ # A level-triggered hint to inspect shared state, not a queue of completions.
3
+ # The reactor owns these descriptors and closes them after its producers stop.
4
+ class ReactorWakeup
5
+ attr_reader :reader
6
+
7
+ def initialize
8
+ @reader, @writer = IO.pipe
9
+ @reader.close_on_exec = true
10
+ @writer.close_on_exec = true
11
+ rescue Exception # rubocop:disable Lint/RescueException -- release descriptors even on interrupted initialization
12
+ close
13
+ raise
14
+ end
15
+
16
+ def signal
17
+ @writer.write_nonblock(".".b)
18
+ nil
19
+ rescue IO::WaitWritable
20
+ # A full pipe is already readable; the queued state remains authoritative.
21
+ nil
22
+ rescue Errno::EINTR
23
+ retry
24
+ end
25
+
26
+ def drain
27
+ loop { @reader.read_nonblock(4096) }
28
+ rescue IO::WaitReadable
29
+ nil
30
+ rescue Errno::EINTR
31
+ retry
32
+ end
33
+
34
+ def close
35
+ begin
36
+ @writer.close unless @writer.nil? || @writer.closed?
37
+ ensure
38
+ @reader.close unless @reader.nil? || @reader.closed?
39
+ end
40
+ end
41
+ end
42
+ end
@@ -95,8 +95,10 @@ module Spinner
95
95
  response = nil
96
96
  handed_off = false
97
97
  app_started = Transport.now
98
+ client.trace[:app_start] = app_started if client.trace
98
99
  begin
99
100
  response = @application.call(client.environment)
101
+ client.trace[:app_return] = Transport.now if client.trace
100
102
  unless response.is_a?(Array) && response.length == 3
101
103
  raise ArgumentError, "expected [status, headers, body]"
102
104
  end
@@ -148,6 +150,7 @@ module Spinner
148
150
  keep_alive = false
149
151
  end
150
152
  writer.write(transport, chunks, Transport.now + @write_timeout)
153
+ client.trace[:response_write_done] = Transport.now if client.trace
151
154
  [((Transport.now - app_started) * 1000).round, keep_alive]
152
155
  rescue IOError, SystemCallError => error
153
156
  warn "SPINNER_METRIC event=transport_failure message=#{error.message}"
@@ -28,8 +28,9 @@ module Spinner
28
28
  end
29
29
 
30
30
  class ThreadPool
31
- def initialize(application, size, capacity, header_limit, read_timeout, write_timeout, body_timeout, port, connections, options)
31
+ def initialize(application, size, capacity, header_limit, read_timeout, write_timeout, body_timeout, port, connections, options, wakeup)
32
32
  @options = options
33
+ @wakeup = wakeup
33
34
  @streams = TaskPool.new(options[:max_streams])
34
35
  @upgrades = TaskPool.new(options[:max_upgrades])
35
36
  @async_clients = []
@@ -43,9 +44,14 @@ module Spinner
43
44
  @stopping = false
44
45
  @stop_deadline = nil
45
46
  @workers = []
46
- size.times do
47
- @workers << spawn_worker(application, header_limit, read_timeout,
48
- write_timeout, body_timeout, port)
47
+ begin
48
+ size.times do
49
+ @workers << spawn_worker(application, header_limit, read_timeout,
50
+ write_timeout, body_timeout, port)
51
+ end
52
+ rescue Exception # rubocop:disable Lint/RescueException -- do not leave producers alive after interrupted startup
53
+ stop
54
+ raise
49
55
  end
50
56
  end
51
57
 
@@ -61,6 +67,7 @@ module Spinner
61
67
  end
62
68
  app_ms = nil
63
69
  reuse = false
70
+ result = nil
64
71
  begin
65
72
  reuse = client.keep_alive?
66
73
  result = connection.serve_buffered(client, method(:execute_async), @options[:stream_idle_timeout])
@@ -70,17 +77,8 @@ module Spinner
70
77
  end
71
78
  warn "SPINNER_METRIC event=finish id=#{client.id} app_ms=#{app_ms}" if @options[:request_metrics]
72
79
  ensure
73
- if result == :async
74
- @lock.synchronize { @active.delete(Thread.current) }
75
- elsif !app_ms.nil? && reuse && !client.socket.closed?
76
- @lock.synchronize do
77
- @completed << client
78
- @active.delete(Thread.current)
79
- end
80
- else
81
- client.close
82
- @lock.synchronize { @active.delete(Thread.current) }
83
- end
80
+ @lock.synchronize { @active.delete(Thread.current) }
81
+ complete(client, !app_ms.nil? && reuse) unless result == :async
84
82
  end
85
83
  end
86
84
  end
@@ -96,9 +94,12 @@ module Spinner
96
94
  begin
97
95
  body.close if body.respond_to?(:close)
98
96
  ensure
99
- client.cleanup_body
100
- client.close
101
- @lock.synchronize { @async_clients.delete(client) }
97
+ begin
98
+ client.cleanup_body
99
+ ensure
100
+ @lock.synchronize { @async_clients.delete(client) }
101
+ complete(client, false)
102
+ end
102
103
  end
103
104
  end
104
105
  accepted = pool.submit(cancelled) do
@@ -111,15 +112,16 @@ module Spinner
111
112
  rescue StandardError => error
112
113
  warn "SPINNER_METRIC event=stream_failure message=#{error.message}"
113
114
  ensure
114
- client.cleanup_body
115
- @lock.synchronize do
116
- @async_clients.delete(client)
117
- client.stream_deadline = nil
118
- if reuse && !client.closed? && !@stopping
119
- @completed << client
120
- else
121
- client.close
115
+ cleaned = false
116
+ begin
117
+ client.cleanup_body
118
+ cleaned = true
119
+ ensure
120
+ @lock.synchronize do
121
+ @async_clients.delete(client)
122
+ client.stream_deadline = nil
122
123
  end
124
+ complete(client, reuse && cleaned)
123
125
  end
124
126
  warn "SPINNER_METRIC event=#{kind}_finish id=#{client.id}" if @options[:request_metrics]
125
127
  end
@@ -131,6 +133,23 @@ module Spinner
131
133
  accepted
132
134
  end
133
135
 
136
+ def complete(client, reuse)
137
+ client.trace[:completion_publication] = Transport.now if client.trace
138
+ retained = @lock.synchronize do
139
+ if reuse && !client.closed? && !@stopping
140
+ @completed << client
141
+ true
142
+ else
143
+ false
144
+ end
145
+ end
146
+ client.close unless retained
147
+ ensure
148
+ # Publish before signaling, outside the pool lock. Closures also wake the
149
+ # reactor: it may have excluded the listener while capacity was full.
150
+ @wakeup.signal
151
+ end
152
+
134
153
  def enqueue(client)
135
154
  @lock.synchronize do
136
155
  return false if @stopping || @queue.length >= @capacity
@@ -213,9 +232,22 @@ module Spinner
213
232
 
214
233
  def stop
215
234
  request_stop
216
- @lock.synchronize { @async_clients.each(&:close) }
217
- @streams.stop
218
- @upgrades.stop
235
+ begin
236
+ @lock.synchronize { @async_clients.each(&:close) }
237
+ ensure
238
+ begin
239
+ @streams.stop
240
+ ensure
241
+ begin
242
+ @upgrades.stop
243
+ ensure
244
+ stop_workers
245
+ end
246
+ end
247
+ end
248
+ end
249
+
250
+ def stop_workers
219
251
  @workers.each(&:kill)
220
252
  @workers.each do |worker|
221
253
  begin
@@ -64,27 +64,21 @@ module Spinner
64
64
  @io_lock.synchronize { write_nonblock_unlocked(bytes) }
65
65
  end
66
66
 
67
- # Keep the binary conversion at the native socket call for framed writes.
68
67
  def write_stream_nonblock(bytes)
69
- @io_lock.synchronize do
70
- if @ssl.nil?
71
- @socket.write_nonblock(bytes.b)
72
- else
73
- write_nonblock_unlocked(bytes)
74
- end
75
- end
68
+ @io_lock.synchronize { write_nonblock_unlocked(bytes) }
76
69
  end
77
70
 
78
71
  def write_nonblock_unlocked(bytes)
79
- return @socket.write_nonblock(bytes.b) if @ssl.nil?
72
+ return write_plain_nonblock(bytes) if @ssl.nil?
73
+ binary = bytes.to_s.b
80
74
  if @pending_write.nil?
81
- @pending_write = FFI::MemoryPointer.new(:char, bytes.bytesize)
82
- @pending_write.put_bytes(0, bytes)
83
- @pending_bytes = bytes
84
- elsif @pending_bytes != bytes
75
+ @pending_write = FFI::MemoryPointer.new(:char, binary.bytesize)
76
+ @pending_write.put_bytes(0, binary)
77
+ @pending_bytes = binary
78
+ elsif @pending_bytes != binary
85
79
  raise IOError, "TLS write changed during retry"
86
80
  end
87
- result = TLSNative.SSL_write(@ssl, @pending_write, bytes.bytesize)
81
+ result = TLSNative.SSL_write(@ssl, @pending_write, binary.bytesize)
88
82
  if result > 0
89
83
  @pending_write = nil
90
84
  @pending_bytes = nil
@@ -108,6 +102,21 @@ module Spinner
108
102
 
109
103
  private
110
104
 
105
+ def write_plain_nonblock(bytes)
106
+ binary = bytes.to_s.b
107
+ return @socket.write_nonblock(binary.b) if RUBY_ENGINE == "ruby"
108
+
109
+ # Spinel 10f112c51 can lower boxed socket/string arguments to a
110
+ # null-terminated write. Keep the IO and binary String typed here.
111
+ # Its autoclose:false handle owns a dup, unlike CRuby's shared fd.
112
+ io = IO.for_fd(@socket.fileno, "wb", autoclose: false)
113
+ begin
114
+ io.write_nonblock(binary.b)
115
+ ensure
116
+ io.close
117
+ end
118
+ end
119
+
111
120
  def wait_or_raise(result, operation)
112
121
  case TLSNative.SSL_get_error(@ssl, result)
113
122
  when 2 then raise IO::EAGAINWaitReadable
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Spinner
4
- VERSION = "0.1.0.pre.1"
4
+ VERSION = "0.1.0.pre.4"
5
5
  end
data/lib/spinner.rb CHANGED
@@ -12,6 +12,7 @@ require_relative "spinner/chunk_decoder"
12
12
  require_relative "spinner/host_authority"
13
13
  require_relative "spinner/upgrade"
14
14
  require_relative "spinner/response_writer"
15
+ require_relative "spinner/reactor_wakeup"
15
16
  require_relative "spinner/reactor"
16
17
  require_relative "spinner/server"
17
18
  require_relative "spinner/thread_pool"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spinel-spinner
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0.pre.1
4
+ version: 0.1.0.pre.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dillon Wyatt
@@ -26,6 +26,7 @@ files:
26
26
  - lib/spinner/input.rb
27
27
  - lib/spinner/proxy_metadata.rb
28
28
  - lib/spinner/reactor.rb
29
+ - lib/spinner/reactor_wakeup.rb
29
30
  - lib/spinner/request_parser.rb
30
31
  - lib/spinner/response_writer.rb
31
32
  - lib/spinner/server.rb
@@ -57,7 +58,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
57
58
  - !ruby/object:Gem::Version
58
59
  version: '0'
59
60
  requirements: []
60
- rubygems_version: 3.6.9
61
+ rubygems_version: 4.0.23
61
62
  specification_version: 4
62
63
  summary: A Spinel-compatible HTTP application server
63
64
  test_files: []