fix message length
This commit is contained in:
parent
d03e08b466
commit
14205a0b2e
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue