polyphony 0.97 → 0.99

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.
Files changed (194) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +13 -0
  3. data/examples/io/https_server_sni_2.rb +14 -8
  4. data/examples/io/irb.rb +1 -1
  5. data/ext/polyphony/backend_common.c +30 -0
  6. data/ext/polyphony/backend_common.h +1 -0
  7. data/ext/polyphony/backend_io_uring.c +125 -0
  8. data/ext/polyphony/backend_libev.c +135 -0
  9. data/ext/polyphony/extconf.rb +6 -5
  10. data/ext/polyphony/io_extensions.c +2 -0
  11. data/ext/polyphony/libev.h +0 -2
  12. data/ext/polyphony/polyphony.c +10 -0
  13. data/ext/polyphony/polyphony.h +2 -0
  14. data/lib/polyphony/adapters/irb.rb +0 -2
  15. data/lib/polyphony/core/sync.rb +53 -0
  16. data/lib/polyphony/extensions/io.rb +39 -14
  17. data/lib/polyphony/extensions/openssl.rb +1 -1
  18. data/lib/polyphony/extensions/socket.rb +30 -1
  19. data/lib/polyphony/version.rb +1 -1
  20. data/lib/polyphony.rb +4 -0
  21. data/test/test_io.rb +14 -7
  22. data/test/test_socket.rb +131 -10
  23. data/test/test_sync.rb +42 -1
  24. data/test/test_thread.rb +2 -1
  25. data/vendor/liburing/.github/workflows/build.yml +7 -16
  26. data/vendor/liburing/.gitignore +5 -0
  27. data/vendor/liburing/CHANGELOG +23 -1
  28. data/vendor/liburing/Makefile +4 -3
  29. data/vendor/liburing/Makefile.common +1 -0
  30. data/vendor/liburing/README +48 -0
  31. data/vendor/liburing/configure +76 -6
  32. data/vendor/liburing/debian/changelog +11 -0
  33. data/vendor/liburing/debian/control +7 -16
  34. data/vendor/liburing/debian/liburing-dev.manpages +3 -6
  35. data/vendor/liburing/debian/liburing2.install +1 -0
  36. data/vendor/liburing/debian/liburing2.symbols +56 -0
  37. data/vendor/liburing/debian/rules +15 -68
  38. data/vendor/liburing/examples/Makefile +4 -0
  39. data/vendor/liburing/examples/io_uring-close-test.c +123 -0
  40. data/vendor/liburing/examples/io_uring-udp.c +1 -1
  41. data/vendor/liburing/examples/send-zerocopy.c +315 -56
  42. data/vendor/liburing/examples/ucontext-cp.c +2 -17
  43. data/vendor/liburing/liburing-ffi.pc.in +12 -0
  44. data/vendor/liburing/liburing.pc.in +1 -1
  45. data/vendor/liburing/liburing.spec +1 -1
  46. data/vendor/liburing/make-debs.sh +3 -3
  47. data/vendor/liburing/man/IO_URING_CHECK_VERSION.3 +1 -0
  48. data/vendor/liburing/man/IO_URING_VERSION_MAJOR.3 +1 -0
  49. data/vendor/liburing/man/IO_URING_VERSION_MINOR.3 +1 -0
  50. data/vendor/liburing/man/io_uring_buf_ring_add.3 +6 -6
  51. data/vendor/liburing/man/io_uring_check_version.3 +72 -0
  52. data/vendor/liburing/man/io_uring_close_ring_fd.3 +43 -0
  53. data/vendor/liburing/man/io_uring_major_version.3 +1 -0
  54. data/vendor/liburing/man/io_uring_minor_version.3 +1 -0
  55. data/vendor/liburing/man/io_uring_prep_accept.3 +1 -1
  56. data/vendor/liburing/man/io_uring_prep_fgetxattr.3 +1 -0
  57. data/vendor/liburing/man/io_uring_prep_fsetxattr.3 +1 -0
  58. data/vendor/liburing/man/io_uring_prep_getxattr.3 +61 -0
  59. data/vendor/liburing/man/io_uring_prep_link_timeout.3 +94 -0
  60. data/vendor/liburing/man/io_uring_prep_msg_ring.3 +22 -2
  61. data/vendor/liburing/man/io_uring_prep_msg_ring_cqe_flags.3 +1 -0
  62. data/vendor/liburing/man/io_uring_prep_poll_add.3 +1 -1
  63. data/vendor/liburing/man/io_uring_prep_provide_buffers.3 +18 -9
  64. data/vendor/liburing/man/io_uring_prep_readv.3 +3 -3
  65. data/vendor/liburing/man/io_uring_prep_readv2.3 +3 -3
  66. data/vendor/liburing/man/io_uring_prep_recv.3 +5 -5
  67. data/vendor/liburing/man/io_uring_prep_recvmsg.3 +4 -4
  68. data/vendor/liburing/man/io_uring_prep_send.3 +9 -0
  69. data/vendor/liburing/man/io_uring_prep_send_set_addr.3 +38 -0
  70. data/vendor/liburing/man/io_uring_prep_send_zc.3 +39 -7
  71. data/vendor/liburing/man/io_uring_prep_send_zc_fixed.3 +1 -0
  72. data/vendor/liburing/man/io_uring_prep_sendmsg.3 +20 -0
  73. data/vendor/liburing/man/io_uring_prep_sendmsg_zc.3 +1 -0
  74. data/vendor/liburing/man/io_uring_prep_setxattr.3 +64 -0
  75. data/vendor/liburing/man/io_uring_prep_splice.3 +40 -0
  76. data/vendor/liburing/man/io_uring_prep_writev.3 +2 -2
  77. data/vendor/liburing/man/io_uring_prep_writev2.3 +2 -2
  78. data/vendor/liburing/man/io_uring_recvmsg_out.3 +13 -9
  79. data/vendor/liburing/man/io_uring_register.2 +15 -9
  80. data/vendor/liburing/man/io_uring_register_buf_ring.3 +4 -4
  81. data/vendor/liburing/man/io_uring_register_buffers.3 +49 -6
  82. data/vendor/liburing/man/io_uring_register_buffers_sparse.3 +1 -0
  83. data/vendor/liburing/man/io_uring_register_buffers_tags.3 +1 -0
  84. data/vendor/liburing/man/io_uring_register_buffers_update_tag.3 +1 -0
  85. data/vendor/liburing/man/io_uring_register_files.3 +60 -5
  86. data/vendor/liburing/man/io_uring_register_files_tags.3 +1 -0
  87. data/vendor/liburing/man/io_uring_register_files_update.3 +1 -0
  88. data/vendor/liburing/man/io_uring_register_files_update_tag.3 +1 -0
  89. data/vendor/liburing/man/io_uring_setup.2 +31 -2
  90. data/vendor/liburing/man/io_uring_wait_cqe_timeout.3 +1 -1
  91. data/vendor/liburing/src/Makefile +25 -3
  92. data/vendor/liburing/src/ffi.c +15 -0
  93. data/vendor/liburing/src/include/liburing/io_uring.h +30 -7
  94. data/vendor/liburing/src/include/liburing.h +190 -148
  95. data/vendor/liburing/src/int_flags.h +1 -0
  96. data/vendor/liburing/src/lib.h +5 -16
  97. data/vendor/liburing/src/liburing-ffi.map +172 -0
  98. data/vendor/liburing/src/liburing.map +11 -0
  99. data/vendor/liburing/src/nolibc.c +9 -2
  100. data/vendor/liburing/src/queue.c +2 -2
  101. data/vendor/liburing/src/register.c +66 -96
  102. data/vendor/liburing/src/setup.c +5 -4
  103. data/vendor/liburing/src/version.c +21 -0
  104. data/vendor/liburing/test/232c93d07b74.c +3 -3
  105. data/vendor/liburing/test/35fa71a030ca.c +3 -3
  106. data/vendor/liburing/test/500f9fbadef8.c +2 -0
  107. data/vendor/liburing/test/917257daa0fe.c +1 -1
  108. data/vendor/liburing/test/Makefile +27 -7
  109. data/vendor/liburing/test/a0908ae19763.c +2 -2
  110. data/vendor/liburing/test/a4c0b3decb33.c +2 -2
  111. data/vendor/liburing/test/accept-link.c +4 -4
  112. data/vendor/liburing/test/accept-reuse.c +5 -7
  113. data/vendor/liburing/test/accept.c +34 -31
  114. data/vendor/liburing/test/b19062a56726.c +1 -1
  115. data/vendor/liburing/test/buf-ring.c +58 -4
  116. data/vendor/liburing/test/ce593a6c480a.c +2 -2
  117. data/vendor/liburing/test/close-opath.c +2 -1
  118. data/vendor/liburing/test/connect.c +8 -0
  119. data/vendor/liburing/test/cq-overflow.c +14 -8
  120. data/vendor/liburing/test/d4ae271dfaae.c +1 -1
  121. data/vendor/liburing/test/defer-taskrun.c +64 -9
  122. data/vendor/liburing/test/defer.c +1 -1
  123. data/vendor/liburing/test/double-poll-crash.c +3 -3
  124. data/vendor/liburing/test/eeed8b54e0df.c +8 -3
  125. data/vendor/liburing/test/eploop.c +74 -0
  126. data/vendor/liburing/test/eventfd-ring.c +1 -1
  127. data/vendor/liburing/test/eventfd.c +1 -1
  128. data/vendor/liburing/test/evloop.c +73 -0
  129. data/vendor/liburing/test/exit-no-cleanup.c +1 -1
  130. data/vendor/liburing/test/fadvise.c +1 -1
  131. data/vendor/liburing/test/fc2a85cb02ef.c +3 -3
  132. data/vendor/liburing/test/fd-pass.c +35 -16
  133. data/vendor/liburing/test/file-register.c +61 -0
  134. data/vendor/liburing/test/file-verify.c +2 -2
  135. data/vendor/liburing/test/files-exit-hang-timeout.c +2 -2
  136. data/vendor/liburing/test/fixed-link.c +1 -1
  137. data/vendor/liburing/test/fsnotify.c +118 -0
  138. data/vendor/liburing/test/hardlink.c +1 -1
  139. data/vendor/liburing/test/helpers.c +54 -2
  140. data/vendor/liburing/test/helpers.h +4 -0
  141. data/vendor/liburing/test/io-cancel.c +3 -1
  142. data/vendor/liburing/test/io_uring_passthrough.c +39 -8
  143. data/vendor/liburing/test/io_uring_setup.c +3 -80
  144. data/vendor/liburing/test/iopoll-overflow.c +118 -0
  145. data/vendor/liburing/test/iopoll.c +90 -4
  146. data/vendor/liburing/test/lfs-openat-write.c +7 -9
  147. data/vendor/liburing/test/lfs-openat.c +6 -8
  148. data/vendor/liburing/test/link_drain.c +31 -5
  149. data/vendor/liburing/test/madvise.c +1 -1
  150. data/vendor/liburing/test/msg-ring-flags.c +192 -0
  151. data/vendor/liburing/test/msg-ring-overflow.c +159 -0
  152. data/vendor/liburing/test/msg-ring.c +173 -13
  153. data/vendor/liburing/test/multicqes_drain.c +22 -19
  154. data/vendor/liburing/test/nvme.h +4 -3
  155. data/vendor/liburing/test/pipe-bug.c +95 -0
  156. data/vendor/liburing/test/poll-link.c +3 -3
  157. data/vendor/liburing/test/poll-many.c +41 -19
  158. data/vendor/liburing/test/poll-mshot-overflow.c +105 -2
  159. data/vendor/liburing/test/poll-race-mshot.c +292 -0
  160. data/vendor/liburing/test/poll-race.c +105 -0
  161. data/vendor/liburing/test/poll.c +244 -26
  162. data/vendor/liburing/test/pollfree.c +5 -5
  163. data/vendor/liburing/test/read-before-exit.c +20 -3
  164. data/vendor/liburing/test/read-write.c +2 -0
  165. data/vendor/liburing/test/recv-multishot.c +96 -3
  166. data/vendor/liburing/test/reg-reg-ring.c +90 -0
  167. data/vendor/liburing/test/rename.c +1 -1
  168. data/vendor/liburing/test/ring-leak.c +0 -1
  169. data/vendor/liburing/test/ring-leak2.c +1 -1
  170. data/vendor/liburing/test/ringbuf-read.c +10 -6
  171. data/vendor/liburing/test/send-zerocopy.c +273 -103
  172. data/vendor/liburing/test/send_recv.c +7 -4
  173. data/vendor/liburing/test/sendmsg_fs_cve.c +2 -2
  174. data/vendor/liburing/test/single-issuer.c +7 -9
  175. data/vendor/liburing/test/skip-cqe.c +3 -4
  176. data/vendor/liburing/test/socket.c +0 -1
  177. data/vendor/liburing/test/sq-poll-dup.c +10 -3
  178. data/vendor/liburing/test/sq-poll-kthread.c +1 -1
  179. data/vendor/liburing/test/sq-poll-share.c +3 -2
  180. data/vendor/liburing/test/sqpoll-cancel-hang.c +17 -6
  181. data/vendor/liburing/test/sqpoll-disable-exit.c +4 -4
  182. data/vendor/liburing/test/symlink.c +2 -1
  183. data/vendor/liburing/test/test.h +2 -1
  184. data/vendor/liburing/test/timeout-new.c +11 -7
  185. data/vendor/liburing/test/timeout.c +1 -2
  186. data/vendor/liburing/test/unlink.c +1 -1
  187. data/vendor/liburing/test/version.c +25 -0
  188. data/vendor/liburing/test/wakeup-hang.c +1 -1
  189. data/vendor/liburing/test/xattr.c +8 -4
  190. metadata +42 -6
  191. data/vendor/liburing/debian/compat +0 -1
  192. data/vendor/liburing/debian/liburing1-udeb.install +0 -1
  193. data/vendor/liburing/debian/liburing1.install +0 -1
  194. data/vendor/liburing/debian/liburing1.symbols +0 -32
