io-nonblock 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: e7f197b776a167ab8e464d769208e51374e123069c567469f5ace8329bcdaa37
4
+ data.tar.gz: 482709a0e5dd558e54a6bcd1329df17a91d36cb6910585446b1685a5389d5af1
5
+ SHA512:
6
+ metadata.gz: 5e55dadc9959a30f527985b7afdb0297dfbdc9b0680a49037099ce0205301992cfbcccd84aa52f18704529d31afb30bc1b033f2284902714fea5e38e5344f60f
7
+ data.tar.gz: '00328f04184febef11667804acc88257c28383fbfb65a54649b16fbe1937172af000798ca201aaf2cdd44c572b37dff48b0cc14cdc436b162efc8e437b3e89cd'
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ *.bundle
10
+ *.dll
11
+ *.so
@@ -0,0 +1,6 @@
1
+ ---
2
+ language: ruby
3
+ cache: bundler
4
+ rvm:
5
+ - 2.8.0
6
+ before_install: gem install bundler -v 2.1.4
data/COPYING ADDED
@@ -0,0 +1,56 @@
1
+ Ruby is copyrighted free software by Yukihiro Matsumoto <matz@netlab.jp>.
2
+ You can redistribute it and/or modify it under either the terms of the
3
+ 2-clause BSDL (see the file BSDL), or the conditions below:
4
+
5
+ 1. You may make and give away verbatim copies of the source form of the
6
+ software without restriction, provided that you duplicate all of the
7
+ original copyright notices and associated disclaimers.
8
+
9
+ 2. You may modify your copy of the software in any way, provided that
10
+ you do at least ONE of the following:
11
+
12
+ a. place your modifications in the Public Domain or otherwise
13
+ make them Freely Available, such as by posting said
14
+ modifications to Usenet or an equivalent medium, or by allowing
15
+ the author to include your modifications in the software.
16
+
17
+ b. use the modified software only within your corporation or
18
+ organization.
19
+
20
+ c. give non-standard binaries non-standard names, with
21
+ instructions on where to get the original software distribution.
22
+
23
+ d. make other distribution arrangements with the author.
24
+
25
+ 3. You may distribute the software in object code or binary form,
26
+ provided that you do at least ONE of the following:
27
+
28
+ a. distribute the binaries and library files of the software,
29
+ together with instructions (in the manual page or equivalent)
30
+ on where to get the original distribution.
31
+
32
+ b. accompany the distribution with the machine-readable source of
33
+ the software.
34
+
35
+ c. give non-standard binaries non-standard names, with
36
+ instructions on where to get the original software distribution.
37
+
38
+ d. make other distribution arrangements with the author.
39
+
40
+ 4. You may modify and include the part of the software into any other
41
+ software (possibly commercial). But some files in the distribution
42
+ are not written by the author, so that they are not under these terms.
43
+
44
+ For the list of those files and their copying conditions, see the
45
+ file LEGAL.
46
+
47
+ 5. The scripts and library files supplied as input to or produced as
48
+ output from the software do not automatically fall under the
49
+ copyright of the software, but belong to whomever generated them,
50
+ and may be sold commercially, and may be aggregated with this
51
+ software.
52
+
53
+ 6. THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
54
+ IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
55
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
56
+ PURPOSE.
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in etc.gemspec
4
+ gemspec
@@ -0,0 +1,29 @@
1
+ # io-nonblock
2
+
3
+ This gem enables non-blocking mode with IO class.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'io-nonblock'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle install
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install io-nonblock
20
+
21
+ ## Development
22
+
23
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
24
+
25
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
26
+
27
+ ## Contributing
28
+
29
+ Bug reports and pull requests are welcome on GitHub at https://github.com/ruby/io-nonblock.
@@ -0,0 +1,12 @@
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
@@ -0,0 +1,14 @@
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__)
@@ -0,0 +1,8 @@
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
@@ -0,0 +1,18 @@
1
+ # AUTOGENERATED DEPENDENCIES START
2
+ nonblock.o: $(RUBY_EXTCONF_H)
3
+ nonblock.o: $(arch_hdrdir)/ruby/config.h
4
+ nonblock.o: $(hdrdir)/ruby.h
5
+ nonblock.o: $(hdrdir)/ruby/assert.h
6
+ nonblock.o: $(hdrdir)/ruby/backward.h
7
+ nonblock.o: $(hdrdir)/ruby/defines.h
8
+ nonblock.o: $(hdrdir)/ruby/encoding.h
9
+ nonblock.o: $(hdrdir)/ruby/intern.h
10
+ nonblock.o: $(hdrdir)/ruby/io.h
11
+ nonblock.o: $(hdrdir)/ruby/missing.h
12
+ nonblock.o: $(hdrdir)/ruby/onigmo.h
13
+ nonblock.o: $(hdrdir)/ruby/oniguruma.h
14
+ nonblock.o: $(hdrdir)/ruby/ruby.h
15
+ nonblock.o: $(hdrdir)/ruby/st.h
16
+ nonblock.o: $(hdrdir)/ruby/subst.h
17
+ nonblock.o: nonblock.c
18
+ # AUTOGENERATED DEPENDENCIES END
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: false
2
+ require 'mkmf'
3
+ target = "io/nonblock"
4
+
5
+ hdr = %w"fcntl.h"
6
+ if have_macro("O_NONBLOCK", hdr) and
7
+ (have_macro("F_GETFL", hdr) or have_macro("F_SETFL", hdr))
8
+ create_makefile(target)
9
+ end
@@ -0,0 +1,140 @@
1
+ /**********************************************************************
2
+
3
+ io/nonblock.c -
4
+
5
+ $Author$
6
+ created at: Tue Jul 14 21:53:18 2009
7
+
8
+ All the files in this distribution are covered under the Ruby's
9
+ license (see the file COPYING).
10
+
11
+ **********************************************************************/
12
+
13
+ #include "ruby.h"
14
+ #include "ruby/io.h"
15
+ #ifdef HAVE_UNISTD_H
16
+ #include <unistd.h>
17
+ #endif
18
+ #include <fcntl.h>
19
+
20
+ #ifdef F_GETFL
21
+ static int
22
+ io_nonblock_mode(int fd)
23
+ {
24
+ int f = fcntl(fd, F_GETFL);
25
+ if (f == -1) rb_sys_fail(0);
26
+ return f;
27
+ }
28
+ #else
29
+ #define io_nonblock_mode(fd) ((void)(fd), 0)
30
+ #endif
31
+
32
+ #ifdef F_GETFL
33
+ /*
34
+ * call-seq:
35
+ * io.nonblock? -> boolean
36
+ *
37
+ * Returns +true+ if an IO object is in non-blocking mode.
38
+ */
39
+ static VALUE
40
+ rb_io_nonblock_p(VALUE io)
41
+ {
42
+ rb_io_t *fptr;
43
+ GetOpenFile(io, fptr);
44
+ if (io_nonblock_mode(fptr->fd) & O_NONBLOCK)
45
+ return Qtrue;
46
+ return Qfalse;
47
+ }
48
+ #else
49
+ #define rb_io_nonblock_p rb_f_notimplement
50
+ #endif
51
+
52
+ #ifdef F_SETFL
53
+ static int
54
+ io_nonblock_set(int fd, int f, int nb)
55
+ {
56
+ if (nb) {
57
+ if ((f & O_NONBLOCK) != 0)
58
+ return 0;
59
+ f |= O_NONBLOCK;
60
+ }
61
+ else {
62
+ if ((f & O_NONBLOCK) == 0)
63
+ return 0;
64
+ f &= ~O_NONBLOCK;
65
+ }
66
+ if (fcntl(fd, F_SETFL, f) == -1)
67
+ rb_sys_fail(0);
68
+ return 1;
69
+ }
70
+
71
+ /*
72
+ * call-seq:
73
+ * io.nonblock = boolean -> boolean
74
+ *
75
+ * Enables non-blocking mode on a stream when set to
76
+ * +true+, and blocking mode when set to +false+.
77
+ */
78
+ static VALUE
79
+ rb_io_nonblock_set(VALUE io, VALUE nb)
80
+ {
81
+ rb_io_t *fptr;
82
+ GetOpenFile(io, fptr);
83
+ if (RTEST(nb))
84
+ rb_io_set_nonblock(fptr);
85
+ else
86
+ io_nonblock_set(fptr->fd, io_nonblock_mode(fptr->fd), RTEST(nb));
87
+ return io;
88
+ }
89
+
90
+ static VALUE
91
+ io_nonblock_restore(VALUE arg)
92
+ {
93
+ int *restore = (int *)arg;
94
+ if (fcntl(restore[0], F_SETFL, restore[1]) == -1)
95
+ rb_sys_fail(0);
96
+ return Qnil;
97
+ }
98
+
99
+ /*
100
+ * call-seq:
101
+ * io.nonblock {|io| } -> io
102
+ * io.nonblock(boolean) {|io| } -> io
103
+ *
104
+ * Yields +self+ in non-blocking mode.
105
+ *
106
+ * When +false+ is given as an argument, +self+ is yielded in blocking mode.
107
+ * The original mode is restored after the block is executed.
108
+ */
109
+ static VALUE
110
+ rb_io_nonblock_block(int argc, VALUE *argv, VALUE io)
111
+ {
112
+ int nb = 1;
113
+ rb_io_t *fptr;
114
+ int f, restore[2];
115
+
116
+ GetOpenFile(io, fptr);
117
+ if (argc > 0) {
118
+ VALUE v;
119
+ rb_scan_args(argc, argv, "01", &v);
120
+ nb = RTEST(v);
121
+ }
122
+ f = io_nonblock_mode(fptr->fd);
123
+ restore[0] = fptr->fd;
124
+ restore[1] = f;
125
+ if (!io_nonblock_set(fptr->fd, f, nb))
126
+ return rb_yield(io);
127
+ return rb_ensure(rb_yield, io, io_nonblock_restore, (VALUE)restore);
128
+ }
129
+ #else
130
+ #define rb_io_nonblock_set rb_f_notimplement
131
+ #define rb_io_nonblock_block rb_f_notimplement
132
+ #endif
133
+
134
+ void
135
+ Init_nonblock(void)
136
+ {
137
+ rb_define_method(rb_cIO, "nonblock?", rb_io_nonblock_p, 0);
138
+ rb_define_method(rb_cIO, "nonblock=", rb_io_nonblock_set, 1);
139
+ rb_define_method(rb_cIO, "nonblock", rb_io_nonblock_block, -1);
140
+ }
@@ -0,0 +1,22 @@
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
metadata ADDED
@@ -0,0 +1,58 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: io-nonblock
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Nobu Nakada
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-09-18 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Enables non-blocking mode with IO class
14
+ email:
15
+ - nobu@ruby-lang.org
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - ".gitignore"
21
+ - ".travis.yml"
22
+ - COPYING
23
+ - Gemfile
24
+ - README.md
25
+ - Rakefile
26
+ - bin/console
27
+ - bin/setup
28
+ - ext/io/nonblock/depend
29
+ - ext/io/nonblock/extconf.rb
30
+ - ext/io/nonblock/nonblock.c
31
+ - io-nonblock.gemspec
32
+ homepage: https://github.com/ruby/io-nonblock
33
+ licenses:
34
+ - Ruby
35
+ - BSD-2-Clause
36
+ metadata:
37
+ homepage_uri: https://github.com/ruby/io-nonblock
38
+ source_code_uri: https://github.com/ruby/io-nonblock
39
+ post_install_message:
40
+ rdoc_options: []
41
+ require_paths:
42
+ - lib
43
+ required_ruby_version: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: 2.3.0
48
+ required_rubygems_version: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: '0'
53
+ requirements: []
54
+ rubygems_version: 3.2.0.rc.1
55
+ signing_key:
56
+ specification_version: 4
57
+ summary: Enables non-blocking mode with IO class
58
+ test_files: []