mirror of
https://github.com/diamondburned/arikawa.git
synced 2024-12-03 12:23:02 +00:00
Compare commits
No commits in common. "abd5bba9c373ed1e7a9df4ff9e6d7031ea2bdaf6" and "63310fdc954664ad17d1b9c6f889c9b45fcb7fa8" have entirely different histories.
abd5bba9c3
...
63310fdc95
|
@ -30,7 +30,7 @@
|
||||||
"variables": [ "$BOT_TOKEN" ]
|
"variables": [ "$BOT_TOKEN" ]
|
||||||
},
|
},
|
||||||
"script": [
|
"script": [
|
||||||
"go test -coverprofile $COV -race -v ./...",
|
"go test -coverprofile -race -v $COV ./...",
|
||||||
"go tool cover -func $COV"
|
"go tool cover -func $COV"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|
|
@ -325,8 +325,6 @@ func (g *Gateway) start(ctx context.Context) error {
|
||||||
return errors.Wrap(ctx.Err(), "failed to wait for Hello event")
|
return errors.Wrap(ctx.Err(), "failed to wait for Hello event")
|
||||||
}
|
}
|
||||||
|
|
||||||
wsutil.WSDebug("Hello received; duration:", hello.HeartbeatInterval)
|
|
||||||
|
|
||||||
// Send Discord either the Identify packet (if it's a fresh connection), or
|
// Send Discord either the Identify packet (if it's a fresh connection), or
|
||||||
// a Resume packet (if it's a dead connection).
|
// a Resume packet (if it's a dead connection).
|
||||||
if g.SessionID == "" {
|
if g.SessionID == "" {
|
||||||
|
|
|
@ -91,9 +91,6 @@ func (c *Conn) Dial(ctx context.Context, addr string) (err error) {
|
||||||
return errors.Wrap(err, "failed to dial WS")
|
return errors.Wrap(err, "failed to dial WS")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reset the deadline.
|
|
||||||
c.Conn.SetWriteDeadline(resetDeadline)
|
|
||||||
|
|
||||||
c.events = make(chan Event, WSBuffer)
|
c.events = make(chan Event, WSBuffer)
|
||||||
go startReadLoop(c.Conn, c.events)
|
go startReadLoop(c.Conn, c.events)
|
||||||
|
|
||||||
|
@ -116,6 +113,7 @@ func (c *Conn) Send(ctx context.Context, b []byte) error {
|
||||||
defer c.Conn.SetWriteDeadline(resetDeadline)
|
defer c.Conn.SetWriteDeadline(resetDeadline)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// We need to clean up ourselves if things are erroring out.
|
||||||
if err := c.Conn.WriteMessage(websocket.TextMessage, b); err != nil {
|
if err := c.Conn.WriteMessage(websocket.TextMessage, b); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -124,8 +122,6 @@ func (c *Conn) Send(ctx context.Context, b []byte) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Conn) Close() error {
|
func (c *Conn) Close() error {
|
||||||
WSDebug("Conn: Close is called; shutting down the Websocket connection.")
|
|
||||||
|
|
||||||
// Have a deadline before closing.
|
// Have a deadline before closing.
|
||||||
var deadline = time.Now().Add(5 * time.Second)
|
var deadline = time.Now().Add(5 * time.Second)
|
||||||
c.Conn.SetWriteDeadline(deadline)
|
c.Conn.SetWriteDeadline(deadline)
|
||||||
|
@ -133,8 +129,6 @@ func (c *Conn) Close() error {
|
||||||
// Close the WS.
|
// Close the WS.
|
||||||
err := c.Conn.Close()
|
err := c.Conn.Close()
|
||||||
|
|
||||||
c.Conn.SetWriteDeadline(resetDeadline)
|
|
||||||
|
|
||||||
WSDebug("Conn: Websocket closed; error:", err)
|
WSDebug("Conn: Websocket closed; error:", err)
|
||||||
WSDebug("Conn: Flusing events...")
|
WSDebug("Conn: Flusing events...")
|
||||||
|
|
||||||
|
@ -168,8 +162,6 @@ func startReadLoop(conn *websocket.Conn, eventCh chan<- Event) {
|
||||||
for {
|
for {
|
||||||
b, err := state.handle()
|
b, err := state.handle()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
WSDebug("Conn: Read error:", err)
|
|
||||||
|
|
||||||
// Is the error an EOF?
|
// Is the error an EOF?
|
||||||
if errors.Is(err, io.EOF) {
|
if errors.Is(err, io.EOF) {
|
||||||
// Yes it is, exit.
|
// Yes it is, exit.
|
||||||
|
|
|
@ -135,8 +135,6 @@ func (ws *Websocket) SendCtx(ctx context.Context, b []byte) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := ws.conn.Send(ctx, b); err != nil {
|
if err := ws.conn.Send(ctx, b); err != nil {
|
||||||
// We need to clean up ourselves if things are erroring out.
|
|
||||||
WSDebug("Conn: Error while sending; closing the connection. Error:", err)
|
|
||||||
ws.close()
|
ws.close()
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -162,7 +160,6 @@ func (ws *Websocket) Close() error {
|
||||||
// more information.
|
// more information.
|
||||||
func (ws *Websocket) close() error {
|
func (ws *Websocket) close() error {
|
||||||
if ws.closed {
|
if ws.closed {
|
||||||
WSDebug("Conn: Websocket is already closed.")
|
|
||||||
return ErrWebsocketClosed
|
return ErrWebsocketClosed
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue