[Win32utils-devel] Asynchronous Pipe::Server problems

Heesob Park phasis at gmail.com
Tue May 20 21:13:53 EDT 2008


Hi,

2008/5/21 Berger, Daniel <Daniel.Berger at qwest.com>:
>
> Hi,
>
> <snip>
>
>> >> The problem is due to the reconnect method.
>> >> The solution is define disconnect as DisconnectNamedPipe
>> >> ,close as before
>> >> and modify
>> >>
>> >>    def reconnect
>> >>       close
>> >>       mainloop
>> >>    end
>> >>
>> >> to
>> >>
>> >>    def reconnect
>> >>       disconnect
>> >>       mainloop
>> >>    end
>> >
>> > Just to clarify, we want this in pipe.rb then?
>> >
>> Yes, of course.
>>
>> > def disconnect
>> >   DisconnectNamedPipe(@pipe)
>> > end
>> >
>> > def close
>> >   CloseHandle(@pipe)
>> > end
>> >
>> close on server.rb could be
>>
>> def close
>>   FlushFileBuffers(@pipe)
>>   DisconnectNamedPipe(@pipe)
>>   CloseHandle(@pipe)
>> end
>
> Ok, I made these changes, and added the begin/ensure for a block form
> (which you can find in CVS). But, I've botched something up in the
> asynchronous server again (sorry!). I fired up the async server and
> connected with the async client and this happened.
>
> C:\Documents and Settings\djberge\workspace\win32-pipe>ruby -Ilib
> -Ilib/win32 examples\test_server_async.rb
> VERSION: 0.2.0
> pipe server is running
> pipe server is running
> connected
> read_complete
> Got [Ruby rocks!]
> pipe server is running
> write_complete
> pipe server is running
> ./lib/win32/pipe/server.rb:68:in `connect': The handle is invalid.
> (Win32::Pipe::Error)
>        from examples/test_server_async.rb:67:in `mainloop'
>        from examples/test_server_async.rb:97
>        from ./lib/win32/pipe/server.rb:35:in `initialize'
>        from examples/test_server_async.rb:96:in `new'
>        from examples/test_server_async.rb:96
>
> So, somehow the server is calling close unexpectedly. I don't think it's
> the begin/ensure code, because even after removing that I get the same
> behavior.
>
It is because the test_server_async.rb calls close method instead of disconnect.
Modify

   def write_complete
      puts "write_complete"
      close
      @state = CONNECTING_STATE
   end

to

   def write_complete
      puts "write_complete"
      disconnect
      @state = CONNECTING_STATE
   end

Regards,

Park Heesob


More information about the win32utils-devel mailing list