libnmdc: fix bugs with buffer splitting

This commit is contained in:
mappu 2016-04-03 19:20:58 +12:00
parent 73f6d66cbd
commit 8d7b0b46af

View File

@ -74,7 +74,7 @@ var rx_incomingTo *regexp.Regexp
var ErrNotConnected error = errors.New("Not connected") var ErrNotConnected error = errors.New("Not connected")
func init() { func init() {
rx_protocolMessage = regexp.MustCompile("(?ms)^[^|]*|") rx_protocolMessage = regexp.MustCompile("(?ms)^[^|]*\\|")
rx_publicChat = regexp.MustCompile("(?ms)^<([^>]*)> (.*)$") rx_publicChat = regexp.MustCompile("(?ms)^<([^>]*)> (.*)$")
rx_incomingTo = regexp.MustCompile("(?ms)^([^ ]+) From: ([^ ]+) \\$<([^>]*)> (.*)") rx_incomingTo = regexp.MustCompile("(?ms)^([^ ]+) From: ([^ ]+) \\$<([^>]*)> (.*)")
} }
@ -368,7 +368,7 @@ func (this *HubConnection) worker() {
// Read from socket into our local buffer (blocking) // Read from socket into our local buffer (blocking)
if this.connValid { if this.connValid {
readBuff := make([]byte, 4096) readBuff := make([]byte, 1024)
nbytes, err = this.conn.Read(readBuff) nbytes, err = this.conn.Read(readBuff)
if nbytes > 0 { if nbytes > 0 {
fullBuffer += string(readBuff[0:nbytes]) fullBuffer += string(readBuff[0:nbytes])
@ -382,7 +382,7 @@ func (this *HubConnection) worker() {
} }
protocolMessage := rx_protocolMessage.FindString(fullBuffer) protocolMessage := rx_protocolMessage.FindString(fullBuffer)
if len(protocolMessage) > 0 { if len(protocolMessage) > 0 {
this.processProtocolMessage(protocolMessage) this.processProtocolMessage(protocolMessage[:len(protocolMessage)-1])
fullBuffer = fullBuffer[len(protocolMessage):] fullBuffer = fullBuffer[len(protocolMessage):]
} else { } else {
break break