[Win32utils-devel] Asynchronous Pipe::Server problems
Daniel Berger
djberg96 at gmail.com
Mon May 19 21:54:14 EDT 2008
Hi all,
I've been working on the win32-pipe library (again) and I've reworked
the interface. Instead of Pipe.new_server or Pipe.new_client, there's
now a base Pipe class, with Pipe::Server and Pipe::Client subclasses.
You can find the latest code in the CVS repo.
Oh, and you'll need to update your windows-pr library with the latest
from CVS if you want to use this. I had to add some missing pipe related
error constants to the Windows::Pipe module. These will be included in
windows-pr 0.8.5.
Anyway, I've got the synchronous mode working alright. Unfortunately, I
can't get the asynchronous server to work. When I try to run the
test_server_async.rb code (in CVS) I get this:
VERSION: 0.2.0
win32-pipe/lib/win32/pipe/server.rb:69:in `connect': Waiting for a
process to open the other end of the pipe. (Win32::Pipe::Error)
from test_server_async.rb:70:in `mainloop'
from test_server_async.rb:101
Any ideas?
Here's the code, btw:
# test_server_async.rb
require 'win32/pipe'
include Win32
puts "VERSION: " + Pipe::VERSION
Thread.new { loop { sleep 0.01 } } # Allow Ctrl-C
CONNECTING_STATE = 0
READING_STATE = 1
WRITING_STATE = 2
class MyPipe < Pipe::Server
def connected
puts "connected"
@state = READING_STATE
end
def read_complete
puts "read_complete"
puts "Got [#{buffer}]"
@state = WRITING_STATE
end
def write_complete
puts "write_complete"
close
@state = CONNECTING_STATE
end
def reconnect
close
mainloop
end
def mainloop
@state = CONNECTING_STATE
while true
if wait(1) # wait for 1 second
if pending? # IO is pending
case @state
when CONNECTING_STATE
connected
when READING_STATE
if transferred == 0
reconnect
break
end
read_complete
when WRITING_STATE
if transferred != length
reconnect
break
end
write_complete
end
end
case @state
when CONNECTING_STATE
if connect
connected
end
when READING_STATE
if read
if not pending?
read_complete
end
else
reconnect
end
when WRITING_STATE
if write("Thanks for the data!")
if not pending?
write_complete
end
else
reconnect
break
end
end
end
sleep(1)
puts "pipe server is running"
end
end
end
pserver = MyPipe.new('foo', true)
pserver.mainloop
pserver.close
More information about the win32utils-devel
mailing list