From 74ecd1d3e52dc7b2d7a01ad28dd695f1bd3ed8d2 Mon Sep 17 00:00:00 2001 From: V Sreekanth Date: Tue, 14 Sep 2010 01:07:28 +0530 Subject: [PATCH 1/5] using bytesize instead of size so that it works well with utf-8 strings and ruby 1.9 --- lib/gearman/util.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/gearman/util.rb b/lib/gearman/util.rb index 5304de6..4d973a3 100644 --- a/lib/gearman/util.rb +++ b/lib/gearman/util.rb @@ -134,8 +134,10 @@ def Util.read_response(sock, timeout=nil) # @param sock Socket connected to a job server # @param req request packet to send def Util.send_request(sock, req) + puts req.encoding + puts req.encoding len = sock.write(req) - if len != req.size + if len != req.bytesize raise NetworkError, "Wrote #{len} instead of #{req.size}" end end From b31fbb4451c8b5c460b637e61449d4926740b6a9 Mon Sep 17 00:00:00 2001 From: V Sreekanth Date: Tue, 14 Sep 2010 01:27:21 +0530 Subject: [PATCH 2/5] Removed the debugging puts --- lib/gearman/util.rb | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/gearman/util.rb b/lib/gearman/util.rb index 4d973a3..3202e45 100644 --- a/lib/gearman/util.rb +++ b/lib/gearman/util.rb @@ -134,8 +134,6 @@ def Util.read_response(sock, timeout=nil) # @param sock Socket connected to a job server # @param req request packet to send def Util.send_request(sock, req) - puts req.encoding - puts req.encoding len = sock.write(req) if len != req.bytesize raise NetworkError, "Wrote #{len} instead of #{req.size}" From a57b81f8e860b4b612691297c2e9bfe0a46046c4 Mon Sep 17 00:00:00 2001 From: V Sreekanth Date: Tue, 14 Sep 2010 18:15:15 +0530 Subject: [PATCH 3/5] Forcing encoding --- lib/gearman/util.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/gearman/util.rb b/lib/gearman/util.rb index 3202e45..5de5f6a 100644 --- a/lib/gearman/util.rb +++ b/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 ## From 7be4c9fcb4aeb66077eb331779d1c94c2759e5ea Mon Sep 17 00:00:00 2001 From: V Sreekanth Date: Fri, 24 Sep 2010 01:58:54 +0530 Subject: [PATCH 4/5] Receiving bytesize check fixed as well --- lib/gearman/util.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/gearman/util.rb b/lib/gearman/util.rb index 5de5f6a..22ff8cf 100644 --- a/lib/gearman/util.rb +++ b/lib/gearman/util.rb @@ -104,8 +104,8 @@ 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}" + if data.bytesize < len + raise NetworkError, "Read #{data.bytesize} byte(s) instead of #{len}" end data end From dc444487b9b24f0591a1c6900f2551fca89424e2 Mon Sep 17 00:00:00 2001 From: V Sreekanth Date: Fri, 24 Sep 2010 02:05:05 +0530 Subject: [PATCH 5/5] Temporarily commenting the byte size matching --- lib/gearman/util.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/gearman/util.rb b/lib/gearman/util.rb index 22ff8cf..e676cee 100644 --- a/lib/gearman/util.rb +++ b/lib/gearman/util.rb @@ -104,9 +104,9 @@ def Util.timed_recv(sock, len, timeout=nil) or break data += sock.readpartial(len - data.size) end - if data.bytesize < len - raise NetworkError, "Read #{data.bytesize} byte(s) instead of #{len}" - end + # if data.bytesize < len + # raise NetworkError, "Read #{data.bytesize} byte(s) instead of #{len}" + # end data end