Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2017
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. # include <stdlib.h>
  2. # include <stdio.h>
  3.  
  4. # include <sys/stat.h>
  5.  
  6. # include <pthread.h>
  7.  
  8. # include <fcgiapp.h>
  9.  
  10. const char* const sockpath = "/tmp/fcgicpp.sock";
  11.  
  12. void* start_fcgi_worker(void* arg);
  13.  
  14. struct FCGI_Info
  15. {
  16. int fcgi_fd;
  17. };
  18.  
  19. int main(void)
  20. {
  21. int fcgifd = FCGX_OpenSocket(sockpath,128);
  22.  
  23. chmod(sockpath,0777);
  24.  
  25. if ( 0 > fcgifd )
  26. {
  27. printf("Error opening socket\n");
  28. exit(1);
  29. }
  30.  
  31. /*
  32. if ( FCGX_IsCGI() )
  33. {
  34. printf("Please run this process as FastCGI process.\n");
  35. exit(1);
  36. }
  37. */
  38.  
  39. const unsigned int n_threads = 4;
  40.  
  41. pthread_t threads[n_threads];
  42.  
  43. struct FCGI_Info info;
  44. info.fcgi_fd = fcgifd;
  45.  
  46. for ( unsigned int i = 0; i < n_threads; i++ )
  47. {
  48. pthread_create(&threads[i],NULL,start_fcgi_worker,(void*)&info);
  49. }
  50.  
  51. // Wait indefinitely
  52. for ( unsigned int i = 0; i < n_threads; i++ )
  53. {
  54. pthread_join(threads[i],NULL);
  55. }
  56.  
  57. return 0;
  58. }
  59.  
  60. void* start_fcgi_worker(void* arg)
  61. {
  62. struct FCGI_Info* info = (struct FCGI_Info*)arg;
  63.  
  64. FCGX_Init();
  65.  
  66. FCGX_Request request;
  67.  
  68. FCGX_InitRequest(&request,info->fcgi_fd,0);
  69.  
  70. while ( 1 )
  71. {
  72. FCGX_Accept_r(&request);
  73.  
  74. FCGX_PutStr("Content-type: text/plain\r\n\r\n",28,request.out);
  75. FCGX_PutStr("Hey!\n",5,request.out);
  76.  
  77. FCGX_Finish_r(&request);
  78. }
  79.  
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement