Skip to content

Commit

Permalink
Merge pull request #86 from piglig/refactor/code-optimization
Browse files Browse the repository at this point in the history
refactor: code optimization
  • Loading branch information
pin authored Jun 17, 2023
2 parents 90a0661 + 603893b commit c10edb1
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 20 deletions.
2 changes: 1 addition & 1 deletion netascii/netascii_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func TestTo(t *testing.T) {
for text, netascii := range basic {
to := ToReader(strings.NewReader(text))
n, _ := ioutil.ReadAll(to)
if bytes.Compare(n, []byte(netascii)) != 0 {
if !bytes.Equal(n, []byte(netascii)) {
t.Errorf("%q to netascii: %q != %q", text, n, netascii)
}
}
Expand Down
2 changes: 1 addition & 1 deletion receiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ func (r *receiver) buildTransferStats() TransferStats {
Tid: r.tid,
Mode: r.mode,
Opts: r.opts,
Duration: time.Now().Sub(r.startTime),
Duration: time.Since(r.startTime),
DatagramsSent: r.datagramsSent,
DatagramsAcked: r.datagramsAcked,
}
Expand Down
16 changes: 8 additions & 8 deletions sender.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,15 +262,15 @@ func (s *sender) sendDatagram(l int) (*net.UDPAddr, error) {

func (s *sender) buildTransferStats() TransferStats {
return TransferStats{
RemoteAddr: s.addr.IP,
Filename: s.filename,
Tid: s.tid,
RemoteAddr: s.addr.IP,
Filename: s.filename,
Tid: s.tid,
SenderAnticipateEnabled: s.sendA.enabled,
Mode: s.mode,
Opts: s.opts,
Duration: time.Now().Sub(s.startTime),
DatagramsSent: s.datagramsSent,
DatagramsAcked: s.datagramsAcked,
Mode: s.mode,
Opts: s.opts,
Duration: time.Since(s.startTime),
DatagramsSent: s.datagramsSent,
DatagramsAcked: s.datagramsAcked,
}
}

Expand Down
2 changes: 1 addition & 1 deletion server.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func NewServer(readHandler func(filename string, rf io.ReaderFrom) error,
// OS providing methods to inspect the underlying UDP and IP packets
// directly.
type RequestPacketInfo interface {
// LocalAddr returns the IP address we are servicing the request on.
// LocalIP returns the IP address we are servicing the request on.
// If it is unable to determine what address that is, the returned
// net.IP will be nil.
LocalIP() net.IP
Expand Down
16 changes: 7 additions & 9 deletions tftp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,15 +94,13 @@ func packUnpack(t *testing.T, filename, mode string, opts options) {
t.Errorf("mode mismatch (%s): '%x' vs '%x'",
mode, m, mode)
}
if opts != nil {
for name, value := range opts {
v, ok := o[name]
if !ok {
t.Errorf("missing %s option", name)
}
if v != value {
t.Errorf("option %s mismatch: '%x' vs '%x'", name, v, value)
}
for name, value := range opts {
v, ok := o[name]
if !ok {
t.Errorf("missing %s option", name)
}
if v != value {
t.Errorf("option %s mismatch: '%x' vs '%x'", name, v, value)
}
}
}
Expand Down

0 comments on commit c10edb1

Please sign in to comment.