-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17 from puellanivis/issue/avoid-truncated-udp-reads
Avoid truncated udp reads
- Loading branch information
Showing
7 changed files
with
247 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package files | ||
|
||
import ( | ||
"io" | ||
) | ||
|
||
// fuzzyLimitedReader reads at least N-bytes from the underlying reader. | ||
// It does not ensure that it reads only or at-most N-bytes. | ||
// Each call to Read updates N to reflect the new amount remaining. | ||
// Read returns EOF when N <= 0 or when the underlying R returns EOF. | ||
type fuzzyLimitedReader struct { | ||
R io.Reader // underlying reader | ||
N int64 // stop reading after at least this much | ||
} | ||
|
||
func (r *fuzzyLimitedReader) Read(b []byte) (n int, err error) { | ||
if r.N <= 0 { | ||
return 0, io.EOF | ||
} | ||
|
||
n, err = r.R.Read(b) | ||
r.N -= int64(n) | ||
|
||
return n, err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.