io-nonblock 0.1.0 → 0.2.0

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: e7f197b776a167ab8e464d769208e51374e123069c567469f5ace8329bcdaa37
4
- data.tar.gz: 482709a0e5dd558e54a6bcd1329df17a91d36cb6910585446b1685a5389d5af1
3
+ metadata.gz: 147c4c19a532bb8ea1192a306c5c50ab2e95c0c9184048e2918af930733f7332
4
+ data.tar.gz: 1db9af6d8cf78b3779113e95e44b28376bd6788b0be957e7a917084bd2c5706d
5
5
  SHA512:
6
- metadata.gz: 5e55dadc9959a30f527985b7afdb0297dfbdc9b0680a49037099ce0205301992cfbcccd84aa52f18704529d31afb30bc1b033f2284902714fea5e38e5344f60f
7
- data.tar.gz: '00328f04184febef11667804acc88257c28383fbfb65a54649b16fbe1937172af000798ca201aaf2cdd44c572b37dff48b0cc14cdc436b162efc8e437b3e89cd'
6
+ metadata.gz: 91ecd0eca31b2a6f16e83e5257e0fb43015b7c46b1961c97c9d5639f90dd18460777cd60f80b0ab0e9755dfa5415a1acb028e22394d3db443959d1576b130b69
7
+ data.tar.gz: e6a1e5387e7aa86578fe09bc67b26265ab26dd36d442a087bded4c5212bd421348aa1c3e062ee73596e689272a25c1eb44f1738c90738bb0bc17fa807f9d3cd7
@@ -19,14 +19,14 @@
19
19
 
20
20
  #ifdef F_GETFL
21
21
  static int
22
- io_nonblock_mode(int fd)
22
+ get_fcntl_flags(int fd)
23
23
  {
24
24
  int f = fcntl(fd, F_GETFL);
25
25
  if (f == -1) rb_sys_fail(0);
26
26
  return f;
27
27
  }
28
28
  #else
29
- #define io_nonblock_mode(fd) ((void)(fd), 0)
29
+ #define get_fcntl_flags(fd) ((void)(fd), 0)
30
30
  #endif
31
31
 
32
32
  #ifdef F_GETFL
@@ -41,7 +41,7 @@ rb_io_nonblock_p(VALUE io)
41
41
  {
42
42
  rb_io_t *fptr;
43
43
  GetOpenFile(io, fptr);
44
- if (io_nonblock_mode(fptr->fd) & O_NONBLOCK)
44
+ if (get_fcntl_flags(fptr->fd) & O_NONBLOCK)
45
45
  return Qtrue;
46
46
  return Qfalse;
47
47
  }
@@ -50,6 +50,13 @@ rb_io_nonblock_p(VALUE io)
50
50
  #endif
51
51
 
52
52
  #ifdef F_SETFL
53
+ static void
54
+ set_fcntl_flags(int fd, int f)
55
+ {
56
+ if (fcntl(fd, F_SETFL, f) == -1)
57
+ rb_sys_fail(0);
58
+ }
59
+
53
60
  static int
54
61
  io_nonblock_set(int fd, int f, int nb)
55
62
  {
@@ -63,8 +70,7 @@ io_nonblock_set(int fd, int f, int nb)
63
70
  return 0;
64
71
  f &= ~O_NONBLOCK;
65
72
  }
66
- if (fcntl(fd, F_SETFL, f) == -1)
67
- rb_sys_fail(0);
73
+ set_fcntl_flags(fd, f);
68
74
  return 1;
69
75
  }
70
76
 
@@ -74,6 +80,46 @@ io_nonblock_set(int fd, int f, int nb)
74
80
  *
75
81
  * Enables non-blocking mode on a stream when set to
76
82
  * +true+, and blocking mode when set to +false+.
