Skip to content

Commit

Permalink
Release: v1.1.3-alpha
Browse files Browse the repository at this point in the history
  • Loading branch information
amir-the-h committed Mar 27, 2023
1 parent ecfa44e commit 7a78a09
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@ Changelog
=========
All notable changes to this project will be documented in this file.

v1.1.3-alpha
-------------

### Changed

- Fixed `Ws` lock issue

v1.1.2-alpha
-------------

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Installation
-----------------

```bash
go get github.com/amir-the-h/[email protected].2-alpha
go get github.com/amir-the-h/[email protected].3-alpha
```

Usage
Expand Down
16 changes: 5 additions & 11 deletions api/ws/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,18 +105,14 @@ func (c *ClientWs) Connect(p bool) error {
//
// https://www.okex.com/docs-v5/en/#websocket-api-login
func (c *ClientWs) Login() error {
c.mu[true].Lock()
if c.Authorized {
c.mu[true].Unlock()
return nil
}
if c.AuthRequested != nil && time.Since(*c.AuthRequested).Seconds() < 30 {
c.mu[true].Unlock()
return nil
}
now := time.Now()
c.AuthRequested = &now
c.mu[true].Unlock()
method := http.MethodGet
path := "/users/self/verify"
ts, sign := c.sign(method, path)
Expand Down Expand Up @@ -261,35 +257,33 @@ func (c *ClientWs) sender(p bool) error {
for {
select {
case data := <-c.sendChan[p]:
c.mu[p].Lock()
c.mu[p].RLock()
err := c.conn[p].SetWriteDeadline(time.Now().Add(writeWait))
if err != nil {
c.mu[p].Unlock()
c.mu[p].RUnlock()
return err
}
w, err := c.conn[p].NextWriter(websocket.TextMessage)
if err != nil {
c.mu[p].Unlock()
c.mu[p].RUnlock()
return err
}
if _, err = w.Write(data); err != nil {
c.mu[p].Unlock()
c.mu[p].RUnlock()
return err
}
now := time.Now()
c.lastTransmit[p] = &now
c.mu[p].Unlock()
c.mu[p].RUnlock()
if err := w.Close(); err != nil {
return err
}
case <-ticker.C:
c.mu[p].Lock()
if c.conn[p] != nil && (c.lastTransmit[p] == nil || (c.lastTransmit[p] != nil && time.Since(*c.lastTransmit[p]) > PingPeriod)) {
go func() {
c.sendChan[p] <- []byte("ping")
}()
}
c.mu[p].Unlock()
case <-c.ctx.Done():
return c.handleCancel("sender")
}
Expand Down

0 comments on commit 7a78a09

Please sign in to comment.