thread-inactive.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. package frankenphp
  2. import (
  3. "net/http"
  4. )
  5. // representation of a thread with no work assigned to it
  6. // implements the threadHandler interface
  7. type inactiveThread struct {
  8. thread *phpThread
  9. }
  10. func convertToInactiveThread(thread *phpThread) {
  11. if thread.handler == nil {
  12. thread.handler = &inactiveThread{thread: thread}
  13. return
  14. }
  15. thread.setHandler(&inactiveThread{thread: thread})
  16. }
  17. func (handler *inactiveThread) beforeScriptExecution() string {
  18. thread := handler.thread
  19. switch thread.state.get() {
  20. case stateTransitionRequested:
  21. return thread.transitionToNewHandler()
  22. case stateBooting, stateTransitionComplete:
  23. thread.state.set(stateInactive)
  24. // wait for external signal to start or shut down
  25. thread.state.waitFor(stateTransitionRequested, stateShuttingDown)
  26. return handler.beforeScriptExecution()
  27. case stateShuttingDown:
  28. // signal to stop
  29. return ""
  30. }
  31. panic("unexpected state: " + thread.state.name())
  32. }
  33. func (thread *inactiveThread) afterScriptExecution(exitStatus int) {
  34. panic("inactive threads should not execute scripts")
  35. }
  36. func (thread *inactiveThread) getActiveRequest() *http.Request {
  37. panic("inactive threads have no requests")
  38. }