mozilla-services / pushgo

🚨🚨🚨OBSOLETE AND UNMAINTAINED🚨🚨🚨 See Autopush for the current server.
https://github.com/mozilla-services/autopush
Mozilla Public License 2.0
24 stars 10 forks source link

Added server side client ping function (called client_pong) #175

Closed jrconlin closed 9 years ago

jrconlin commented 9 years ago

Set up a routine to send out "{}" frames every period.

Potential TODOs:

Closes #174.

jrconlin commented 9 years ago

Also need to add tests, (once worker tests are built).

ghost commented 9 years ago

Thinking a bit more about this, I wonder if we could use a read deadline in the sniffer loop to avoid the lock and extra goroutine:

sock.Socket.SetReadDeadline(time.Now().Add(self.pongInterval))
if err = websocket.Message.Receive(sock.Socket, &raw); err != nil {
    if ne, ok := err.(net.Error); ok && ne.Timeout() {
        if err = websocket.Message.Send(sock.Socket, "{}"); err == nil {
            continue
        }
    }
    self.stopped = true
    // ...
}

If we don't hear from the client within the pong interval, Receive will be unblocked with a timeout and we can send a ping packet. Otherwise, we'll reset the deadline on the next turn of the loop. What do you think?

bbangert commented 9 years ago

This would be my preference, adding another goroutine per connection isn't free.

jrconlin commented 9 years ago

Agreed. On Dec 21, 2014 9:41 AM, "Ben Bangert" notifications@github.com wrote:

This would be my preference, adding another goroutine per connection isn't free.

— Reply to this email directly or view it on GitHub https://github.com/mozilla-services/pushgo/pull/175#issuecomment-67777862 .

ghost commented 9 years ago

r+; looks great! Thanks for cleaning up the AlwaysRoute cruft, too.