@@ -742,4 +742,33 @@ class ::UNIXSocket
742
742
  def write_nonblock(buf, exception: true)
743
743
  @io.write_nonblock(buf, exception: exception)
744
744
  end
745
- end
745
+ end
746
+
747
+ class ::UDPSocket
748
+ def recvfrom(maxlen, flags = 0)
749
+ buf = +''
750
+ Polyphony.backend_recvmsg(self, buf, maxlen, 0, flags, 0, nil)
751
+ end
752
+
753
+ def recvmsg(maxlen = nil, flags = 0, maxcontrollen = nil, opts = {})
754
+ buf = +''
755
+ Polyphony.backend_recvmsg(self, buf, maxlen || 4096, 0, flags, maxcontrollen, opts)
756
+ end
757
+
758
+ def sendmsg(msg, flags = 0, dest_sockaddr = nil, *controls)
759
+ Polyphony.backend_sendmsg(self, msg, flags, dest_sockaddr, controls)
760
+ end
761
+
762
+ def send(msg, flags, *addr)
763
+ sockaddr = case addr.size
764
+ when 2
765
+ Socket.sockaddr_in(addr[1], addr[0])
766
+ when 1
767
+ addr[0]
768
+ else
769
+ nil
770
+ end
771
+
772
+ Polyphony.backend_sendmsg(self, msg, flags, sockaddr, nil)
773
+ end
774
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Polyphony
4
- VERSION = '0.97'
4
+ VERSION = '0.99'
5
5
  end
