/library/server/fcgi/implementation/linux/fcgi_imp.e

http://github.com/jocelyn/EiffelWebReloaded · Specman e · 183 lines · 89 code · 26 blank · 68 comment · 2 complexity · c782be5da4bee0ba213d626f8f91d33f MD5 · raw file

  1. note
  2. description: "Implementation for the FCGI_I interface"
  3. legal: "See notice at end of class."
  4. status: "See notice at end of class."
  5. date: "$Date$"
  6. revision: "$Revision$"
  7. deferred class FCGI_IMP
  8. inherit
  9. FCGI_I
  10. STRING_HANDLER
  11. feature {NONE} -- Initialization
  12. make
  13. -- Initialize FCGI interface
  14. do
  15. create fcgi
  16. end
  17. fcgi: FCGI_C_API
  18. -- FastCGI C API primitives
  19. feature -- Access
  20. fcgi_environ: POINTER
  21. do
  22. Result := fcgi.environ
  23. end
  24. feature -- FCGI Connection
  25. fcgi_listen: INTEGER
  26. -- Listen to the FCGI input stream
  27. -- Return 0 for successful calls, -1 otherwise.
  28. do
  29. Result := {FCGI_C_API}.accept
  30. end
  31. update_eif_environ
  32. external
  33. "C inline use <string.h>"
  34. alias
  35. "[
  36. eif_environ = (char**) environ;
  37. ]"
  38. end
  39. fcgi_finish
  40. -- Finish current request from HTTP server started from
  41. -- the most recent call to `fcgi_accept'.
  42. do
  43. {FCGI_C_API}.finish
  44. end
  45. set_fcgi_exit_status (v: INTEGER)
  46. do
  47. {FCGI_C_API}.set_exit_status (-2)
  48. end
  49. feature -- FCGI output
  50. put_string (a_str: STRING)
  51. -- Put `a_str' on the FastCGI stdout.
  52. local
  53. l_c_str: C_STRING
  54. do
  55. l_c_str := c_buffer
  56. l_c_str.set_string (a_str)
  57. {FCGI_C_API}.put_string (l_c_str.item, l_c_str.count)
  58. end
  59. -- fcgi_printf (fmt: STRING; args: FINITE[ANY])
  60. -- -- Put args, formatted per 'fmt' on the FastCGI stdout.
  61. -- local
  62. -- l_c_str: C_STRING
  63. -- do
  64. -- create l_c_str.make (apf.aprintf (fmt, args))
  65. -- {FCGI_C_API}.put_string (l_c_str.item, l_c_str.count)
  66. -- end
  67. feature -- FCGI Input
  68. copy_from_stdin (n: INTEGER; tf: FILE)
  69. -- Read up to n bytes from stdin and write to given file
  70. local
  71. l_c_str: C_STRING
  72. num, readsize, writecount: INTEGER
  73. done: BOOLEAN
  74. do
  75. --put_trace ("copy_from_stdin, n=" +n.out)
  76. readsize := n.min (K_input_bufsize)
  77. --put_trace ("copy_from_stdin, readsize=" +readsize.out)
  78. l_c_str := c_buffer
  79. from
  80. until done or writecount >= n
  81. loop
  82. num := {FCGI_C_API}.read_content_into (l_c_str.item, readsize)
  83. --put_trace ("copy_from_stdin, num=" +num.out)
  84. if num = 0 then
  85. -- EOF
  86. done := True
  87. else
  88. tf.put_managed_pointer (c_buffer.managed_data, 0, num)
  89. writecount := writecount + num
  90. end
  91. end
  92. end
  93. feature {NONE} -- Implementation: FCGI Input
  94. fill_pointer_from_stdin (p: POINTER; n: INTEGER): INTEGER
  95. -- Read up to `n' bytes from stdin and store in pointer `p'
  96. -- and return number of bytes read.
  97. do
  98. Result := {FCGI_C_API}.read_content_into (p, n)
  99. end
  100. feature -- I/O Routines
  101. --RFO read_stdin_into (a_str: STRING)
  102. --RFO -- Read a string from the `stdin' into `a_str'.
  103. --RFO require
  104. --RFO a_str_not_void: a_str /= Void
  105. --RFO local
  106. --RFO l_c_str: C_STRING
  107. --RFO n: INTEGER
  108. --RFO do
  109. --RFO l_c_str := c_buffer
  110. --RFO n := {FCGI_C_API}.read_content_into (l_c_str.item, l_c_str.capacity)
  111. --RFO a_str.set_count (n)
  112. --RFO l_c_str.read_substring_into (a_str, 1, n)
  113. --RFO end
  114. --RFO read_string_into (a_str: STRING)
  115. --RFO require
  116. --RFO exists: a_str /= Void
  117. --RFO local
  118. --RFO l_c_str: C_STRING
  119. --RFO p: POINTER
  120. --RFO do
  121. --RFO create l_c_str.make_empty (1024)
  122. --RFO p := {FCGI_C_API}.gets (l_c_str.item)
  123. --RFO-- if p /= default_pointer and p = l_c_str.item then
  124. --RFO a_str.resize (l_c_str.count)
  125. --RFO l_c_str.read_string_into (a_str)
  126. --RFO-- else
  127. --RFO-- put_error_line ("Bad pointer from gets")
  128. --RFO-- end
  129. --RFO end
  130. --RFO read_line
  131. --RFO -- Read up to the next end of line, or end of input
  132. --RFO -- Leave result in last_string
  133. --RFO -- Newline character is absent from result
  134. --RFO do
  135. --RFO if last_string = Void then
  136. --RFO create Result.make (K_input_bufsize)
  137. --RFO else
  138. --RFO last_string.wipe_out
  139. --RFO end
  140. --RFO-- if input_filename /= Void then
  141. --RFO-- io.read_line
  142. --RFO-- last_string.append (io.last_string)
  143. --RFO-- else
  144. --RFO read_string_into (last_string)
  145. --RFO-- end
  146. --RFO end
  147. note
  148. copyright: "Copyright (c) 1984-2011, Eiffel Software and others"
  149. license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
  150. source: "[
  151. Eiffel Software
  152. 5949 Hollister Ave., Goleta, CA 93117 USA
  153. Telephone 805-685-1006, Fax 805-685-6869
  154. Website http://www.eiffel.com
  155. Customer support http://support.eiffel.com
  156. ]"
  157. end