networking 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -13,7 +13,7 @@ module Networking
13
13
  Log.debug2("Writing data size: #{marshal_data.length}")
14
14
  data_size = [marshal_data.length].pack("l")
15
15
  if data_size.nil? || marshal_data.nil?
16
- Log.debug3 'Send data size is nil!'
16
+ Log.debug2 'Send data size is nil!'
17
17
  end
18
18
  begin
19
19
  bytes_written = stream.write data_size
@@ -49,7 +49,7 @@ module Networking
49
49
  end
50
50
 
51
51
  unmarshalled_data = Marshal.load(data)
52
- Log.debug3('Read good.')
52
+ Log.debug2('Read good.')
53
53
  return [true, unmarshalled_data]
54
54
  end
55
55
 
@@ -71,7 +71,7 @@ module Networking
71
71
  end
72
72
 
73
73
  def send_obj(obj, addr_info=nil)
74
- Log.debug3("addr_info=#{addr_info}")
74
+ Log.debug3("send_obj with addr_info:#{addr_info}")
75
75
  unless addr_info.nil?
76
76
  if @sockets.key?(addr_info)
77
77
  Networking.write_to_stream(@sockets[addr_info], obj)
@@ -91,19 +91,18 @@ module Networking
91
91
  def run_server
92
92
  Log.debug3('run_server')
93
93
  return Thread.new do
94
- Log.debug3('run_server2')
95
94
  loop {
96
95
  begin
97
96
  Socket.tcp_server_loop(@port) do |sock, addr_info|
98
- Log.debug3("----- #{@port} -----")
99
- Log.debug3("tcp_server_loop... #{sock} #{addr_info.inspect}")
97
+ Log.debug2("----- #{@port} -----")
98
+ Log.debug2("tcp_server_loop... #{sock} #{addr_info.inspect}")
100
99
  @sockets[addr_info] = sock
101
100
  @new_clb.call(addr_info) if @new_clb != nil
102
101
  loop do
103
102
  # Blocking read.
104
- Log.debug3('read_from_stream')
103
+ Log.debug2('read_from_stream')
105
104
  stream_ok, obj = Networking.read_from_stream(sock)
106
- Log.debug3("Server returned from read: #{stream_ok}")
105
+ Log.debug2("Server returned from read: #{stream_ok}")
107
106
  @obj_clb.call(addr_info, obj) if @obj_clb != nil && stream_ok
108
107
  break if !stream_ok
109
108
  end
@@ -120,7 +119,7 @@ module Networking
120
119
  # and if it ends, it will fail, and rescue will work.
121
120
  break
122
121
  rescue IOError => e
123
- Log.info("Connection broken during tcp_server_loop. Restarting server loop " \
122
+ Log.warning("Connection broken during tcp_server_loop. Restarting server loop " \
124
123
  "port:#{port}.")
125
124
  end
126
125
  }
@@ -137,8 +136,7 @@ module Networking
137
136
  @tcp_socket = nil
138
137
  @obj_clb = obj_clb
139
138
  @reconnected_clb = reconnected_clb
140
- Log.debug1('TCPClient init.')
141
- Log.debug1("TCPClient init...#{@obj_clb}...")
139
+ Log.debug3("Start TCPClient initialize with @obj_clb: #{@obj_clb}")
142
140
  if @obj_clb != nil
143
141
  @tcp_thread = start_reading
144
142
  @tcp_thread.abort_on_exception = true
@@ -147,6 +145,7 @@ module Networking
147
145
  @remote_server_available = ConditionVariable.new
148
146
  @remote_server_available_mutex = Mutex.new
149
147
  open_socket unless socket_good?
148
+ Log.debug3("End TCPClient initialize.")
150
149
  end
151
150
 
152
151
  def send_obj(obj)
@@ -157,8 +156,7 @@ module Networking
157
156
  Log.warning('Socket not opened for writing, skipping send.')
158
157
  return false
159
158
  end
160
- Log.debug1('writing...')
161
- #Log.debug3("socket port: #{@tcp_socket.peeraddr}")
159
+ Log.debug2("writing... socket port: #{@tcp_socket.peeraddr}")
162
160
  bytes_written = Networking.write_to_stream(@tcp_socket, obj)
163
161
  return bytes_written
164
162
  end
@@ -172,7 +170,7 @@ module Networking
172
170
  rescue Errno::ECONNREFUSED
173
171
  Log.warning('Connection refused')
174
172
  end
175
- Log.debug1("Reconnect clb: '#{@reconnected_clb.nil? ? 'nil' : @reconnected_clb}'")
173
+ Log.debug3("Reconnect clb: '#{@reconnected_clb.nil? ? 'nil' : @reconnected_clb}'")
176
174
  if socket_good?
177
175
  @remote_server_available_mutex.synchronize {
178
176
  @remote_server_available.signal
@@ -183,13 +181,12 @@ module Networking
183
181
 
184
182
  private
185
183
  def socket_good?
186
- Log.debug1 "socket_good? #{@tcp_socket != nil && !@tcp_socket.closed?}"
184
+ Log.debug3("socket_good? #{@tcp_socket != nil && !@tcp_socket.closed?}")
187
185
  return @tcp_socket != nil && !@tcp_socket.closed?
188
186
  end
189
187
 
190
188
  private
191
189
  def start_reading
192
- Log.debug1('start_reading (TCPClient).')
193
190
  return Thread.new do
194
191
  loop do
195
192
  Log.debug3('Start blocking read (TCPClient).')
@@ -1,3 +1,3 @@
1
1
  module Networking
2
- VERSION = "1.0.0"
2
+ VERSION = "1.0.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: networking
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-05-01 00:00:00.000000000 Z
12
+ date: 2013-05-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: params