data/lib/polyphony.rb CHANGED
@@ -133,3 +133,7 @@ if (debug_socket_path = ENV['POLYPHONY_DEBUG_SOCKET_PATH'])
133
133
  require 'polyphony/debugger'
134
134
  Polyphony.start_debug_server(debug_socket_path)
135
135
  end
136
+
137
+ if Object.const_defined?(:IRB)
138
+ require_relative './polyphony/adapters/irb'
139
+ end
data/test/test_io.rb CHANGED
@@ -93,6 +93,13 @@ class IOTest < MiniTest::Test
93
93
  assert_equal 'deffoobar', buf
94
94
  end
95
95
 
96
+ def test_read_zero
97
+ i, o = IO.pipe
98
+
99
+ o << 'hi'
100
+ assert_equal '', i.read(0)
101
+ end
102
+
96
103
  def test_readpartial
97
104
  i, o = IO.pipe
98
105
 
@@ -516,13 +523,12 @@ class IOClassMethodsTest < MiniTest::Test
516
523
  assert_equal BIN_DATA, s
517
524
  end
518
525
 
519
- # def test_foreach
520
- # skip 'IO.foreach is not yet implemented'
521
- # lines = []
522
- # IO.foreach(__FILE__) { |l| lines << l }
523
- # assert_equal "# frozen_string_literal: true\n", lines[0]
524
- # assert_equal "end\n", lines[-1]
525
- # end
526
+ def test_foreach
527
+ lines = []
528
+ IO.foreach(__FILE__) { |l| lines << l }
529
+ assert_equal "# frozen_string_literal: true\n", lines[0]
530
+ assert_equal "end\n", lines[-1]
531
+ end
526
532
 
