diff --git a/example/client.go b/example/client.go index 48e868d..58a3aa9 100644 --- a/example/client.go +++ b/example/client.go @@ -9,7 +9,7 @@ func main() { client := gearman.NewClient() defer client.Close() client.AddServer("127.0.0.1:4730") - echo := []byte("Hello world") + echo := []byte("Hello\x00world") if data, err := client.Echo(echo); err != nil { log.Println(string(data)) diff --git a/src/pkg/gearman/client.go b/src/pkg/gearman/client.go index 006946e..e04d9bf 100644 --- a/src/pkg/gearman/client.go +++ b/src/pkg/gearman/client.go @@ -204,7 +204,7 @@ func (client *Client) Status(handle string) (known, running bool, numerator, den if job, err = client.readLastJob(STATUS_RES); err != nil { return } - data := splitByteArray(job.Data, '\x00') + data := splitByteArray(job.Data, '\x00', 5) if len(data) != 5 { err = os.NewError("Data Error.") return diff --git a/src/pkg/gearman/client/job.go b/src/pkg/gearman/client/job.go index d1062b8..4513866 100644 --- a/src/pkg/gearman/client/job.go +++ b/src/pkg/gearman/client/job.go @@ -65,7 +65,7 @@ func (job *ClientJob) Result() (data []byte, err os.Error) { err = os.NewError("Work exception.") fallthrough case WORK_COMPLETE: - s := splitByteArray(job.Data, '\x00') + s := splitByteArray(job.Data, '\x00', 2) if len(s) != 2 { err = os.NewError("Invalid data.") return @@ -84,7 +84,7 @@ func (job *ClientJob) Update() (data []byte, err os.Error) { err = os.NewError("The job is not a update.") return } - s := splitByteArray(job.Data, '\x00') + s := splitByteArray(job.Data, '\x00', 2) if len(s) != 2 { err = os.NewError("Invalid data.") return diff --git a/src/pkg/gearman/gearman.go b/src/pkg/gearman/gearman.go index 81a0a54..b56496c 100644 --- a/src/pkg/gearman/gearman.go +++ b/src/pkg/gearman/gearman.go @@ -85,13 +85,17 @@ type Job interface { } // Splite the byte array by a byte -func splitByteArray(slice []byte, spot byte) (data [][]byte) { +func splitByteArray(slice []byte, spot byte, limit int) (data [][]byte) { data = make([][]byte, 0, 10) start, end := 0, 0 for i, v := range slice { if v == spot { if start != end { data = append(data, slice[start:end]) + if (limit > 0) && (limit - 1 == len(data)) { + start = end + break + } } start, end = i+1, i+1 } else { @@ -104,7 +108,7 @@ func splitByteArray(slice []byte, spot byte) (data [][]byte) { // Extract the error message func getError(data []byte) (eno os.Errno, err os.Error) { - rel := splitByteArray(data, '\x00') + rel := splitByteArray(data, '\x00', 2) if len(rel) != 2 { err = os.NewError("The input is not a error data.") return diff --git a/src/pkg/gearman/worker.go b/src/pkg/gearman/worker.go index 16c2171..020c401 100644 --- a/src/pkg/gearman/worker.go +++ b/src/pkg/gearman/worker.go @@ -217,7 +217,13 @@ func (worker *Worker) SetId(id string) (err os.Error) { // Execute the job. And send back the result. func (worker *Worker) exec(job *WorkerJob) (err os.Error) { - jobdata := splitByteArray(job.Data, '\x00') + var limit int + if job.DataType == JOB_ASSIGN { + limit = 3 + } else { + limit = 4 + } + jobdata := splitByteArray(job.Data, '\x00', limit) job.Handle = string(jobdata[0]) funcname := string(jobdata[1]) if job.DataType == JOB_ASSIGN {