83
+ *
84
+ * This method set or clear O_NONBLOCK flag for the file descriptor
85
+ * in <em>ios</em>.
86
+ *
87
+ * The behavior of most IO methods is not affected by this flag
88
+ * because they retry system calls to complete their task
89
+ * after EAGAIN and partial read/write.
90
+ * (An exception is IO#syswrite which doesn't retry.)
91
+ *
92
+ * This method can be used to clear non-blocking mode of standard I/O.
93
+ * Since nonblocking methods (read_nonblock, etc.) set non-blocking mode but
94
+ * they doesn't clear it, this method is usable as follows.
95
+ *
96
+ * END { STDOUT.nonblock = false }
97
+ * STDOUT.write_nonblock("foo")
98
+ *
99
+ * Since the flag is shared across processes and
100
+ * many non-Ruby commands doesn't expect standard I/O with non-blocking mode,
101
+ * it would be safe to clear the flag before Ruby program exits.
102
+ *
103
+ * For example following Ruby program leaves STDIN/STDOUT/STDER non-blocking mode.
104
+ * (STDIN, STDOUT and STDERR are connected to a terminal.
105
+ * So making one of them nonblocking-mode effects other two.)
106
+ * Thus cat command try to read from standard input and
107
+ * it causes "Resource temporarily unavailable" error (EAGAIN).
108
+ *
109
+ * % ruby -e '
110
+ * STDOUT.write_nonblock("foo\n")'; cat
111
+ * foo
112
+ * cat: -: Resource temporarily unavailable
113
+ *
114
+ * Clearing the flag makes the behavior of cat command normal.
115
+ * (cat command waits input from standard input.)
116
+ *
117
+ * % ruby -rio/nonblock -e '
118
+ * END { STDOUT.nonblock = false }
119
+ * STDOUT.write_nonblock("foo")
120
+ * '; cat
121
+ * foo
122
+ *
77
123
  */
78
124
  static VALUE
79
125
  rb_io_nonblock_set(VALUE io, VALUE nb)
@@ -83,7 +129,7 @@ rb_io_nonblock_set(VALUE io, VALUE nb)
83
129
  if (RTEST(nb))
84
130
  rb_io_set_nonblock(fptr);
85
131
  else
86
- io_nonblock_set(fptr->fd, io_nonblock_mode(fptr->fd), RTEST(nb));
132
+ io_nonblock_set(fptr->fd, get_fcntl_flags(fptr->fd), RTEST(nb));
87
133
  return io;
88
134
  }
89
135
 
@@ -91,15 +137,14 @@ static VALUE
91
137
  io_nonblock_restore(VALUE arg)
92
138
  {
93
139
  int *restore = (int *)arg;
94
- if (fcntl(restore[0], F_SETFL, restore[1]) == -1)
95
- rb_sys_fail(0);
140
+ set_fcntl_flags(restore[0], restore[1]);
96
141
  return Qnil;
97
142
  }
98
143
 