527
533
  def test_read_class_method
528
534
  s = IO.read(__FILE__)
@@ -658,6 +664,7 @@ class IOClassMethodsTest < MiniTest::Test
658
664
 
659
665
  # writing always causes snoozing
660
666
  o << 'foo'
667
+ 3.times { snooze }
661
668
  o << 'bar'
662
669
  o.close
663
670
 
data/test/test_socket.rb CHANGED
@@ -3,12 +3,9 @@
3
3
  require_relative 'helper'
4
4
  require 'fileutils'
5
5
  require 'msgpack'
6
+ require 'localhost/authority'
6
7
 
7
- class SocketTest < MiniTest::Test
8
- def setup
9
- super
10
- end
11
-
8
+ class TCPSocketTest < MiniTest::Test
12
9
  def start_tcp_server_on_random_port(host = '127.0.0.1')
13
10
  port = rand(1100..60000)
14
11
  server = TCPServer.new(host, port)
@@ -41,13 +38,13 @@ class SocketTest < MiniTest::Test
41
38
  end
42
39
 
43
40
  def test_tcpsocket_open_with_hostname
44
- client = TCPSocket.open('google.com', 80)
45
- client.write("GET / HTTP/1.0\r\nHost: google.com\r\n\r\n")
41
+ client = TCPSocket.open('ipinfo.io', 80)
42
+ client.write("GET / HTTP/1.0\r\nHost: ipinfo.io\r\n\r\n")
46
43
  result = nil
47
44
  move_on_after(3) {
48
45
  result = client.read
49
46
  }
50
- assert result =~ /HTTP\/1.0 301 Moved Permanently/
47
+ assert result =~ /HTTP\/1.0 200 OK/
51
48
  end
52
49
 
53
50
  def test_tcp_ipv6
@@ -166,7 +163,9 @@ class SocketTest < MiniTest::Test
166
163
  server_fiber&.await
167
164
  server&.close
168
165
  end
166
+ end
169
167
 
168
+ class UNIXSocketTest < MiniTest::Test
170
169
  def test_unix_socket
171
170
  path = '/tmp/test_unix_socket'
172
171
  FileUtils.rm(path) rescue nil
@@ -193,7 +192,7 @@ class SocketTest < MiniTest::Test
193
192
  end
194
193
  end
195
194
 
196
- class SocketWithRawBufferTest < MiniTest::Test
195
+ class TCPSocketWithRawBufferTest < MiniTest::Test
197
196
  def start_tcp_server_on_random_port(host = '127.0.0.1')
198
197
  port = rand(1100..60000)
199
198
  server = TCPServer.new(host, port)
@@ -243,6 +242,68 @@ class SocketWithRawBufferTest < MiniTest::Test
243
242
  end
244
243
  end
245
244
 
245
+ class UDPSocketTest < MiniTest::Test
246
+ def test_udp_recvfrom
247
+ u1 = UDPSocket.new
248
+ u1.bind('127.0.0.1', 0)
249
+
250
+ server_fiber = spin do
251
+ msg, peer_addr = u1.recvfrom(256)
252
+ u1.send(msg, 0, peer_addr[3], peer_addr[1])
253
+ end
254
+
255
+ server_addr = u1.addr
256
+ u2 = UDPSocket.new
257
+ u2.bind('127.0.0.1', 0)
258
+ u2.send('foobar', 0, server_addr[3], server_addr[1])
259
+
260
+ msg, addr = u2.recvfrom(256)
261
+
262
+ assert_equal 'foobar', msg
263
+ assert_equal server_addr, addr
264
+ end
265
+
266
+ def test_udp_recvmsg
267
+ u1 = UDPSocket.new
268
+ u1.bind('127.0.0.1', 0)
269
+
270
+ server_fiber = spin do
271
+ msg, peer_addr = u1.recvmsg(256)
272
+ u1.send(msg, 0, peer_addr[3], peer_addr[1])
273
+ end
274
+
275
+ server_addr = u1.addr
276
+ u2 = UDPSocket.new
277
+ u2.bind('127.0.0.1', 0)
278
+ u2.send('foobar', 0, server_addr[3], server_addr[1])
279
+
280
+ msg, addr = u2.recvmsg(256)
281
+
282
+ assert_equal 'foobar', msg
283
+ assert_equal server_addr, addr
284
+ end
285
+
286
+ def test_udp_recvfrom_ipv6
287
+ u1 = UDPSocket.new :INET6
288
+ u1.bind('::1', 0)
289
+
290
+ server_fiber = spin do
291
+ msg, peer_addr = u1.recvfrom(256)
292
+ u1.send(msg, 0, peer_addr[3], peer_addr[1])
293
+ end
294
+
295
+ server_addr = u1.addr
296
+ u2 = UDPSocket.new :INET6
297
+ u2.bind('::1', 0)
298
+ u2.send('foobar', 0, server_addr[3], server_addr[1])
299
+
300
+ msg, addr = u2.recvfrom(256)
301
+
302
+ assert_equal 'foobar', msg
303
+ assert_equal server_addr, addr
304
+ end
305
+ end
306
+
246
307
  if IS_LINUX
