@ -69,7 +69,7 @@ func Decode(raw []byte) (*Packet, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (p *Packet) Encode() ([]byte, error) {
|
func (p *Packet) Encode() ([]byte, error) {
|
||||||
buff := make([]byte, 5)
|
buff := make([]byte, 4)
|
||||||
buff[0] = uint8(p.code)
|
buff[0] = uint8(p.code)
|
||||||
buff[1] = uint8(p.id)
|
buff[1] = uint8(p.id)
|
||||||
|
|
||||||
@ -77,10 +77,10 @@ func (p *Packet) Encode() ([]byte, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return buff, err
|
return buff, err
|
||||||
}
|
}
|
||||||
binary.BigEndian.PutUint16(buff[2:], uint16(len(payloadBuffer)+5))
|
|
||||||
if p.code == CodeRequest || p.code == CodeResponse {
|
if p.code == CodeRequest || p.code == CodeResponse {
|
||||||
buff[4] = uint8(p.msgType)
|
buff = append(buff, uint8(p.msgType))
|
||||||
}
|
}
|
||||||
buff = append(buff, payloadBuffer...)
|
buff = append(buff, payloadBuffer...)
|
||||||
|
binary.BigEndian.PutUint16(buff[2:], uint16(len(buff)))
|
||||||
return buff, nil
|
return buff, nil
|
||||||
}
|
}
|
||||||
|
@ -54,12 +54,12 @@ func (conn *TLSConnection) Read(p []byte) (int, error) {
|
|||||||
n, err := conn.reader.Read(p)
|
n, err := conn.reader.Read(p)
|
||||||
if n == 0 {
|
if n == 0 {
|
||||||
log.Debugf("TLS(buffer): Attempted read %d from empty buffer, stalling...", len(p))
|
log.Debugf("TLS(buffer): Attempted read %d from empty buffer, stalling...", len(p))
|
||||||
time.Sleep(500 * time.Millisecond)
|
time.Sleep(100 * time.Millisecond)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if conn.expectedWriterByteCount > 0 && conn.writtenByteCount < int(conn.expectedWriterByteCount) {
|
if conn.expectedWriterByteCount > 0 && conn.writtenByteCount < int(conn.expectedWriterByteCount) {
|
||||||
log.Debugf("TLS(buffer): Attempted read %d while waiting for bytes %d, stalling...", len(p), conn.expectedWriterByteCount-conn.reader.Len())
|
log.Debugf("TLS(buffer): Attempted read %d while waiting for bytes %d, stalling...", len(p), conn.expectedWriterByteCount-conn.reader.Len())
|
||||||
time.Sleep(500 * time.Millisecond)
|
time.Sleep(100 * time.Millisecond)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if conn.expectedWriterByteCount > 0 && conn.writtenByteCount == int(conn.expectedWriterByteCount) {
|
if conn.expectedWriterByteCount > 0 && conn.writtenByteCount == int(conn.expectedWriterByteCount) {
|
||||||
|
Reference in New Issue
Block a user