net-proto 1.1.1 → 1.2.0

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
  SHA1:
3
- metadata.gz: 83b848fce79a24c404a269ecfaf838c8999e000a
4
- data.tar.gz: 33fada4059a1ac04b305e0d04b621d777cc4e5e9
3
+ metadata.gz: 9ad82469ee27db26ef64fc237b2f0997c128e491
4
+ data.tar.gz: b75d18a5640061415124e0db9a4c9d984a09e1af
5
5
  SHA512:
6
- metadata.gz: fd37187da1d51e62cf87fb54dab95ab6a5dc718aa397f25b9fb7e2e7898926d00ef38445bfa71619606ddee887610bbb89fb103b7f39fcc989fddb3ef8e5b270
7
- data.tar.gz: d36e65afe0656f492d34ada92d6833aa18da0c36ec3846b26bb1cef8172c64a82dadda712d6c282d86c811013e597bb7745e9cb5a1ecc500ec23f06dab869968
6
+ metadata.gz: bc8b339c75aa05037c264351888309c7d65392f3db57cdaf89cab05ca46584a8747501e905b999e0fb0f2aa30b7a6f1fb12bbea84d0baaddf8c2995e694c58bd
7
+ data.tar.gz: b056f5cb415e6cbf756c5e9e4e36f77f29bf66844e493f243ace79ee5f1ce662a35a9924963f62c30c1f386ae29aa58f78a99275fa5204a3739e1a25d2906a1e
data/CHANGES CHANGED
@@ -1,3 +1,8 @@
1
+ == 1.2.0 - 3-Nov-2014
2
+ * The getprotobynumber and getprotobyname methods on MS Windows now accept
3
+ optional window and message arguments. If used, the method becomes
4
+ asynchronous and yields a block instead.
5
+
1
6
  == 1.1.1 - 9-Oct-2014
2
7
  * Implemented getprotoent on Windows using pure Ruby.
3
8
  * Miscellaneous minor updates to the Rakefile, gemspec and docs.
@@ -58,10 +58,6 @@ Proto.getprotoent{ |struct| ... }
58
58
  None that I'm aware of. Please log any bug reports on the project page
59
59
  at https://github.com/djberg96/net-proto.
60
60
 
61
- == Future Plans
62
- Use the asynchronous calls (WSAAsyncGetProtoByName and
63
- WSAAsyncGetProtoByNumber) on MS Windows systems.
64
-
65
61
  == Copyright
66
62
  (C) 2003-2014 Daniel J. Berger
67
63
  All rights reserved.
@@ -5,7 +5,7 @@ module Net
5
5
  extend FFI::Library
6
6
 
7
7
  # The version of the net-proto library
8
- VERSION = '1.1.1'
8
+ VERSION = '1.2.0'
9
9
 
10
10
  private_class_method :new
11
11
 
@@ -15,9 +15,15 @@ module Net
15
15
  # These should exist on every platform.
16
16
  attach_function :getprotobyname_c, :getprotobyname, [:string], :pointer
17
17
  attach_function :getprotobynumber_c, :getprotobynumber, [:int], :pointer
18
+ attach_function :WSAAsyncGetProtoByName, [:uintptr_t, :uint, :string, :pointer, :pointer], :uintptr_t
19
+ attach_function :WSAAsyncGetProtoByNumber, [:uintptr_t, :uint, :int, :pointer, :pointer], :uintptr_t
20
+ attach_function :WSAGetLastError, [], :int
18
21
 
19
22
  private_class_method :getprotobyname_c
20
23
  private_class_method :getprotobynumber_c
24
+ private_class_method :WSAAsyncGetProtoByName
25
+ private_class_method :WSAAsyncGetProtoByNumber
26
+ private_class_method :WSAGetLastError
21
27
 
22
28
  public
23
29
 
@@ -47,17 +53,38 @@ module Net
47
53
  # Net::Proto.getprotobyname('tcp') # => 6
48
54
  # Net::Proto.getprotobyname('bogus') # => nil
49
55
  #
50
- def self.getprotobyname(protocol)
56
+ # On MS Windows, you may also pass a window handle and a message (int)
57
+ # that window will receive. If present, this method becomes asynchronous
58
+ # and yields a block instead, with the protocol and handle.
59
+ #
60
+ # Example:
61
+ #
62
+ # Net::Proto.getprotobyname('tcp', SOME_WINDOW, SOME_MSG){ |num, handle| ... }
63
+ #
64
+ def self.getprotobyname(protocol, hwnd = 0, msg = 0)
51
65
  raise TypeError unless protocol.is_a?(String)
52
66
 
53
- begin
54
- ptr = getprotobyname_c(protocol)
55
- struct = ProtocolStruct.new(ptr) unless ptr.null?
56
- ensure
57
- endprotoent() if respond_to?(:endprotoent, true)
58
- end
67
+ if hwnd && hwnd > 0
68
+ struct = ProtocolStruct.new
69
+ size_ptr = FFI::MemoryPointer.new(:int)
70
+ size_ptr.write_int(struct.size)
71
+
72
+ handle = WSAAsyncGetProtoByName(hwnd, msg, protocol, struct, size_ptr)
59
73
 
