ChipMaster's trial hacks on C++CMS starting with v1.2.1. Not sure I'll follow on with the v2 since it looks to be breaking and mostly frivolous.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

92 lines
1.5 KiB

  1. #include "fcgi.h"
  2. #include "cppcms_error.h"
  3. #include <errno.h>
  4. namespace cppcms {
  5. fcgi_stream::fcgi_stream(FCGX_Request &req) :
  6. std::ostream(&fcgi_cout),
  7. request(req),
  8. fcgi_cout(req.out),
  9. fcgi_cerr(req.err),
  10. stream_cerr(&fcgi_cerr)
  11. {
  12. };
  13. std::string fcgi_stream::getenv(const char *variable)
  14. {
  15. char const *p;
  16. if((p=FCGX_GetParam(variable,request.envp))!=NULL)
  17. return p;
  18. return "";
  19. };
  20. size_t fcgi_stream::read(char *d,size_t len)
  21. {
  22. return FCGX_GetStr(d,len,request.in);
  23. };
  24. std::ostream &fcgi_stream::err()
  25. {
  26. return stream_cerr;
  27. };
  28. fcgi_stream::~fcgi_stream()
  29. {
  30. FCGX_Finish_r(&request);
  31. };
  32. pthread_once_t fcgi_api::init_fcgi = PTHREAD_ONCE_INIT;
  33. void fcgi_api::init()
  34. {
  35. FCGX_Init();
  36. }
  37. fcgi_api::fcgi_api(char const *socket,int backlog)
  38. {
  39. pthread_once(&init_fcgi,fcgi_api::init);
  40. if(socket && socket[0]!='\0') {
  41. fd=FCGX_OpenSocket(socket,backlog);
  42. }
  43. else {
  44. fd=0; // STDIN
  45. }
  46. if(fd<0) {
  47. throw cppcms_error(errno,"FCGX_OpenSocket");
  48. }
  49. }
  50. cgi_session *fcgi_api::accept_session()
  51. {
  52. FCGX_Request *request=new FCGX_Request();
  53. FCGX_InitRequest(request,fd,FCGI_FAIL_ACCEPT_ON_INTR);
  54. if(FCGX_Accept_r(request)<0) {
  55. delete request;
  56. return NULL;
  57. }
  58. return new fcgi_session(request,NULL);
  59. }
  60. bool fcgi_session::prepare()
  61. {
  62. connection=new cgicc_connection_fast_cgi(*request);
  63. return true;
  64. }
  65. cgicc_connection &fcgi_session::get_connection()
  66. {
  67. if(!connection) {
  68. throw cppcms_error("Connection was not prepared");
  69. }
  70. return *connection;
  71. }
  72. fcgi_api::~fcgi_api()
  73. {
  74. if(fd!=-1) close(fd);
  75. }
  76. };