summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/nlopes/slack/websocket_managed_conn.go
diff options
context:
space:
mode:
authorWim <wim@42.be>2016-11-06 00:07:24 +0100
committerWim <wim@42.be>2016-11-06 00:07:24 +0100
commit37873acfcd328e7c9eaf2e69148de05b8d00a428 (patch)
tree9402715a83f140dda8d102aee6697366546a9382 /vendor/github.com/nlopes/slack/websocket_managed_conn.go
parent2dbe0eb55729620ffdfdb7e4f10003564d79c7e1 (diff)
downloadmatterbridge-msglm-37873acfcd328e7c9eaf2e69148de05b8d00a428.tar.gz
matterbridge-msglm-37873acfcd328e7c9eaf2e69148de05b8d00a428.tar.bz2
matterbridge-msglm-37873acfcd328e7c9eaf2e69148de05b8d00a428.zip
Update vendor (slack)
Diffstat (limited to 'vendor/github.com/nlopes/slack/websocket_managed_conn.go')
-rw-r--r--vendor/github.com/nlopes/slack/websocket_managed_conn.go21
1 files changed, 17 insertions, 4 deletions
diff --git a/vendor/github.com/nlopes/slack/websocket_managed_conn.go b/vendor/github.com/nlopes/slack/websocket_managed_conn.go
index db2df902..65bb7299 100644
--- a/vendor/github.com/nlopes/slack/websocket_managed_conn.go
+++ b/vendor/github.com/nlopes/slack/websocket_managed_conn.go
@@ -90,6 +90,7 @@ func (rtm *RTM) connect(connectionCount int) (*Info, *websocket.Conn, error) {
rtm.IncomingEvents <- RTMEvent{"invalid_auth", &InvalidAuthEvent{}}
return nil, nil, sErr
}
+
// any other errors are treated as recoverable and we try again after
// sending the event along the IncomingEvents channel
rtm.IncomingEvents <- RTMEvent{"connection_error", &ConnectionErrorEvent{
@@ -191,6 +192,18 @@ func (rtm *RTM) handleIncomingEvents(keepRunning <-chan bool) {
}
}
+func (rtm *RTM) sendWithDeadline(msg interface{}) error {
+ // set a write deadline on the connection
+ if err := rtm.conn.SetWriteDeadline(time.Now().Add(10 * time.Second)); err != nil {
+ return err
+ }
+ if err := websocket.JSON.Send(rtm.conn, msg); err != nil {
+ return err
+ }
+ // remove write deadline
+ return rtm.conn.SetWriteDeadline(time.Time{})
+}
+
// sendOutgoingMessage sends the given OutgoingMessage to the slack websocket.
//
// It does not currently detect if a outgoing message fails due to a disconnect
@@ -204,8 +217,8 @@ func (rtm *RTM) sendOutgoingMessage(msg OutgoingMessage) {
}}
return
}
- err := websocket.JSON.Send(rtm.conn, msg)
- if err != nil {
+
+ if err := rtm.sendWithDeadline(msg); err != nil {
rtm.IncomingEvents <- RTMEvent{"outgoing_error", &OutgoingErrorEvent{
Message: msg,
ErrorObj: err,
@@ -227,8 +240,8 @@ func (rtm *RTM) ping() error {
rtm.pings[id] = time.Now()
msg := &Ping{ID: id, Type: "ping"}
- err := websocket.JSON.Send(rtm.conn, msg)
- if err != nil {
+
+ if err := rtm.sendWithDeadline(msg); err != nil {
rtm.Debugf("RTM Error sending 'PING %d': %s", id, err.Error())
return err
}