Skip to content

Commit 2b6f6a3

Browse files
authored
fixed bug with 0-byte reads/writes (#35)
1 parent afe0327 commit 2b6f6a3

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

connection.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,10 @@ func (v *connection) recvMessage() (msgs.BackEndMsg, error) {
193193

194194
msgBytes := make([]byte, msgSize)
195195

196-
if err = v.readAll(msgBytes); err != nil {
197-
return nil, err
196+
if msgSize > 0 {
197+
if err = v.readAll(msgBytes); err != nil {
198+
return nil, err
199+
}
198200
}
199201

200202
bem, err := msgs.CreateBackEndMsg(msgHeader[0], msgBytes)
@@ -230,10 +232,12 @@ func (v *connection) sendMessage(msg msgs.FrontEndMsg) error {
230232
_, result = v.conn.Write(sizeBytes)
231233

232234
if result == nil {
233-
_, result = v.conn.Write(msgBytes)
235+
if len(msgBytes) > 0 {
236+
_, result = v.conn.Write(msgBytes)
234237

235-
if result == nil {
236-
connectionLogger.Debug("-> " + msg.String())
238+
if result == nil {
239+
connectionLogger.Debug("-> " + msg.String())
240+
}
237241
}
238242
}
239243
}

0 commit comments

Comments
 (0)