Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Minor ruby 1.9 utf-8 fix #1

Open
wants to merge 5 commits into from

1 participant

@sreeix

Hi,
I am playing with gearman on ruby 1.9 and i got errors with the lib with messages like
Gearman::NetworkError - Wrote 2678 instead of 2676:

The String was utf-8 and hence the bytesize and string size does not match. I have fixed it by using bytesize method. So It should work for both 1.8 and 1.9

Cheers
sreekantg

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Sep 13, 2010
  1. @sreeix
  2. @sreeix

    Removed the debugging puts

    sreeix authored
Commits on Sep 14, 2010
  1. @sreeix

    Forcing encoding

    sreeix authored
Commits on Sep 23, 2010
  1. @sreeix
  2. @sreeix
This page is out of date. Refresh to see the latest.
Showing with 6 additions and 6 deletions.
  1. +6 −6 lib/gearman/util.rb
View
12 lib/gearman/util.rb
@@ -1,5 +1,5 @@
#!/usr/bin/env ruby
-
+# encoding: UTF-8
require 'socket'
require 'time'
@@ -69,7 +69,7 @@ def Util.pack_request(type_name, arg='')
type_num = NUMS[type_name.to_sym]
raise InvalidArgsError, "Invalid type name '#{type_name}'" unless type_num
arg = '' if not arg
- "\0REQ" + [type_num, arg.size].pack('NN') + arg
+ "\0REQ" + [type_num, arg.size].pack('NN').force_encoding("UTF-8") + arg
end
##
@@ -104,9 +104,9 @@ def Util.timed_recv(sock, len, timeout=nil)
or break
data += sock.readpartial(len - data.size)
end
- if data.size < len
- raise NetworkError, "Read #{data.size} byte(s) instead of #{len}"
- end
+ # if data.bytesize < len
+ # raise NetworkError, "Read #{data.bytesize} byte(s) instead of #{len}"
+ # end
data
end
@@ -135,7 +135,7 @@ def Util.read_response(sock, timeout=nil)
# @param req request packet to send
def Util.send_request(sock, req)
len = sock.write(req)
- if len != req.size
+ if len != req.bytesize
raise NetworkError, "Wrote #{len} instead of #{req.size}"
end
end
Something went wrong with that request. Please try again.