Module: Packet::Connection

Includes:
NbioHelper
Defined in:
lib/packet/packet_connection.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from NbioHelper

#dump_object, #gen_worker_key, #object_dump, #packet_classify, #read_data, #write_and_schedule, #write_once

Instance Attribute Details

#connectionObject

Returns the value of attribute connection.



4
5
6
# File 'lib/packet/packet_connection.rb', line 4

def connection
  @connection
end

#connection_liveObject

Returns the value of attribute connection_live.



3
4
5
# File 'lib/packet/packet_connection.rb', line 3

def connection_live
  @connection_live
end

#initializedObject

Returns the value of attribute initialized.



4
5
6
# File 'lib/packet/packet_connection.rb', line 4

def initialized
  @initialized
end

#outbound_dataObject

Returns the value of attribute outbound_data.



3
4
5
# File 'lib/packet/packet_connection.rb', line 3

def outbound_data
  @outbound_data
end

#reactorObject

Returns the value of attribute reactor.



4
5
6
# File 'lib/packet/packet_connection.rb', line 4

def reactor
  @reactor
end

#signatureObject

Returns the value of attribute signature.



4
5
6
# File 'lib/packet/packet_connection.rb', line 4

def signature
  @signature
end

#workerObject

Returns the value of attribute worker.



4
5
6
# File 'lib/packet/packet_connection.rb', line 4

def worker
  @worker
end

Instance Method Details

#add_periodic_timer(interval, &block) ⇒ Object



63
64
65
# File 'lib/packet/packet_connection.rb', line 63

def add_periodic_timer interval, &block
  reactor.add_periodic_timer(interval,&block)
end

#add_timer(t_time, &block) ⇒ Object



67
68
69
# File 'lib/packet/packet_connection.rb', line 67

def add_timer(t_time,&block)
  reactor.add_timer(t_time,&block)
end

#ask_worker(*args) ⇒ Object



47
48
49
50
51
52
53
54
# File 'lib/packet/packet_connection.rb', line 47

def ask_worker(*args)
  worker_name = args.shift
  data_options = args.last
  data_options[:client_signature] = connection.fileno
  t_worker = reactor.live_workers[worker_name]
  raise Packet::InvalidWorker.new("Invalid worker with name #{worker_name} and key #{data_options[:data][:worker_key]}") unless t_worker
  t_worker.send_request(data_options)
end

#cancel_timer(t_timer) ⇒ Object



71
72
73
# File 'lib/packet/packet_connection.rb', line 71

def cancel_timer(t_timer)
  reactor.cancel_timer(t_timer)
end

#close_connection(sock = nil) ⇒ Object



28
29
30
31
32
# File 'lib/packet/packet_connection.rb', line 28

def close_connection(sock = nil)
  unbind
  reactor.cancel_write(connection)
  reactor.remove_connection(connection)
end

#close_connection_after_writingObject



34
35
36
37
# File 'lib/packet/packet_connection.rb', line 34

def close_connection_after_writing
  connection.flush unless connection.closed?
  close_connection
end

#connect(ip, port, t_module, &block) ⇒ Object



59
60
61
# File 'lib/packet/packet_connection.rb', line 59

def connect ip,port,t_module,&block
  reactor.connect(ip,port,t_module,&block)
end

#connection_completedObject



8
# File 'lib/packet/packet_connection.rb', line 8

def connection_completed; end

#delete_worker(worker_options = {}) ⇒ Object



83
84
85
# File 'lib/packet/packet_connection.rb', line 83

def delete_worker worker_options = {}
  reactor.delete_worker(worker_options)
end

#get_peernameObject



39
40
41
# File 'lib/packet/packet_connection.rb', line 39

def get_peername
  connection.getpeername
end

#invoke_initObject



21
22
23
24
25
26
# File 'lib/packet/packet_connection.rb', line 21

def invoke_init
  @initialized = true
  @connection_live = true
  @outbound_data = []
  post_init
end

#post_initObject



9
# File 'lib/packet/packet_connection.rb', line 9

def post_init; end

#receive_data(data) ⇒ Object



10
# File 'lib/packet/packet_connection.rb', line 10

def receive_data data; end

#reconnect(server, port, handler) ⇒ Object



75
76
77
# File 'lib/packet/packet_connection.rb', line 75

def reconnect server,port,handler
  reactor.reconnect(server,port,handler)
end

#send_data(p_data) ⇒ Object



12
13
14
15
16
17
18
19
# File 'lib/packet/packet_connection.rb', line 12

def send_data p_data
  @outbound_data << p_data
  begin
    write_and_schedule(connection)
  rescue DisconnectError => sock
    close_connection
  end
end

#send_object(p_object) ⇒ Object



43
44
45
# File 'lib/packet/packet_connection.rb', line 43

def send_object p_object
  dump_object(p_object,connection)
end

#start_server(ip, port, t_module, &block) ⇒ Object



55
56
57
# File 'lib/packet/packet_connection.rb', line 55

def start_server ip,port,t_module,&block
  reactor.start_server(ip,port,t_module,&block)
end

#start_worker(worker_options = {}) ⇒ Object



79
80
81
# File 'lib/packet/packet_connection.rb', line 79

def start_worker(worker_options = {})
  reactor.start_worker(worker_options)
end

#unbindObject



7
# File 'lib/packet/packet_connection.rb', line 7

def unbind; end