fix message length

This commit is contained in:
xdrm-brackets 2018-05-05 23:53:00 +02:00
parent d03e08b466
commit 14205a0b2e
1 changed files with 6 additions and 1 deletions

View File

@ -153,6 +153,11 @@ func (m Message) Send(socket net.Conn) error {
header := make([]byte, 0, maximumHeaderSize)
// fix size
if uint(len(m.Data)) <= m.Size {
m.Size = uint( len(m.Data) )
}
/* (1) Byte 0 : FIN + opcode */
header = append(header, 0x80 | byte(TEXT) )
@ -182,7 +187,7 @@ func (m Message) Send(socket net.Conn) error {
/* (3) Build write buffer */
writeBuf := make([]byte, 0, len(header) + int(m.Size))
writeBuf = append(writeBuf, header...)
writeBuf = append(writeBuf, m.Data...)
writeBuf = append(writeBuf, m.Data[0:m.Size]...)
/* (4) Send over socket */
_, err := socket.Write(writeBuf)