( writer http.ResponseWriter, request *http.Request )
| 75 | } |
| 76 | |
| 77 | func ( s *Server ) connect( writer http.ResponseWriter, request *http.Request ) { |
| 78 | if request.Method != "GET" { http.Error( writer, http.StatusText( http.StatusNotFound ), http.StatusNotFound ); return } |
| 79 | select { |
| 80 | case s.connectionOpsLock<-struct{}{}: defer func() { <-s.connectionOpsLock }(); break |
| 81 | case <-time.NewTimer( time.Second ).C: http.Error( writer, http.StatusText( http.StatusConflict ), http.StatusConflict ); return |
| 82 | } |
| 83 | |
| 84 | writer.Header().Add( "content-type", "application/json" ) |
| 85 | switch code := s.connection.Code(); code { |
| 86 | case connection.Routed: break |
| 87 | case connection.Clean: |
| 88 | if err := s.connection.Init(); err != nil { |
| 89 | writer.Write( Result{ Error: &Error{ Code: CodeConnect, Message: err.Error() } }.Json() ); return |
| 90 | } |
| 91 | break |
| 92 | default: writer.Write( Result{ Error: &Error{ Code: CodeConnect, Message: "bad state: " + code } }.Json() ); return |
| 93 | } |
| 94 | wg := sync.WaitGroup{} |
| 95 | wg.Add( 1 ) |
| 96 | s.connection.SetConnectNotify( func( err error ) { |
| 97 | switch err { |
| 98 | case nil: writer.Write( Result{ Result: s.connection.State() }.Json() ) |
| 99 | default: writer.Write( Result{ Error: &Error{ Code: CodeConnect, Message: err.Error() } }.Json() ) |
| 100 | } |
| 101 | wg.Done() |
| 102 | } ) |
| 103 | s.connection.ScheduleConnect( 0 ) |
| 104 | wg.Wait() |
| 105 | } |
| 106 | |
| 107 | // disconnect is gentle, leaves the client in "routed" state, i.e. leak protection might be active when configured |
| 108 | func ( s *Server ) disconnect( writer http.ResponseWriter, request *http.Request ) { |
nothing calls this directly
no test coverage detected