Unverified Commit c199e77a authored by Dominique Feyer's avatar Dominique Feyer Committed by GitHub
Browse files

Merge pull request #20 from jdoubleu/fix-large-xdebug-chunks

Fix incomplete data from xdebug
parents d5e0fbf6 65f6efd9
......@@ -12,6 +12,8 @@ import (
"fmt"
"io"
"net"
"bytes"
"strconv"
)
const h = "%s"
......@@ -97,12 +99,31 @@ func (p *Proxy) pipe(src, dst *net.TCPConn) {
buff := make([]byte, 0xffff)
for {
n, err := src.Read(buff)
if err != nil {
p.pipeErrors <- err
// make sure the other pipe will stop as well
dst.Close()
if p.handleError(err, dst) {
return
}
// check for incomplete data from xdebug
if isFromDebugger {
header := bytes.Split(buff, []byte{0})
sizeStr := string(header[0])
sizeLen := len(sizeStr)
size, err := strconv.Atoi(sizeStr)
if p.handleError(err, dst) {
return
}
// whole message consists of [size NULL XML(data) NULL]
packetLen := sizeLen + size + 2
// read more data if buffer has not been filled with all expected data
for n < packetLen {
n2, err := src.Read(buff[n:])
if p.handleError(err, dst) {
return
}
n += n2
}
}
b := buff[:n]
p.log(h, f)
if p.Config.VeryVerbose {
......@@ -142,10 +163,7 @@ func (p *Proxy) pipe(src, dst *net.TCPConn) {
// write out result
n, err = dst.Write(b)
if err != nil {
p.pipeErrors <- err
// make sure the other pipe will stop as well
src.Close()
if p.handleError(err, src) {
return
}
if isFromDebugger {
......@@ -155,3 +173,15 @@ func (p *Proxy) pipe(src, dst *net.TCPConn) {
}
}
}
func (p *Proxy) handleError(err error, ch *net.TCPConn) bool {
if err != nil {
p.pipeErrors <- err
// make sure the other pipe will stop as well
ch.Close()
return true
}
return false
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment