Skip to content

Commit

Permalink
go-aah/aah#126 added isdisconnected method
Browse files Browse the repository at this point in the history
  • Loading branch information
jeevatkm committed Apr 23, 2018
1 parent 10956e4 commit 4f36a28
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
4 changes: 3 additions & 1 deletion engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ var (
ErrAuthenticationFailed = errors.New("aahws: authentication failed")
ErrWebSocketNotFound = errors.New("aahws: not found")
ErrWebSocketConnectFailed = errors.New("aahws: connect failed")
ErrConnectionClosed = errors.New("aahws: connection closed")
ErrUseOfClosedConnection = errors.New("aahws: use of closed ws connection")
)

// EventCallbackFunc func type used for all WebSocket event callback.
Expand Down Expand Up @@ -121,7 +123,7 @@ func (e *Engine) SetAuthCallback(ac AuthCallbackFunc) {
e.doAuth = ac
}

// Connect method primarly does upgrades HTTP connection into WebSocket
// Connect method primarily does upgrades HTTP connection into WebSocket
// connection.
//
// Along with Check Origin, Authentication Callback and aah WebSocket events
Expand Down
20 changes: 16 additions & 4 deletions util.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
package ws

import (
"errors"
"fmt"
"io"
"net/http"
"strconv"
"strings"
Expand All @@ -18,6 +18,18 @@ import (
// Package methods
//______________________________________________________________________________

func IsDisconnected(err error) bool {
switch err {
case ErrConnectionClosed, ErrUseOfClosedConnection:
return true
}
return false
}

//‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
// Package Unexported methods
//______________________________________________________________________________

// WriteHTTPError is to write WebSocket context error.
func writeHTTPError(w http.ResponseWriter, code int, body string) {
w.Header().Set(ahttp.HeaderContentType, ahttp.ContentTypePlainText.String())
Expand All @@ -38,9 +50,9 @@ func createError(err error) error {

msg := err.Error()
if strings.HasPrefix(msg, "ws closed") {
return errors.New("aahws: connection closed")
} else if strings.HasSuffix(msg, "use of closed network connection") {
return errors.New("aahws: use of closed ws connection")
return ErrConnectionClosed
} else if err == io.EOF || strings.HasSuffix(msg, "use of closed network connection") {
return ErrUseOfClosedConnection
}
return fmt.Errorf("aah%s", msg)
}

0 comments on commit 4f36a28

Please sign in to comment.