Last active
October 13, 2015 20:48
-
-
Save igm/4253741 to your computer and use it in GitHub Desktop.
Active Connection State
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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