247
308
  class HTTPClientTest < MiniTest::Test
248
309
 
@@ -261,4 +322,64 @@ if IS_LINUX
261
322
  assert_equal 'https://ipinfo.io/missingauth', response['readme']
262
323
  end
263
324
  end
264
- end
325
+ end
326
+
327
+ class SSLSocketTest < MiniTest::Test
328
+ def handle_http_request(socket)
329
+ while (data = socket.gets("\n", 8192))
330
+ if data.chomp.empty?
331
+ socket << "HTTP/1.1 200 OK\nConnection: close\nContent-Length: 3\n\nfoo"
332
+ break
333
+ end
334
+ end
335
+ end
336
+
337
+ def test_ssl_accept_loop
338
+ authority = Localhost::Authority.fetch
339
+ server_ctx = authority.server_context
340
+
341
+ opts = {
342
+ reuse_addr: true,
343
+ dont_linger: true,
344
+ secure_context: server_ctx
345
+ }
346
+
347
+ port = rand(10001..39999)
348
+ server = Polyphony::Net.tcp_listen('127.0.0.1', port, opts)
349
+ f = spin do
350
+ server.accept_loop { |s| handle_http_request(s) }
351
+ end
352
+
353
+ # make bad request
354
+ `curl -s http://localhost:#{port}/`
355
+
356
+ msg = `curl -sk https://localhost:#{port}/`
357
+ assert_equal 'foo', msg
358
+
359
+ f.stop
360
+ f.await
361
+
362
+ port = rand(10001..39999)
363
+ server = Polyphony::Net.tcp_listen('127.0.0.1', port, opts)
364
+ errors = []
365
+ f = spin do
366
+ ## without ignoring errors
367
+ f2 = spin do
368
+ server.accept_loop(false) { |s| handle_http_request(s) }
369
+ end
370
+ f2.await
371
+ rescue => e
372
+ errors << e
373
+ end
374
+
375
+ msg = `curl -sk https://localhost:#{port}/`
376
+ assert_equal 'foo', msg
377
+
378
+ # make bad request
379
+ `curl -s http://localhost:#{port}/`
380
+
381
+ f.await
382
+ assert_equal 1, errors.size
383
+ assert_kind_of OpenSSL::SSL::SSLError, errors.first
384
+ end
385
+ end
data/test/test_sync.rb CHANGED
@@ -113,4 +113,45 @@ class MutexTest < MiniTest::Test
113
113
  receive
114
114
  assert !lock.locked?
115
115
  end
116
- end
116
+
117
+ def test_lock_unlock
118
+ m = Polyphony::Mutex.new
119
+ assert_nil m.locked?
120
+ assert_equal false, m.owned?
121
+ assert_raises(ThreadError) { m.unlock }
122
+
123
+ m.lock
124
+ assert_equal Fiber.current, m.locked?
125
+ assert_equal true, m.owned?
126
+
127
+ assert_raises(ThreadError) { m.lock }
128
+
129
+ m.unlock
130
+ assert_nil m.locked?
131
+ assert_equal false, m.owned?
132
+ end
133
+
134
+ def test_try_lock
135
+ m = Polyphony::Mutex.new
136
+
137
+ r = m.try_lock
138
+ assert_equal true, r
139
+
140
+ r = m.try_lock
141
+ assert_equal false, r
142
+
143
+ this = Fiber.current
144
+ m.unlock
145
+ f = spin do
146
+ m.synchronize { this << 'ok'; sleep 0.2 }
147
+ end
148
+
149
+ assert_equal 'ok', receive
150
+ r = m.try_lock
151
+ assert_equal false, r
152
+
153
+ f.await
154
+ r = m.try_lock
155
+ assert_equal true, r
156
+ end
157
+ end
data/test/test_thread.rb CHANGED
@@ -40,13 +40,14 @@ class ThreadTest < MiniTest::Test
40
40
 
41
41
  def test_thread_join_with_timeout
42
42
  buffer = []
43
- spin { (1..3).each { |i| snooze; buffer << i } }
43
+ f = spin { (1..3).each { |i| snooze; buffer << i } }
44
44
  t = Thread.new { sleep 1; buffer << 4 }
45
45
  t0 = Time.now
46
46
  r = t.join(0.01)
47
47
  t = nil
48
48
 
49
49
  assert Time.now - t0 < 0.2
50
+ f.join
50
51
  assert_equal [1, 2, 3], buffer
51
52
  assert_nil r
52
53
  ensure
@@ -26,7 +26,8 @@ jobs:
26
26
  cxx_pkg: clang
27
27
  cc: clang
