PageRenderTime 66ms CodeModel.GetById 61ms app.highlight 2ms RepoModel.GetById 2ms app.codeStats 0ms

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