File: connectify.rb

package info (click to toggle)
ruby-em-socksify 0.3.1-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 168 kB
  • sloc: ruby: 256; sh: 20; makefile: 3
file content (41 lines) | stat: -rw-r--r-- 826 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
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
36
37
38
39
40
41
module EventMachine

  module Connectify
    def connectify(host, port, username=nil, password=nil, &blk)
      @connect_target_host = host
      @connect_target_port = port
      @connect_username = username
      @connect_password = password
      @connect_data = ''

      connect_hook
      connect_send_handshake

      @connect_deferrable = DefaultDeferrable.new
      @connect_deferrable.callback(&blk) if blk
      @connect_deferrable
    end

    def connect_hook
      extend CONNECT

      class << self
        alias receive_data connect_receive_data
      end
    end

    def connect_unhook
      class << self
        remove_method :receive_data
      end

      @connect_deferrable.succeed
    end

    def connect_receive_data(data)
      @connect_data << data
      connect_parse_response
    end
  end

end