28
28
  cxx: clang++
29
- extra_flags: -Wshorten-64-to-32
29
+ liburing_extra_flags: -Wshorten-64-to-32
30
+ extra_flags: -Wmissing-prototypes -Wstrict-prototypes -Wunreachable-code-loop-increment -Wunreachable-code -Wmissing-variable-declarations -Wextra-semi-stmt
30
31
 
31
32
  # x86 (32-bit) gcc
32
33
  - arch: i686
@@ -85,10 +86,10 @@ jobs:
85
86
  cxx: mips-linux-gnu-g++
86
87
 
87
88
  env:
88
- FLAGS: -g -O3 -Wall -Wextra -Werror
89
+ FLAGS: -g -O3 -Wall -Wextra -Werror -Wno-sign-compare ${{matrix.extra_flags}}
89
90
 
90
91
  # Flags for building sources in src/ dir only.
91
- LIBURING_CFLAGS: ${{matrix.extra_flags}}
92
+ LIBURING_CFLAGS: ${{matrix.liburing_extra_flags}}
92
93
 
93
94
  steps:
94
95
  - name: Checkout source
@@ -98,9 +99,9 @@ jobs:
98
99
  run: |
99
100
  if [[ "${{matrix.cc_pkg}}" == "clang" ]]; then \
100
101
  wget https://apt.llvm.org/llvm.sh -O /tmp/llvm.sh; \
101
- sudo bash /tmp/llvm.sh 16; \
102
- sudo update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-16 400; \
103
- sudo update-alternatives --install /usr/bin/clang clang /usr/bin/clang-16 400; \
102
+ sudo bash /tmp/llvm.sh 17; \
103
+ sudo update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-17 400; \
104
+ sudo update-alternatives --install /usr/bin/clang clang /usr/bin/clang-17 400; \
104
105
  else \
105
106
  sudo apt-get update -y; \
106
107
  sudo apt-get install -y ${{matrix.cc_pkg}} ${{matrix.cxx_pkg}}; \
@@ -116,16 +117,6 @@ jobs:
116
117
  ./configure --cc=${{matrix.cc}} --cxx=${{matrix.cxx}};
117
118
  make -j$(nproc) V=1 CPPFLAGS="-Werror" CFLAGS="$FLAGS" CXXFLAGS="$FLAGS";
118
119
 
119
- - name: Build nolibc
120
- run: |
121
- if [[ "${{matrix.arch}}" == "x86_64" || "${{matrix.arch}}" == "i686" || "${{matrix.arch}}" == "aarch64" ]]; then \
122
- make clean; \
123
- ./configure --cc=${{matrix.cc}} --cxx=${{matrix.cxx}} --nolibc; \
124
- make -j$(nproc) V=1 CPPFLAGS="-Werror" CFLAGS="$FLAGS" CXXFLAGS="$FLAGS"; \
125
- else \
126
- echo "Skipping nolibc build, this arch doesn't support building liburing without libc"; \
127
- fi;
128
-
129
120
  - name: Test install command
130
121
  run: |
131
122
  sudo make install;
@@ -9,8 +9,12 @@
9
9
 
10
10
  /src/liburing.a
11
11
  /src/liburing.so*
12
+ /src/liburing-ffi.a
13
+ /src/liburing-ffi.so*
12
14
  /src/include/liburing/compat.h
15
+ /src/include/liburing/io_uring_version.h
13
16
 
17
+ /examples/io_uring-close-test
14
18
  /examples/io_uring-cp
15
19
  /examples/io_uring-test
16
20
  /examples/io_uring-udp
@@ -28,5 +32,6 @@ config-host.mak
28
32
  config.log
29
33
 
30
34
  liburing.pc
35
+ liburing-ffi.pc
31
36
 
32
37
  cscope.out
@@ -1,8 +1,30 @@
1
+ liburing-2.4 release
2
+
3
+ - Add io_uring_{major,minor,check}_version() functions.
4
+ - Add IO_URING_{MAJOR,MINOR,CHECK}_VERSION() macros.
5
+ - FFI support (for non-C/C++ languages integration).
6
+ - Add io_uring_prep_msg_ring_cqe_flags() function.
7
+ - Deprecate --nolibc configure option.
8
+ - CONFIG_NOLIBC is always enabled on x86-64, x86, and aarch64.
9
+ - Add support for IORING_REGISTER_USE_REGISTERED_RING and use if available.
10
+ - Add io_uring_close_ring_fd() function.
11
+
1
12
  liburing-2.3 release
2
13
 
3
14
  - Support non-libc build for aarch64.
4
15
  - Add io_uring_{enter,enter2,register,setup} syscall functions.
5
-
16
+ - Add sync cancel interface, io_uring_register_sync_cancel().
17
+ - Fix return value of io_uring_submit_and_wait_timeout() to match the
18
+ man page.
19
+ - Improvements to the regression tests
20
+ - Add support and test case for passthrough IO
21
+ - Add recv and recvmsg multishot helpers and support
22
+ - Add documentation and support for IORING_SETUP_DEFER_TASKRUN
23
+ - Fix potential missing kernel entry with IORING_SETUP_IOPOLL
24
+ - Add support and documentation for zero-copy network transmit
25
+ - Various optimizations
26
+ - Many cleanups
27
+ - Many man page additions and updates
6
28
 
7
29
  liburing-2.2 release
8
30
 
@@ -25,7 +25,7 @@ runtests-parallel: all
25
25
  @$(MAKE) -C test runtests-parallel
