gdipfrun_onethread.pm 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. #######################################################################
  2. # gdipfrun.pm
  3. #
  4. # This routine is a common FastCGI template.
  5. #
  6. # It runs a single looping acceptor thread.
  7. #
  8. # See COPYING for licensing information.
  9. #
  10. #######################################################################
  11. # Perl modules
  12. use strict;
  13. use FCGI;
  14. # global variables
  15. use vars qw($cgi_exit $conf $bad_config);
  16. # GnuDIP modules
  17. use gdiplib;
  18. sub gdipfrun {
  19. # functions to run in thread
  20. my $initfunc = shift;
  21. my $acptfunc = shift;
  22. if (! $initfunc) {
  23. print STDERR "GnuDIP FastCGI has exited - no initialization function passed\n";
  24. exit 1;
  25. }
  26. if (! $acptfunc) {
  27. print STDERR "GnuDIP FastCGI has exited - no accept function passed\n";
  28. exit 1;
  29. }
  30. # force persistence
  31. $$conf{'persistance'} = 'YES';
  32. # create request
  33. my $req = FCGI::Request();
  34. if (! $req->IsFastCGI()) {
  35. print STDERR "GnuDIP FastCGI not called as FastCGI program\n";
  36. return;
  37. }
  38. # configuration error handler for now
  39. $bad_config = sub {
  40. # go do Finish
  41. goto FINISH;
  42. };
  43. # run initialization
  44. &$initfunc();
  45. # accept connections
  46. while ($req->Accept() eq 0) {
  47. # override for "exit"
  48. $cgi_exit = sub {
  49. # next connection
  50. goto ENDLOOP;
  51. };
  52. # run the CGI
  53. &$acptfunc();
  54. ENDLOOP:
  55. undef $cgi_exit;
  56. $req->Finish();
  57. }
  58. FINISH:
  59. undef $bad_config;
  60. # should never get here
  61. print STDERR "GnuDIP FastCGI has ended unexpectedly\n";
  62. }
  63. #####################################################
  64. # must return 1
  65. #####################################################
  66. 1;