add more code commenting + remove unnecessary loop

Signed-off-by: kim (grufwub) <grufwub@gmail.com>
This commit is contained in:
kim (grufwub) 2020-04-10 16:09:31 +01:00
parent ad5ce0bbe1
commit ea39cf261d

View File

@ -43,31 +43,30 @@ func (client *Client) Start() {
/* Buffered read from listener */
iter := 0
for {
/* Buffered read from listener */
count, err = client.Socket.Read(buf)
if err != nil {
client.Log("Error reading from socket %s: %v\n", client.Socket, err.Error())
return
}
/* Stop once we hit null bytes */
for i := 0; i < count; i += 1 {
if buf[i] == 0 {
break
}
received = append(received, buf[i])
}
/* Only copy non-null bytes */
received = append(received, buf[:count])
/* If count is less than expected read size, we've hit EOF */
if count < SocketReadBufSize {
/* EOF */
break
}
/* Hit max read chunk size, send error + close connection */
if iter == MaxSocketReadChunks {
client.Error("max socket read size reached\n")
client.Log("Reached max socket read size: %d. Closing connection...\n", MaxSocketReadChunks*SocketReadBufSize)
return
}
/* Keep count :) */
iter += 1
}