win32-pipe 0.2.2 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +51 -46
- data/MANIFEST +17 -15
- data/README +52 -55
- data/Rakefile +68 -48
- data/examples/example_client.rb +29 -29
- data/examples/example_client_async.rb +82 -82
- data/examples/example_server.rb +32 -32
- data/examples/example_server_async.rb +100 -100
- data/lib/win32/pipe.rb +251 -254
- data/lib/win32/pipe/client.rb +65 -65
- data/lib/win32/pipe/server.rb +96 -96
- data/lib/win32/pipe/windows/constants.rb +37 -0
- data/lib/win32/pipe/windows/functions.rb +31 -0
- data/test/test_win32_pipe.rb +162 -126
- data/test/test_win32_pipe_client.rb +62 -60
- data/test/test_win32_pipe_server.rb +34 -34
- data/win32-pipe.gemspec +25 -25
- metadata +22 -10
data/CHANGES
CHANGED
@@ -1,46 +1,51 @@
|
|
1
|
-
== 0.
|
2
|
-
*
|
3
|
-
*
|
4
|
-
*
|
5
|
-
|
6
|
-
== 0.2.
|
7
|
-
*
|
8
|
-
*
|
9
|
-
*
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
*
|
15
|
-
*
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
*
|
20
|
-
*
|
21
|
-
|
22
|
-
*
|
23
|
-
|
24
|
-
*
|
25
|
-
*
|
26
|
-
*
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
*
|
31
|
-
*
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
* Moved the
|
36
|
-
*
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
*
|
42
|
-
*
|
43
|
-
|
44
|
-
|
45
|
-
== 0.0
|
46
|
-
*
|
1
|
+
== 0.3.0 - 8-Sep-2012
|
2
|
+
* Converted to FFI. Now works with JRuby, too.
|
3
|
+
* Native errors are now raised as SystemCallErrors.
|
4
|
+
* Test updates, gemspec dependency updates, etc.
|
5
|
+
|
6
|
+
== 0.2.2 - 19-Mar-2012
|
7
|
+
* Added test-unit 2.x as a development dependency.
|
8
|
+
* Refactored some tests to use features of test-unit 2.x.
|
9
|
+
* Refactored the Rakefile.
|
10
|
+
|
11
|
+
== 0.2.1 - 9-Aug-2009
|
12
|
+
* License changed to Artistic 2.0.
|
13
|
+
* Test and example files renamed.
|
14
|
+
* Gemspec updates, including license and description.
|
15
|
+
* Updates to the Rakefile, including the removal of old C rake tasks, as
|
16
|
+
well as the addition of tasks to run the example programs.
|
17
|
+
|
18
|
+
== 0.2.0 - 28-May-2008
|
19
|
+
* Now pure Ruby.
|
20
|
+
* Major interface change. Pipe::Server.new and Pipe::Client.new replace the
|
21
|
+
Pipe.new_server and Pipe.new_client methods, respectively.
|
22
|
+
* An optional 3rd argument, the open mode, is now accepted which allows finer
|
23
|
+
control over how pipes are created.
|
24
|
+
* Several pipe mode and open mode constants were added.
|
25
|
+
* The asynchronous pipe server actually works now.
|
26
|
+
* Added the Pipe#name method.
|
27
|
+
* Added the Pipe#asynchronous? method.
|
28
|
+
* Added the Pipe#size method as an alias for Pipe#length.
|
29
|
+
* Added a Rakefile with tasks for testing and installation.
|
30
|
+
* Added a gemspec and uploaded a gem file to RubyForge.
|
31
|
+
* Merged the doc files into the README and/or replaced them with inlined
|
32
|
+
comments that are RDoc friendly.
|
33
|
+
|
34
|
+
== 0.1.2 - 1-Mar-2005
|
35
|
+
* Moved the 'examples' directory to the toplevel directory.
|
36
|
+
* Made the CHANGES and README files rdoc friendly.
|
37
|
+
|
38
|
+
== 0.1.1 - 25-Aug-2004
|
39
|
+
* Added many more tests to the test suite.
|
40
|
+
* Moved the example programs to doc/examples.
|
41
|
+
* Fixed minor bugs in the asynchronous client and server test programs.
|
42
|
+
* Removed the pipe.html file. You can generate your own html documentation
|
43
|
+
using rd2 on the pipe.rd file.
|
44
|
+
|
45
|
+
== 0.1.0 - 13-Feb-2004
|
46
|
+
* Asynchronous support added (thanks Park Heesob)
|
47
|
+
* Sample test programs added. See files under 'test'.
|
48
|
+
* Documentation updates.
|
49
|
+
|
50
|
+
== 0.0.1 - 20-Nov-2003
|
51
|
+
* Initial release
|
data/MANIFEST
CHANGED
@@ -1,15 +1,17 @@
|
|
1
|
-
* MANIFEST
|
2
|
-
* README
|
3
|
-
* CHANGES
|
4
|
-
* Rakefile
|
5
|
-
* win32-pipe.gemspec
|
6
|
-
* examples/example_server.rb
|
7
|
-
* examples/example_server_async.rb
|
8
|
-
* examples/example_client.rb
|
9
|
-
* examples/example_client_async.rb
|
10
|
-
* lib/win32/pipe.rb
|
11
|
-
* lib/win32/pipe/client.rb
|
12
|
-
* lib/win32/pipe/server.rb
|
13
|
-
*
|
14
|
-
*
|
15
|
-
* test/
|
1
|
+
* MANIFEST
|
2
|
+
* README
|
3
|
+
* CHANGES
|
4
|
+
* Rakefile
|
5
|
+
* win32-pipe.gemspec
|
6
|
+
* examples/example_server.rb
|
7
|
+
* examples/example_server_async.rb
|
8
|
+
* examples/example_client.rb
|
9
|
+
* examples/example_client_async.rb
|
10
|
+
* lib/win32/pipe.rb
|
11
|
+
* lib/win32/pipe/client.rb
|
12
|
+
* lib/win32/pipe/server.rb
|
13
|
+
* lib/win32/pipe/windows/constants.rb
|
14
|
+
* lib/win32/pipe/windows/functions.rb
|
15
|
+
* test/test_win32_pipe.rb
|
16
|
+
* test/test_win32_pipe_client.rb
|
17
|
+
* test/test_win32_pipe_server.rb
|
data/README
CHANGED
@@ -1,55 +1,52 @@
|
|
1
|
-
== Description
|
2
|
-
|
3
|
-
|
4
|
-
== Prerequisites
|
5
|
-
|
6
|
-
|
7
|
-
== Installation
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
==
|
40
|
-
|
41
|
-
|
42
|
-
==
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
==
|
51
|
-
|
52
|
-
|
53
|
-
== Authors
|
54
|
-
Daniel Berger
|
55
|
-
Park Heesob
|
1
|
+
== Description
|
2
|
+
A Ruby interface for named pipes on Windows.
|
3
|
+
|
4
|
+
== Prerequisites
|
5
|
+
ffi
|
6
|
+
|
7
|
+
== Installation
|
8
|
+
gem install win32-pipe
|
9
|
+
|
10
|
+
== Synopsis
|
11
|
+
require 'win32/pipe'
|
12
|
+
include Win32
|
13
|
+
|
14
|
+
# In server.rb
|
15
|
+
pipe_server = Pipe::Server.new("foo_pipe")
|
16
|
+
pipe_server.connect
|
17
|
+
data = pipe_server.read
|
18
|
+
puts "Got #{data} from client"
|
19
|
+
pipe_server.close
|
20
|
+
|
21
|
+
# In client.rb (run from a different shell)
|
22
|
+
pipe_client = Pipe::Client.new("foo_pipe")
|
23
|
+
pipe_client.write("Hello World")
|
24
|
+
pipe_client.close
|
25
|
+
|
26
|
+
== What's a named pipe?
|
27
|
+
A pipe with a name - literally. In practice, it will feel more like a cross
|
28
|
+
between a socket and a pipe. At least, it does to me.
|
29
|
+
|
30
|
+
== What good is it?
|
31
|
+
My hope is that it can be used in certain circumstances where a fork might
|
32
|
+
be desirable, but which is not possible on Windows. It could also be handy
|
33
|
+
for the traditional "piping data to a server" usage. And if you come up
|
34
|
+
with anything cool, please let us all know!
|
35
|
+
|
36
|
+
== Future Plans
|
37
|
+
Add transactions
|
38
|
+
|
39
|
+
== License
|
40
|
+
Artistic 2.0
|
41
|
+
|
42
|
+
== Warranty
|
43
|
+
This package is provided "as is" and without any express or
|
44
|
+
implied warranties, including, without limitation, the implied
|
45
|
+
warranties of merchantability and fitness for a particular purpose.
|
46
|
+
|
47
|
+
== Copyright
|
48
|
+
(C) 2003-2012, Daniel J. Berger, All Rights Reserved.
|
49
|
+
|
50
|
+
== Authors
|
51
|
+
Daniel Berger
|
52
|
+
Park Heesob
|
data/Rakefile
CHANGED
@@ -1,48 +1,68 @@
|
|
1
|
-
require 'rake'
|
2
|
-
require 'rake/clean'
|
3
|
-
require 'rake/testtask'
|
4
|
-
|
5
|
-
CLEAN.include("**/*.gem")
|
6
|
-
|
7
|
-
namespace :gem do
|
8
|
-
desc 'Create the win32-pipe gem'
|
9
|
-
task :create => [:clean] do
|
10
|
-
spec = eval(IO.read('win32-pipe.gemspec'))
|
11
|
-
Gem::Builder.new(spec).build
|
12
|
-
end
|
13
|
-
|
14
|
-
desc 'Install the win32-pipe gem'
|
15
|
-
task :install => [:create] do
|
16
|
-
file = Dir['*.gem'].first
|
17
|
-
sh "gem install #{file}"
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
namespace :example do
|
22
|
-
desc 'Run the asynchronous client example program'
|
23
|
-
task :async_client do
|
24
|
-
ruby '-Ilib examples/example_client_async.rb'
|
25
|
-
end
|
26
|
-
|
27
|
-
desc 'Run the client example program'
|
28
|
-
task :client do
|
29
|
-
ruby '-Ilib examples/example_client.rb'
|
30
|
-
end
|
31
|
-
|
32
|
-
desc 'Run the asynchronous server example program'
|
33
|
-
task :async_server do
|
34
|
-
ruby '-Ilib examples/example_server_async.rb'
|
35
|
-
end
|
36
|
-
|
37
|
-
desc 'Run the server example program'
|
38
|
-
task :server do
|
39
|
-
ruby '-Ilib examples/example_server.rb'
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
1
|
+
require 'rake'
|
2
|
+
require 'rake/clean'
|
3
|
+
require 'rake/testtask'
|
4
|
+
|
5
|
+
CLEAN.include("**/*.gem")
|
6
|
+
|
7
|
+
namespace :gem do
|
8
|
+
desc 'Create the win32-pipe gem'
|
9
|
+
task :create => [:clean] do
|
10
|
+
spec = eval(IO.read('win32-pipe.gemspec'))
|
11
|
+
Gem::Builder.new(spec).build
|
12
|
+
end
|
13
|
+
|
14
|
+
desc 'Install the win32-pipe gem'
|
15
|
+
task :install => [:create] do
|
16
|
+
file = Dir['*.gem'].first
|
17
|
+
sh "gem install #{file}"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
namespace :example do
|
22
|
+
desc 'Run the asynchronous client example program'
|
23
|
+
task :async_client do
|
24
|
+
ruby '-Ilib examples/example_client_async.rb'
|
25
|
+
end
|
26
|
+
|
27
|
+
desc 'Run the client example program'
|
28
|
+
task :client do
|
29
|
+
ruby '-Ilib examples/example_client.rb'
|
30
|
+
end
|
31
|
+
|
32
|
+
desc 'Run the asynchronous server example program'
|
33
|
+
task :async_server do
|
34
|
+
ruby '-Ilib examples/example_server_async.rb'
|
35
|
+
end
|
36
|
+
|
37
|
+
desc 'Run the server example program'
|
38
|
+
task :server do
|
39
|
+
ruby '-Ilib examples/example_server.rb'
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
namespace :test do
|
44
|
+
Rake::TestTask.new(:base) do |test|
|
45
|
+
test.warning = true
|
46
|
+
test.verbose = true
|
47
|
+
test.test_files = FileList['test\test_win32_pipe.rb']
|
48
|
+
end
|
49
|
+
|
50
|
+
Rake::TestTask.new(:client) do |test|
|
51
|
+
test.warning = true
|
52
|
+
test.verbose = true
|
53
|
+
test.test_files = FileList['test\test_win32_pipe_client.rb']
|
54
|
+
end
|
55
|
+
|
56
|
+
Rake::TestTask.new(:server) do |test|
|
57
|
+
test.warning = true
|
58
|
+
test.verbose = true
|
59
|
+
test.test_files = FileList['test\test_win32_pipe_server.rb']
|
60
|
+
end
|
61
|
+
|
62
|
+
Rake::TestTask.new(:all) do |test|
|
63
|
+
test.warning = true
|
64
|
+
test.verbose = true
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
task :default => 'test:all'
|
data/examples/example_client.rb
CHANGED
@@ -1,30 +1,30 @@
|
|
1
|
-
#########################################################################
|
2
|
-
# example_client.rb
|
3
|
-
#
|
4
|
-
# Simple client test. Be sure to start the server first in a separate
|
5
|
-
# terminal. You can run this example via the 'rake example_client' task.
|
6
|
-
#
|
7
|
-
# Modify this code as you see fit.
|
8
|
-
#########################################################################
|
9
|
-
require 'win32/pipe'
|
10
|
-
include Win32
|
11
|
-
|
12
|
-
Thread.new { loop { sleep 0.01 } } # Allow Ctrl-C
|
13
|
-
|
14
|
-
puts "VERSION: " + Pipe::VERSION
|
15
|
-
|
16
|
-
# Block form
|
17
|
-
Pipe::Client.new('foo') do |pipe|
|
18
|
-
puts "Connected..."
|
19
|
-
pipe.write("Ruby rocks!")
|
20
|
-
data = pipe.read
|
21
|
-
puts "Got [#{data}] back from server"
|
22
|
-
end
|
23
|
-
|
24
|
-
# Non-block form
|
25
|
-
#pclient = Pipe::Client.new('foo')
|
26
|
-
#puts "Connected..."
|
27
|
-
#pclient.write("Ruby rocks!")
|
28
|
-
#data = pclient.read
|
29
|
-
#puts "Got [#{data}] back from server"
|
1
|
+
#########################################################################
|
2
|
+
# example_client.rb
|
3
|
+
#
|
4
|
+
# Simple client test. Be sure to start the server first in a separate
|
5
|
+
# terminal. You can run this example via the 'rake example_client' task.
|
6
|
+
#
|
7
|
+
# Modify this code as you see fit.
|
8
|
+
#########################################################################
|
9
|
+
require 'win32/pipe'
|
10
|
+
include Win32
|
11
|
+
|
12
|
+
Thread.new { loop { sleep 0.01 } } # Allow Ctrl-C
|
13
|
+
|
14
|
+
puts "VERSION: " + Pipe::VERSION
|
15
|
+
|
16
|
+
# Block form
|
17
|
+
Pipe::Client.new('foo') do |pipe|
|
18
|
+
puts "Connected..."
|
19
|
+
pipe.write("Ruby rocks!")
|
20
|
+
data = pipe.read
|
21
|
+
puts "Got [#{data}] back from server"
|
22
|
+
end
|
23
|
+
|
24
|
+
# Non-block form
|
25
|
+
#pclient = Pipe::Client.new('foo')
|
26
|
+
#puts "Connected..."
|
27
|
+
#pclient.write("Ruby rocks!")
|
28
|
+
#data = pclient.read
|
29
|
+
#puts "Got [#{data}] back from server"
|
30
30
|
#pclient.close
|
@@ -1,82 +1,82 @@
|
|
1
|
-
#########################################################################
|
2
|
-
# example_client_async.rb
|
3
|
-
#
|
4
|
-
# Simple client test. Be sure to start the server first in a separate
|
5
|
-
# terminal. You can run this example via the 'rake example_async_client'
|
6
|
-
# task.
|
7
|
-
#########################################################################
|
8
|
-
require 'win32/pipe'
|
9
|
-
include Win32
|
10
|
-
|
11
|
-
puts "VERSION: " + Pipe::VERSION
|
12
|
-
|
13
|
-
Thread.new { loop { sleep 0.01 } } # Allow Ctrl-C
|
14
|
-
|
15
|
-
CONNECTING_STATE = 0
|
16
|
-
READING_STATE = 1
|
17
|
-
WRITING_STATE = 2
|
18
|
-
|
19
|
-
class MyPipe < Pipe::Client
|
20
|
-
def read_complete
|
21
|
-
puts "read_complete"
|
22
|
-
puts "Got [#{buffer}] back from server"
|
23
|
-
@state = WRITING_STATE
|
24
|
-
end
|
25
|
-
|
26
|
-
def write_complete
|
27
|
-
puts "write_complete"
|
28
|
-
@state = READING_STATE
|
29
|
-
end
|
30
|
-
|
31
|
-
def mainloop
|
32
|
-
@state = WRITING_STATE
|
33
|
-
while true
|
34
|
-
if wait(1) # wait for 1 second
|
35
|
-
if pending? # IO is pending
|
36
|
-
case @state
|
37
|
-
when READING_STATE
|
38
|
-
if transferred == 0
|
39
|
-
reconnect
|
40
|
-
break
|
41
|
-
end
|
42
|
-
read_complete
|
43
|
-
break
|
44
|
-
when WRITING_STATE
|
45
|
-
if transferred != length
|
46
|
-
reconnect
|
47
|
-
break
|
48
|
-
end
|
49
|
-
write_complete
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
case @state
|
54
|
-
when READING_STATE
|
55
|
-
if read
|
56
|
-
if not pending?
|
57
|
-
read_complete
|
58
|
-
break
|
59
|
-
end
|
60
|
-
end
|
61
|
-
when WRITING_STATE
|
62
|
-
if write("Ruby rocks!")
|
63
|
-
if not pending?
|
64
|
-
write_complete
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
sleep(1)
|
71
|
-
puts "pipe client is running"
|
72
|
-
end
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
flags = Pipe::DEFAULT_OPEN_MODE | Pipe::OVERLAPPED
|
77
|
-
|
78
|
-
MyPipe.new('foo', nil, flags) do |client|
|
79
|
-
puts "Connected..."
|
80
|
-
client.mainloop
|
81
|
-
end
|
82
|
-
|
1
|
+
#########################################################################
|
2
|
+
# example_client_async.rb
|
3
|
+
#
|
4
|
+
# Simple client test. Be sure to start the server first in a separate
|
5
|
+
# terminal. You can run this example via the 'rake example_async_client'
|
6
|
+
# task.
|
7
|
+
#########################################################################
|
8
|
+
require 'win32/pipe'
|
9
|
+
include Win32
|
10
|
+
|
11
|
+
puts "VERSION: " + Pipe::VERSION
|
12
|
+
|
13
|
+
Thread.new { loop { sleep 0.01 } } # Allow Ctrl-C
|
14
|
+
|
15
|
+
CONNECTING_STATE = 0
|
16
|
+
READING_STATE = 1
|
17
|
+
WRITING_STATE = 2
|
18
|
+
|
19
|
+
class MyPipe < Pipe::Client
|
20
|
+
def read_complete
|
21
|
+
puts "read_complete"
|
22
|
+
puts "Got [#{buffer}] back from server"
|
23
|
+
@state = WRITING_STATE
|
24
|
+
end
|
25
|
+
|
26
|
+
def write_complete
|
27
|
+
puts "write_complete"
|
28
|
+
@state = READING_STATE
|
29
|
+
end
|
30
|
+
|
31
|
+
def mainloop
|
32
|
+
@state = WRITING_STATE
|
33
|
+
while true
|
34
|
+
if wait(1) # wait for 1 second
|
35
|
+
if pending? # IO is pending
|
36
|
+
case @state
|
37
|
+
when READING_STATE
|
38
|
+
if transferred == 0
|
39
|
+
reconnect
|
40
|
+
break
|
41
|
+
end
|
42
|
+
read_complete
|
43
|
+
break
|
44
|
+
when WRITING_STATE
|
45
|
+
if transferred != length
|
46
|
+
reconnect
|
47
|
+
break
|
48
|
+
end
|
49
|
+
write_complete
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
case @state
|
54
|
+
when READING_STATE
|
55
|
+
if read
|
56
|
+
if not pending?
|
57
|
+
read_complete
|
58
|
+
break
|
59
|
+
end
|
60
|
+
end
|
61
|
+
when WRITING_STATE
|
62
|
+
if write("Ruby rocks!")
|
63
|
+
if not pending?
|
64
|
+
write_complete
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
sleep(1)
|
71
|
+
puts "pipe client is running"
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
flags = Pipe::DEFAULT_OPEN_MODE | Pipe::OVERLAPPED
|
77
|
+
|
78
|
+
MyPipe.new('foo', nil, flags) do |client|
|
79
|
+
puts "Connected..."
|
80
|
+
client.mainloop
|
81
|
+
end
|
82
|
+
|