lib/avro/ipc.rb in avro-1.3.3 vs lib/avro/ipc.rb in avro-1.5.4
- old
+ new
@@ -12,10 +12,12 @@
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
+require "net/http"
+
module Avro::IPC
class AvroRemoteError < Avro::AvroError; end
HANDSHAKE_REQUEST_SCHEMA = Avro::Schema.parse <<-JSON
@@ -395,11 +397,11 @@
def write_framed_message(message)
message_length = message.size
total_bytes_sent = 0
while message_length - total_bytes_sent > 0
- if message_length - total_bytes_sent > BUFFER_SIZE:
+ if message_length - total_bytes_sent > BUFFER_SIZE
buffer_length = BUFFER_SIZE
else
buffer_length = message_length - total_bytes_sent
end
write_buffer(message[total_bytes_sent,buffer_length])
@@ -519,17 +521,16 @@
class HTTPTransceiver
attr_reader :remote_name, :host, :port
def initialize(host, port)
@host, @port = host, port
@remote_name = "#{host}:#{port}"
+ @conn = Net::HTTP.start host, port
end
def transceive(message)
writer = FramedWriter.new(StringIO.new)
writer.write_framed_message(message)
- resp = Net::HTTP.start(host, port) do |http|
- http.post('/', writer.to_s, {'Content-Type' => 'avro/binary'})
- end
+ resp = @conn.post('/', writer.to_s, {'Content-Type' => 'avro/binary'})
FramedReader.new(StringIO.new(resp.body)).read_framed_message
end
end
end