26
26
 
27
27
  config-host.mak: configure
28
- @if [ ! -e "$@" ]; then \
28
+ +@if [ ! -e "$@" ]; then \
29
29
  echo "Running configure ..."; \
30
30
  ./configure; \
31
31
  else \
@@ -45,13 +45,14 @@ endif
45
45
  -e "s%@VERSION@%$(VERSION)%g" \
46
46
  $< >$@
47
47
 
48
- install: $(NAME).pc
48
+ install: $(NAME).pc $(NAME)-ffi.pc
49
49
  @$(MAKE) -C src install prefix=$(DESTDIR)$(prefix) \
50
50
  includedir=$(DESTDIR)$(includedir) \
51
51
  libdir=$(DESTDIR)$(libdir) \
52
52
  libdevdir=$(DESTDIR)$(libdevdir) \
53
53
  relativelibdir=$(relativelibdir)
54
54
  $(INSTALL) -D -m 644 $(NAME).pc $(DESTDIR)$(libdevdir)/pkgconfig/$(NAME).pc
55
+ $(INSTALL) -D -m 644 $(NAME)-ffi.pc $(DESTDIR)$(libdevdir)/pkgconfig/$(NAME)-ffi.pc
55
56
  $(INSTALL) -m 755 -d $(DESTDIR)$(mandir)/man2
56
57
  $(INSTALL) -m 644 man/*.2 $(DESTDIR)$(mandir)/man2
57
58
  $(INSTALL) -m 755 -d $(DESTDIR)$(mandir)/man3
@@ -63,7 +64,7 @@ install-tests:
63
64
  @$(MAKE) -C test install prefix=$(DESTDIR)$(prefix) datadir=$(DESTDIR)$(datadir)
64
65
 
65
66
  clean:
66
- @rm -f config-host.mak config-host.h cscope.out $(NAME).pc test/*.dmesg
67
+ @rm -f config-host.mak config-host.h cscope.out $(NAME).pc $(NAME)-ffi.pc test/*.dmesg
67
68
  @$(MAKE) -C src clean
68
69
  @$(MAKE) -C test clean
69
70
  @$(MAKE) -C examples clean
@@ -3,4 +3,5 @@ NAME=liburing
3
3
  SPECFILE=$(TOP)/$(NAME).spec
4
4
  VERSION=$(shell awk '/Version:/ { print $$2 }' $(SPECFILE))
5
5
  VERSION_MAJOR=$(shell echo $(VERSION) | cut -d. -f1)
6
+ VERSION_MINOR=$(shell echo $(VERSION) | cut -d. -f2)
6
7
  TAG = $(NAME)-$(VERSION)
@@ -47,6 +47,54 @@ the kernel io_uring support. Please note that this suite isn't expected to
47
47
  pass on older kernels, and may even crash or hang older kernels!
48
48
 
49
49
 
50
+ Building liburing
51
+ -----------------
52
+
53
+ #
54
+ # Prepare build config (optional).
55
+ #
56
+ # --cc specifies the C compiler.
57
+ # --cxx speficies the C++ compiler.
58
+ #
59
+ ./configure --cc=gcc --cxx=g++;
60
+
61
+ #
62
+ # Build liburing.
63
+ #
64
+ make -j$(nproc);
65
+
66
+ #
67
+ # Install liburing (headers, shared/static libs, and manpage).
68
+ #
69
+ sudo make install;
70
+
71
+ See './configure --help' for more information about build config options.
72
+
73
+
74
+ FFI support
75
+ -----------
76
+
77
+ By default, the build results in 4 lib files:
78
+
79
+ 2 shared libs:
80
+
81
+ liburing.so
82
+ liburing-ffi.so
83
+
84
+ 2 static libs:
85
+
86
+ liburing.a
87
+ liburing-ffi.a
88
+
89
+ Languages and applications that can't use 'static inline' functions in
90
+ liburing.h should use the FFI variants.
91
+
92
+ liburing's main public interface lives in liburing.h as 'static inline'
93
+ functions. Users wishing to consume liburing purely as a binary dependency
94
+ should link against liburing-ffi. It contains definitions for every 'static
95
+ inline' function.
96
+
97
+
50
98
  License
51
99
  -------
52
100
 
@@ -5,6 +5,22 @@ set -e
5
5
  cc=${CC:-gcc}
6
6
  cxx=${CXX:-g++}
7
7
 
8
+ #
9
+ # TODO(ammarfaizi2): Remove this notice and `--nolibc` option.
10
+ #
11
+ nolibc_deprecated() {
12
+ echo "";
13
+ echo "=================================================================";
14
+ echo "";
15
+ echo " --nolibc option is deprecated and has no effect.";
16
+ echo " It will be removed in a future liburing release.";
17
+ echo "";
18
+ echo " liburing on x86-64, x86 (32-bit) and aarch64 always use CONFIG_NOLIBC.";
19
+ echo "";
20
+ echo "=================================================================";
21
+ echo "";
22
+ }
23
+
8
24
  for opt do
9
25
  optarg=$(expr "x$opt" : 'x[^=]*=\(.*\)' || true)
10
26
  case "$opt" in
@@ -26,7 +42,7 @@ for opt do
26
42
  ;;
27
43
  --cxx=*) cxx="$optarg"
28
44
  ;;
29
- --nolibc) liburing_nolibc="yes"
45
+ --nolibc) nolibc_deprecated
30
46
  ;;
31
47
  *)
32
48
  echo "ERROR: unknown option $opt"
@@ -115,7 +131,7 @@ print_config() {
115
131
  }
116
132
 
117
133
  # Default CFLAGS
118
- CFLAGS="-D_GNU_SOURCE -include config-host.h"
134
+ CFLAGS="-D_GNU_SOURCE -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -include config-host.h"
119
135
  BUILD_CFLAGS=""
120
136
 
121
137
  # Print configure header at the top of $config_host_h
@@ -385,13 +401,43 @@ fi
385
401
  print_config "NVMe uring command support" "$nvme_uring_cmd"
386
402
 
387
403
  #############################################################################
404
+ #
405
+ # Currently, CONFIG_NOLIBC is only enabled on x86-64, x86 (32-bit) and aarch64.
406
+ #
407
+ cat > $TMPC << EOF
408
+ int main(void){
409
+ #if defined(__x86_64__) || defined(__i386__) || defined(__aarch64__)
410
+ return 0;
411
+ #else
412
+ #error libc is needed
413
+ #endif
414
+ }
415
+ EOF
416
+ if compile_prog "" "" "nolibc support"; then
417
+ liburing_nolibc="yes"
418
+ fi
419
+ print_config "nolibc support" "$liburing_nolibc";
420
+ #############################################################################
421
+
422
+ ####################################################
423
+ # Most Android devices don't have sys/fanotify.h
424
+ has_fanotify="no"
425
+ cat > $TMPC << EOF
426
+ #include <sys/fanotify.h>
427
+ int main(void)
428
+ {
429
+ return 0;
430
+ }
431
+ EOF
432
+ if compile_prog "" "" "fanotify"; then
433
+ has_fanotify="yes"
434
+ fi
435
+ print_config "has_fanotify" "$has_fanotify"
436
+ ####################################################
437
+
388
438
  if test "$liburing_nolibc" = "yes"; then
389
439
  output_sym "CONFIG_NOLIBC"
390
- else
391
- liburing_nolibc="no"
392
440
  fi
393
- print_config "liburing_nolibc" "$liburing_nolibc"
394
-
395
441
  if test "$__kernel_rwf_t" = "yes"; then
396
442
  output_sym "CONFIG_HAVE_KERNEL_RWF_T"
397
443
  fi
@@ -422,12 +468,31 @@ fi
422
468
  if test "$nvme_uring_cmd" = "yes"; then
423
469
  output_sym "CONFIG_HAVE_NVME_URING"
424
470
  fi
471
+ if test "$has_fanotify" = "yes"; then
472
+ output_sym "CONFIG_HAVE_FANOTIFY"
473
+ fi
425
474
 
426
475
  echo "CC=$cc" >> $config_host_mak
427
476
  print_config "CC" "$cc"
428
477
  echo "CXX=$cxx" >> $config_host_mak
429
478
  print_config "CXX" "$cxx"
430
479
 
480
+ # generate io_uring_version.h
481
+ MAKE_PRINT_VARS="include Makefile.common\nprint-%: ; @echo \$(\$*)\n"
482
+ VERSION_MAJOR=$(env echo -e "$MAKE_PRINT_VARS" | make -s --no-print-directory -f - print-VERSION_MAJOR)
483
+ VERSION_MINOR=$(env echo -e "$MAKE_PRINT_VARS" | make -s --no-print-directory -f - print-VERSION_MINOR)
484
+ io_uring_version_h="src/include/liburing/io_uring_version.h"
485
+ cat > $io_uring_version_h << EOF
486
+ /* SPDX-License-Identifier: MIT */
487
+ #ifndef LIBURING_VERSION_H
488
+ #define LIBURING_VERSION_H
489
+
490
+ #define IO_URING_VERSION_MAJOR $VERSION_MAJOR
491
+ #define IO_URING_VERSION_MINOR $VERSION_MINOR
492
+
493
+ #endif
494
+ EOF
495
+
431
496
  # generate compat.h
