|
|
@ -24,6 +24,8 @@ content (n bytes) - actual message content |
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const BATCH_SIZE = 1 << 16 |
|
|
|
|
|
|
|
|
|
|
|
// Read the message type and content size, and return the actual content.
|
|
|
|
// Read the message type and content size, and return the actual content.
|
|
|
|
func ReadMessageContent(conn net.Conn) ([]byte, error) { |
|
|
|
func ReadMessageContent(conn net.Conn) ([]byte, error) { |
|
|
|
var ( |
|
|
|
var ( |
|
|
@ -65,12 +67,12 @@ func ReadMessageContent(conn net.Conn) ([]byte, error) { |
|
|
|
//log.Printf("The content size is %d bytes.", bytesToRead)
|
|
|
|
//log.Printf("The content size is %d bytes.", bytesToRead)
|
|
|
|
|
|
|
|
|
|
|
|
//// Read the content in chunk of 1024 bytes
|
|
|
|
//// Read the content in chunk of 1024 bytes
|
|
|
|
tmpBuf := make([]byte, 1024) |
|
|
|
tmpBuf := make([]byte, BATCH_SIZE) |
|
|
|
ILOOP: |
|
|
|
ILOOP: |
|
|
|
for { |
|
|
|
for { |
|
|
|
timeoutDuration := 1 * time.Second |
|
|
|
timeoutDuration := 1 * time.Second |
|
|
|
conn.SetReadDeadline(time.Now().Add(timeoutDuration)) |
|
|
|
conn.SetReadDeadline(time.Now().Add(timeoutDuration)) |
|
|
|
if bytesToRead < 1024 { |
|
|
|
if bytesToRead < BATCH_SIZE { |
|
|
|
// Read the last number of bytes less than 1024
|
|
|
|
// Read the last number of bytes less than 1024
|
|
|
|
tmpBuf = make([]byte, bytesToRead) |
|
|
|
tmpBuf = make([]byte, bytesToRead) |
|
|
|
} |
|
|
|
} |
|
|
|