Skip to content

Instantly share code, notes, and snippets.

@igm
Last active October 13, 2015 20:48
Show Gist options
  • Save igm/4253741 to your computer and use it in GitHub Desktop.
Save igm/4253741 to your computer and use it in GitHub Desktop.
Active Connection State
type httpTransaction struct {
req *http.Request
rw http.ResponseWriter
done chan bool
...
}
func activeConnectionState(c *conn) connectionStateFn {
select {
...
case httpTx := <-c.httpTransactions:
conn_closed := make(chan bool)
// spawn new go routine to reject parallel connections (with the same session id)
go c.activeConnectionGuard(conn_closed)
// perform necessary stuff on current connection
// ...
// notifify "guard" to terminate when done
conn_closed <- true
return activeConnectionState // return back the same state
case <- time.After(TIMEOUT):
return nil // return back nil state which means to terminate connection
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment