dat-tcp 0.5.0 → 0.5.1
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.
- data/lib/dat-tcp/server_spy.rb +82 -0
 - data/lib/dat-tcp/version.rb +1 -1
 - metadata +5 -4
 
| 
         @@ -0,0 +1,82 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require 'dat-tcp/logger'
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            module DatTCP
         
     | 
| 
      
 4 
     | 
    
         
            +
             
     | 
| 
      
 5 
     | 
    
         
            +
              class ServerSpy
         
     | 
| 
      
 6 
     | 
    
         
            +
             
     | 
| 
      
 7 
     | 
    
         
            +
                attr_reader :ip, :port, :file_descriptor
         
     | 
| 
      
 8 
     | 
    
         
            +
                attr_reader :client_file_descriptors
         
     | 
| 
      
 9 
     | 
    
         
            +
                attr_reader :logger
         
     | 
| 
      
 10 
     | 
    
         
            +
                attr_reader :waiting_for_pause, :waiting_for_stop, :waiting_for_halt
         
     | 
| 
      
 11 
     | 
    
         
            +
                attr_accessor :listen_called, :start_called
         
     | 
| 
      
 12 
     | 
    
         
            +
                attr_accessor :stop_listen_called, :pause_called
         
     | 
| 
      
 13 
     | 
    
         
            +
                attr_accessor :stop_called, :halt_called
         
     | 
| 
      
 14 
     | 
    
         
            +
             
     | 
| 
      
 15 
     | 
    
         
            +
                attr_accessor :serve_proc
         
     | 
| 
      
 16 
     | 
    
         
            +
             
     | 
| 
      
 17 
     | 
    
         
            +
                def initialize
         
     | 
| 
      
 18 
     | 
    
         
            +
                  @ip = nil
         
     | 
| 
      
 19 
     | 
    
         
            +
                  @port = nil
         
     | 
| 
      
 20 
     | 
    
         
            +
                  @file_descriptor = nil
         
     | 
| 
      
 21 
     | 
    
         
            +
                  @client_file_descriptors = []
         
     | 
| 
      
 22 
     | 
    
         
            +
                  @logger = DatTCP::Logger::Null.new
         
     | 
| 
      
 23 
     | 
    
         
            +
             
     | 
| 
      
 24 
     | 
    
         
            +
                  @waiting_for_pause = nil
         
     | 
| 
      
 25 
     | 
    
         
            +
                  @waiting_for_stop = nil
         
     | 
| 
      
 26 
     | 
    
         
            +
                  @waiting_for_hale = nil
         
     | 
| 
      
 27 
     | 
    
         
            +
             
     | 
| 
      
 28 
     | 
    
         
            +
                  @listen_called = false
         
     | 
| 
      
 29 
     | 
    
         
            +
                  @stop_listen_called = false
         
     | 
| 
      
 30 
     | 
    
         
            +
                  @start_called = false
         
     | 
| 
      
 31 
     | 
    
         
            +
                  @pause_called = false
         
     | 
| 
      
 32 
     | 
    
         
            +
                  @stop_called = false
         
     | 
| 
      
 33 
     | 
    
         
            +
                  @halt_called = false
         
     | 
| 
      
 34 
     | 
    
         
            +
             
     | 
| 
      
 35 
     | 
    
         
            +
                  @serve_proc = proc{ }
         
     | 
| 
      
 36 
     | 
    
         
            +
                end
         
     | 
| 
      
 37 
     | 
    
         
            +
             
     | 
| 
      
 38 
     | 
    
         
            +
                def listening?
         
     | 
| 
      
 39 
     | 
    
         
            +
                  @listen_called && !@stop_listen_called
         
     | 
| 
      
 40 
     | 
    
         
            +
                end
         
     | 
| 
      
 41 
     | 
    
         
            +
             
     | 
| 
      
 42 
     | 
    
         
            +
                def running?
         
     | 
| 
      
 43 
     | 
    
         
            +
                  @start_called && !(@pause_called || @stop_called || @halt_called)
         
     | 
| 
      
 44 
     | 
    
         
            +
                end
         
     | 
| 
      
 45 
     | 
    
         
            +
             
     | 
| 
      
 46 
     | 
    
         
            +
                def listen(*args)
         
     | 
| 
      
 47 
     | 
    
         
            +
                  case args.size
         
     | 
| 
      
 48 
     | 
    
         
            +
                  when 2
         
     | 
| 
      
 49 
     | 
    
         
            +
                    @ip, @port = args
         
     | 
| 
      
 50 
     | 
    
         
            +
                  when 1
         
     | 
| 
      
 51 
     | 
    
         
            +
                    @file_descriptor = args.first
         
     | 
| 
      
 52 
     | 
    
         
            +
                  end
         
     | 
| 
      
 53 
     | 
    
         
            +
                  @listen_called = true
         
     | 
| 
      
 54 
     | 
    
         
            +
                end
         
     | 
| 
      
 55 
     | 
    
         
            +
             
     | 