99
144
  /*
100
145
  * call-seq:
101
- * io.nonblock {|io| } -> io
102
- * io.nonblock(boolean) {|io| } -> io
146
+ * io.nonblock {|io| } -> object
147
+ * io.nonblock(boolean) {|io| } -> object
103
148
  *
104
149
  * Yields +self+ in non-blocking mode.
105
150
  *
@@ -119,7 +164,7 @@ rb_io_nonblock_block(int argc, VALUE *argv, VALUE io)
119
164
  rb_scan_args(argc, argv, "01", &v);
120
165
  nb = RTEST(v);
121
166
  }
122
- f = io_nonblock_mode(fptr->fd);
167
+ f = get_fcntl_flags(fptr->fd);
123
168
  restore[0] = fptr->fd;
124
169
  restore[1] = f;
125
170
  if (!io_nonblock_set(fptr->fd, f, nb))
metadata CHANGED
@@ -1,34 +1,28 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: io-nonblock
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nobu Nakada
8
8
  autorequire:
9
- bindir: exe
9
+ bindir: bin
10
10
  cert_chain: []
11
- date: 2020-09-18 00:00:00.000000000 Z
11
+ date: 2022-12-05 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Enables non-blocking mode with IO class
14
14
  email:
15
15
  - nobu@ruby-lang.org
16
16
  executables: []
17
- extensions: []
17
+ extensions:
18
+ - ext/io/nonblock/extconf.rb
18
19
  extra_rdoc_files: []
19
20
  files:
20
- - ".gitignore"
21
- - ".travis.yml"
22
21
  - COPYING
23
- - Gemfile
24
22
  - README.md
25
- - Rakefile
26
- - bin/console
27
- - bin/setup
28
23
  - ext/io/nonblock/depend
29
24
  - ext/io/nonblock/extconf.rb
30
25
  - ext/io/nonblock/nonblock.c
31
- - io-nonblock.gemspec
32
26
  homepage: https://github.com/ruby/io-nonblock
33
27
  licenses:
34
28
  - Ruby
@@ -51,7 +45,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
51
45
  - !ruby/object:Gem::Version
52
46
  version: '0'
53
47
  requirements: []
54
- rubygems_version: 3.2.0.rc.1
48
+ rubygems_version: 3.4.0.dev
55
49
  signing_key:
56
50
  specification_version: 4
57
51
  summary: Enables non-blocking mode with IO class
data/.gitignore DELETED
@@ -1,11 +0,0 @@
1
- /.bundle/
2
- /.yardoc
3
- /_yardoc/
4
- /coverage/
5
- /doc/
6
- /pkg/
7
- /spec/reports/
8
- /tmp/
9
- *.bundle
10
- *.dll
11
- *.so
data/.travis.yml DELETED
@@ -1,6 +0,0 @@
1
- ---
2
- language: ruby
3
- cache: bundler
4
- rvm:
5
- - 2.8.0
6
- before_install: gem install bundler -v 2.1.4
data/Gemfile DELETED
@@ -1,4 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- # Specify your gem's dependencies in etc.gemspec
4
- gemspec
data/Rakefile DELETED
@@ -1,12 +0,0 @@
1
- require "bundler/gem_tasks"
2
- require "rake/testtask"
3
-
4
- Rake::TestTask.new(:test) do |t|
5
- t.libs << "test"
6
- t.libs << "lib"
7
- t.test_files = FileList["test/**/test_*.rb"]
8
- end
9
-
10
- require 'rake/extensiontask'
11
- Rake::ExtensionTask.new("io/nonblock")
12
- task :default => :test
data/bin/console DELETED
@@ -1,14 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require "bundler/setup"
4
- require "io/nonblock"
5
-
6
- # You can add fixtures and/or initialization code here to make experimenting
7
- # with your gem easier. You can also use a different console, if you like.
8
-
9
- # (If you use this, don't forget to add pry to your Gemfile!)
10
- # require "pry"
11
- # Pry.start
12
-
13
- require "irb"
14
- IRB.start(__FILE__)
data/bin/setup DELETED
@@ -1,8 +0,0 @@
1
- #!/usr/bin/env bash
2
- set -euo pipefail
3
- IFS=$'\n\t'
4
- set -vx
5
-
6
- bundle install
7
-
8
- # Do any other automated setup that you need to do here
data/io-nonblock.gemspec DELETED
@@ -1,22 +0,0 @@
1
- Gem::Specification.new do |spec|
2
- spec.name = "io-nonblock"
3
- spec.version = "0.1.0"
4
- spec.authors = ["Nobu Nakada"]
5
- spec.email = ["nobu@ruby-lang.org"]
6
-
7
- spec.summary = %q{Enables non-blocking mode with IO class}
8
- spec.description = %q{Enables non-blocking mode with IO class}
9
- spec.homepage = "https://github.com/ruby/io-nonblock"
10
- spec.licenses = ["Ruby", "BSD-2-Clause"]
11
- spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
12
-
13
- spec.metadata["homepage_uri"] = spec.homepage
14
- spec.metadata["source_code_uri"] = spec.homepage
15
-
16
- spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
17
- `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
- end
19
- spec.bindir = "exe"
20
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
- spec.require_paths = ["lib"]
22
- end