chunk read fix, msg stream id read fix and open stream init func

This commit is contained in:
Muaz Ahmad 2023-08-10 03:24:48 +05:00
parent 5bc8a7affc
commit 45a06a10f7

View file

@ -21,6 +21,11 @@ type message struct {
msg_len uint32 msg_len uint32
} }
func OpenStreamsMapInit() (map[uint32]*chnk_stream, map[uint32]*message) {
open_chnkstrms := make(map[uint32]*chnk_stream)
open_msgs := make(map[uint32]*message)
return open_chnkstrms, open_msgs
}
func read_basic_header(conn net.Conn) (uint8, uint32, error) { func read_basic_header(conn net.Conn) (uint8, uint32, error) {
fmt_csid_byte := make([]byte, 1) fmt_csid_byte := make([]byte, 1)
@ -74,7 +79,7 @@ func read_message_header_0(conn net.Conn, chnk_stream_ptr *chnk_stream, msg_ptr
msg_ptr.msg_type = msg_typeid[0] msg_ptr.msg_type = msg_typeid[0]
msg_streamid := make([]byte, 4) msg_streamid := make([]byte, 4)
if _, err := conn.Read(msg_typeid); err != nil { if _, err := conn.Read(msg_streamid); err != nil {
return err return err
} }
chnk_stream_ptr.last_msg_strm_id = binary.BigEndian.Uint32(msg_streamid) chnk_stream_ptr.last_msg_strm_id = binary.BigEndian.Uint32(msg_streamid)
@ -94,9 +99,9 @@ func read_chunk_data(conn net.Conn, msg_ptr *message, chnk_size uint32) (error)
bytes_left := msg_ptr.msg_len - msg_ptr.curr_bytes_read bytes_left := msg_ptr.msg_len - msg_ptr.curr_bytes_read
var buffer_end uint32 var buffer_end uint32
if bytes_left < chnk_size { if bytes_left < chnk_size {
buffer_end = bytes_left + msg_ptr.curr_bytes_read + 1 buffer_end = bytes_left + msg_ptr.curr_bytes_read
} else { } else {
buffer_end = chnk_size + msg_ptr.curr_bytes_read + 1 buffer_end = chnk_size + msg_ptr.curr_bytes_read
} }
n, err := conn.Read(msg_ptr.data[msg_ptr.curr_bytes_read:buffer_end]) n, err := conn.Read(msg_ptr.data[msg_ptr.curr_bytes_read:buffer_end])
if err != nil { if err != nil {