Skip to content

Commit

Permalink
NO-ISSUE Code refactoring (#44)
Browse files Browse the repository at this point in the history
  • Loading branch information
linxGnu authored Oct 23, 2020
1 parent 4fe750a commit c8e20f1
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 22 deletions.
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
module github.com/linxGnu/gosmpp

require (
github.com/stretchr/testify v1.5.1
golang.org/x/text v0.3.2
github.com/stretchr/testify v1.6.1
golang.org/x/text v0.3.3
)

go 1.13
13 changes: 7 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0 h1:4G4v2dO3VZwixGIRoQ5Lfboy6nUhCyYzaqnIAPPhYs4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.5.1 h1:nOGnQDM7FYENwehXlg/kFVnos3rEvtKTjRvOWSzb6H4=
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs=
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0=
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
golang.org/x/text v0.3.3 h1:cokOdA+Jmi5PJGXLlLllQSgYigAEfHXJAERHVMaCc2k=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
21 changes: 8 additions & 13 deletions transmitter.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,8 @@ func (t *transmitter) Submit(p pdu.PDU) (err error) {
select {
case <-t.ctx.Done():
err = t.ctx.Err()
return

case t.input <- p:
return
}
} else {
err = ErrTransmitterClosing
Expand Down Expand Up @@ -246,20 +244,17 @@ func (t *transmitter) write(v []byte) (n int, err error) {
hasTimeout := t.settings.Timeout > 0

if hasTimeout {
if err = t.conn.SetWriteTimeout(t.settings.Timeout); err != nil {
return
}
err = t.conn.SetWriteTimeout(t.settings.Timeout)
}

if n, err = t.conn.Write(v); err != nil && n == 0 {
// retry again with double timeout
if hasTimeout {
if err = t.conn.SetWriteTimeout(t.settings.Timeout << 1); err != nil {
return
}
if err == nil {
if n, err = t.conn.Write(v); err != nil &&
n == 0 &&
hasTimeout &&
t.conn.SetWriteTimeout(t.settings.Timeout<<1) == nil {
// retry again with double timeout
n, err = t.conn.Write(v)
}

n, err = t.conn.Write(v)
}

return
Expand Down
1 change: 0 additions & 1 deletion transmitter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ func TestTransmitter(t *testing.T) {
_, ok := p.(*pdu.CancelSM)
require.True(t, ok)
}
tr.settings.Timeout = 500 * time.Millisecond

// do trigger
trigger(&tr)
Expand Down

0 comments on commit c8e20f1

Please sign in to comment.