@@ -57,22 +57,22 @@ def request_handler(client, packet)
57
57
cid = packet . get_tlv_value ( TLV_TYPE_CHANNEL_ID )
58
58
59
59
# No channel identifier, then drop it
60
- if ( cid == nil )
60
+ if cid . nil?
61
61
return false
62
62
end
63
63
64
64
channel = client . find_channel ( cid )
65
65
66
66
# No valid channel context? The channel may not be registered yet
67
- if ( channel == nil )
67
+ if channel . nil?
68
68
return false
69
69
end
70
70
71
71
72
72
dio = channel . dio_map ( packet . method )
73
73
74
74
# Supported DIO request? Dump it.
75
- if ( dio == nil )
75
+ if dio . nil?
76
76
return true
77
77
end
78
78
@@ -98,12 +98,12 @@ def Channel.create(client, type = nil, klass = nil,
98
98
request = Packet . create_request ( 'core_channel_open' )
99
99
100
100
# Set the type of channel that we're allocating
101
- if ( type != nil )
101
+ if ! type . nil?
102
102
request . add_tlv ( TLV_TYPE_CHANNEL_TYPE , type )
103
103
end
104
104
105
105
# If no factory class was provided, use the default native class
106
- if ( klass == nil )
106
+ if klass . nil?
107
107
klass = self
108
108
end
109
109
@@ -112,15 +112,20 @@ def Channel.create(client, type = nil, klass = nil,
112
112
request . add_tlvs ( addends ) ;
113
113
114
114
# Transmit the request and wait for the response
115
- response = client . send_request ( request )
116
- cid = response . get_tlv_value ( TLV_TYPE_CHANNEL_ID )
117
-
118
- return nil unless cid
119
-
120
- # Create the channel instance
121
- channel = klass . new ( client , cid , type , flags )
115
+ cid = nil
116
+ begin
117
+ response = client . send_request ( request )
118
+ cid = response . get_tlv_value ( TLV_TYPE_CHANNEL_ID )
119
+ rescue RequestError
120
+ # Handle channel open failure exceptions
121
+ end
122
122
123
- return channel
123
+ if cid
124
+ # Create the channel instance
125
+ klass . new ( client , cid , type , flags )
126
+ else
127
+ raise Rex ::ConnectionRefused
128
+ end
124
129
end
125
130
126
131
##
@@ -169,13 +174,13 @@ def read(length = nil, addends = nil)
169
174
# Reads data from the remote half of the channel.
170
175
#
171
176
def _read ( length = nil , addends = nil )
172
- if ( self . cid == nil )
177
+ if self . cid . nil?
173
178
raise IOError , "Channel has been closed." , caller
174
179
end
175
180
176
181
request = Packet . create_request ( 'core_channel_read' )
177
182
178
- if ( length == nil )
183
+ if length . nil?
179
184
# Default block size to a higher amount for passive dispatcher
180
185
length = self . client . passive_service ? ( 1024 *1024 ) : 65536
181
186
end
@@ -217,7 +222,7 @@ def write(buf, length = nil, addends = nil)
217
222
#
218
223
def _write ( buf , length = nil , addends = nil )
219
224
220
- if ( self . cid == nil )
225
+ if self . cid . nil?
221
226
raise IOError , "Channel has been closed." , caller
222
227
end
223
228
@@ -245,7 +250,7 @@ def _write(buf, length = nil, addends = nil)
245
250
response = self . client . send_request ( request )
246
251
written = response . get_tlv ( TLV_TYPE_LENGTH )
247
252
248
- return ( written == nil ) ? 0 : written . value
253
+ written . nil? ? 0 : written . value
249
254
end
250
255
251
256
#
@@ -273,7 +278,7 @@ def close_read
273
278
# Closes the channel.
274
279
#
275
280
def self . _close ( client , cid , addends = nil )
276
- if ( cid == nil )
281
+ if cid . nil?
277
282
raise IOError , "Channel has been closed." , caller
278
283
end
279
284
@@ -302,7 +307,7 @@ def _close(addends = nil)
302
307
# Enables or disables interactive mode.
303
308
#
304
309
def interactive ( tf = true , addends = nil )
305
- if ( self . cid == nil )
310
+ if self . cid . nil?
306
311
raise IOError , "Channel has been closed." , caller
307
312
end
308
313
0 commit comments