60
- ptr.null? ? nil : struct[:p_proto]
74
+ if handle == 0
75
+ raise SystemCallError.new('WSAAsyncGetProtoByName', WSAGetLastError())
76
+ end
77
+
78
+ yield struct[:p_proto], handle
79
+ else
80
+ begin
81
+ ptr = getprotobyname_c(protocol)
82
+ struct = ProtocolStruct.new(ptr) unless ptr.null?
83
+ ensure
84
+ endprotoent() if respond_to?(:endprotoent, true)
85
+ end
86
+ ptr.null? ? nil : struct[:p_proto]
87
+ end
61
88
  end
62
89
 
63
90
  # Given a protocol number, returns the corresponding string, or nil if
@@ -68,17 +95,39 @@ module Net
68
95
  # Net::Proto.getprotobynumber(6) # => 'tcp'
69
96
  # Net::Proto.getprotobynumber(999) # => nil
70
97
  #
71
- def self.getprotobynumber(protocol)
98
+ # On MS Windows, you may also pass a window handle and a message (int)
99
+ # that window will receive. If present, this method becomes asynchronous
100
+ # and yields a block instead, with the protocol and handle.
101
+ #
102
+ # Example:
103
+ #
104
+ # Net::Proto.getprotobynumber(6, SOME_WINDOW, SOME_MSG){ |name, handle| ... }
105
+ #
106
+ def self.getprotobynumber(protocol, hwnd = 0, msg = 0)
72
107
  raise TypeError unless protocol.is_a?(Integer)
73
108
 
74
- begin
75
- ptr = getprotobynumber_c(protocol)
76
- struct = ProtocolStruct.new(ptr) unless ptr.null?
77
- ensure
78
- endprotoent() if respond_to?(:endprotoent, true)
79
- end
109
+ if hwnd && hwnd > 0
110
+ struct = ProtocolStruct.new
111
+ size_ptr = FFI::MemoryPointer.new(:int)
112
+ size_ptr.write_int(struct.size)
113
+
114
+ handle = WSAAsyncGetProtoByNumber(hwnd, msg, protocol, struct, size_ptr)
80
115
 
81
- ptr.null? ? nil: struct[:p_name]
116
+ if handle == 0
117
+ raise SystemCallError.new('WSAAsyncGetProtoByNumber', WSAGetLastError())
118
+ end
119
+
120
+ yield struct[:p_name], handle
121
+ else
122
+ begin
123
+ ptr = getprotobynumber_c(protocol)
124
+ struct = ProtocolStruct.new(ptr) unless ptr.null?
125
+ ensure
126
+ endprotoent() if respond_to?(:endprotoent, true)
127
+ end
128
+
129
+ ptr.null? ? nil: struct[:p_name]
130
+ end
82
131
  end
83
132
 
84
133
  # In block form, yields each entry from /etc/protocol as a struct of type
@@ -2,7 +2,7 @@ require 'rubygems'
2
2
 
3
3
  Gem::Specification.new do |gem|
4
4
  gem.name = 'net-proto'
5
- gem.version = '1.1.1'
5
+ gem.version = '1.2.0'
6
6
  gem.author = 'Daniel J. Berger'
7
7
  gem.license = 'Artistic 2.0'
8
8
  gem.email = 'djberg96@gmail.com'
@@ -24,7 +24,7 @@ class TC_Net_Proto < Test::Unit::TestCase
24
24
  end
25
25
 
26
26
  test "version number is set to expected value" do
27
- assert_equal('1.1.1', Net::Proto::VERSION)
27
+ assert_equal('1.2.0', Net::Proto::VERSION)
28
28
  end
29
29
 
30
30
  test "get_protocol method basic functionality" do
metadata CHANGED
@@ -1,55 +1,55 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: net-proto
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel J. Berger
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-09 00:00:00.000000000 Z
11
+ date: 2014-11-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ffi
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - '>='
18
18
  - !ruby/object:Gem::Version
19
19
  version: 1.0.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ">="
24
+ - - '>='
25
25
  - !ruby/object:Gem::Version
26
26
  version: 1.0.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: test-unit
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
31
+ - - '>='
32
32
  - !ruby/object:Gem::Version
33
33
  version: 2.2.0
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ">="
38
+ - - '>='
39
39
  - !ruby/object:Gem::Version
40
40
  version: 2.2.0
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ">="
45
+ - - '>='
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ">="
52
+ - - '>='
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  description: |2
@@ -89,17 +89,17 @@ require_paths:
89
89
  - lib
90
90
  required_ruby_version: !ruby/object:Gem::Requirement
91
91
  requirements:
92
- - - ">="
92
+ - - '>='
93
93
  - !ruby/object:Gem::Version
94
94
  version: '0'
95
95
  required_rubygems_version: !ruby/object:Gem::Requirement
96
96
  requirements:
97
- - - ">="
97
+ - - '>='
98
98
  - !ruby/object:Gem::Version
99
99
  version: '0'
100
100
  requirements: []
101
101
  rubyforge_project:
102
- rubygems_version: 2.4.1
102
+ rubygems_version: 2.4.2
103
103
  signing_key:
104
104
  specification_version: 4
105
105
  summary: A Ruby interface for determining protocol information