432
497
  compat_h="src/include/liburing/compat.h"
433
498
  cat > $compat_h << EOF
@@ -452,10 +517,15 @@ struct __kernel_timespec {
452
517
  long long tv_nsec;
453
518
  };
454
519
 
520
+ /* <linux/time_types.h> is not available, so it can't be included */
521
+ #define UAPI_LINUX_IO_URING_H_SKIP_LINUX_TIME_TYPES_H 1
522
+
455
523
  EOF
456
524
  else
457
525
  cat >> $compat_h << EOF
458
526
  #include <linux/time_types.h>
527
+ /* <linux/time_types.h> is included above and not needed again */
528
+ #define UAPI_LINUX_IO_URING_H_SKIP_LINUX_TIME_TYPES_H 1
459
529
 
460
530
  EOF
461
531
  fi
@@ -1,3 +1,14 @@
1
+ liburing (2.2-1) stable; urgency=low
2
+
3
+ * Update to 2.2
4
+ * Bump up so version to 2
5
+ * Drop liburing1-udeb
6
+ * Package using dh instead of using dh_* helpers manually
7
+ * Add linux header dependency to liburing-dev
8
+ * Bump up debhelper-compact level to 13
9
+
10
+ -- Kefu Chai <tchaikov@gmail.com> Sun, 16 Oct 2022 16:30:48 +0800
11
+
1
12
  liburing (0.7-1) stable; urgency=low
2
13
 
3
14
  * Update to 0.7