| 
      
 56 
     | 
    
         
            +
                def stop_listen
         
     | 
| 
      
 57 
     | 
    
         
            +
                  @stop_listen_called = true
         
     | 
| 
      
 58 
     | 
    
         
            +
                end
         
     | 
| 
      
 59 
     | 
    
         
            +
             
     | 
| 
      
 60 
     | 
    
         
            +
                def start(client_file_descriptors = nil)
         
     | 
| 
      
 61 
     | 
    
         
            +
                  @client_file_descriptors = client_file_descriptors || []
         
     | 
| 
      
 62 
     | 
    
         
            +
                  @start_called = true
         
     | 
| 
      
 63 
     | 
    
         
            +
                end
         
     | 
| 
      
 64 
     | 
    
         
            +
             
     | 
| 
      
 65 
     | 
    
         
            +
                def pause(wait = false)
         
     | 
| 
      
 66 
     | 
    
         
            +
                  @waiting_for_pause = wait
         
     | 
| 
      
 67 
     | 
    
         
            +
                  @pause_called = true
         
     | 
| 
      
 68 
     | 
    
         
            +
                end
         
     | 
| 
      
 69 
     | 
    
         
            +
             
     | 
| 
      
 70 
     | 
    
         
            +
                def stop(wait = false)
         
     | 
| 
      
 71 
     | 
    
         
            +
                  @waiting_for_stop = wait
         
     | 
| 
      
 72 
     | 
    
         
            +
                  @stop_called = true
         
     | 
| 
      
 73 
     | 
    
         
            +
                end
         
     | 
| 
      
 74 
     | 
    
         
            +
             
     | 
| 
      
 75 
     | 
    
         
            +
                def halt(wait = false)
         
     | 
| 
      
 76 
     | 
    
         
            +
                  @waiting_for_halt = wait
         
     | 
| 
      
 77 
     | 
    
         
            +
                  @halt_called = true
         
     | 
| 
      
 78 
     | 
    
         
            +
                end
         
     | 
| 
      
 79 
     | 
    
         
            +
             
     | 
| 
      
 80 
     | 
    
         
            +
              end
         
     | 
| 
      
 81 
     | 
    
         
            +
             
     | 
| 
      
 82 
     | 
    
         
            +
            end
         
     | 
    
        data/lib/dat-tcp/version.rb
    CHANGED
    
    
    
        metadata
    CHANGED
    
    | 
         @@ -1,13 +1,13 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification 
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: dat-tcp
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version 
         
     | 
| 
       4 
     | 
    
         
            -
              hash:  
     | 
| 
      
 4 
     | 
    
         
            +
              hash: 9
         
     | 
| 
       5 
5 
     | 
    
         
             
              prerelease: 
         
     | 
| 
       6 
6 
     | 
    
         
             
              segments: 
         
     | 
| 
       7 
7 
     | 
    
         
             
              - 0
         
     | 
| 
       8 
8 
     | 
    
         
             
              - 5
         
     | 
| 
       9 
     | 
    
         
            -
              -  
     | 
| 
       10 
     | 
    
         
            -
              version: 0.5. 
     | 
| 
      
 9 
     | 
    
         
            +
              - 1
         
     | 
| 
      
 10 
     | 
    
         
            +
              version: 0.5.1
         
     | 
| 
       11 
11 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       12 
12 
     | 
    
         
             
            authors: 
         
     | 
| 
       13 
13 
     | 
    
         
             
            - Collin Redding
         
     | 
| 
         @@ -16,7 +16,7 @@ autorequire: 
     | 
|
| 
       16 
16 
     | 
    
         
             
            bindir: bin
         
     | 
| 
       17 
17 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       18 
18 
     | 
    
         | 
| 
       19 
     | 
    
         
            -
            date: 2014-06- 
     | 
| 
      
 19 
     | 
    
         
            +
            date: 2014-06-27 00:00:00 Z
         
     | 
| 
       20 
20 
     | 
    
         
             
            dependencies: 
         
     | 
| 
       21 
21 
     | 
    
         
             
            - !ruby/object:Gem::Dependency 
         
     | 
| 
       22 
22 
     | 
    
         
             
              requirement: &id001 !ruby/object:Gem::Requirement 
         
     | 
| 
         @@ -64,6 +64,7 @@ files: 
     | 
|
| 
       64 
64 
     | 
    
         
             
            - dat-tcp.gemspec
         
     | 
| 
       65 
65 
     | 
    
         
             
            - lib/dat-tcp.rb
         
     | 
| 
       66 
66 
     | 
    
         
             
            - lib/dat-tcp/logger.rb
         
     | 
| 
      
 67 
     | 
    
         
            +
            - lib/dat-tcp/server_spy.rb
         
     | 
| 
       67 
68 
     | 
    
         
             
            - lib/dat-tcp/version.rb
         
     | 
| 
       68 
69 
     | 
    
         
             
            homepage: https://github.com/redding/dat-tcp
         
     | 
| 
       69 
70 
     | 
    
         
             
            licenses: 
         
     |