@@ -6,7 +6,7 @@ static void ngx_http_redirectionio_dummy_handler(ngx_event_t *wev);
6
6
7
7
static ngx_int_t ngx_http_redirectionio_read_uint32 (ngx_connection_t * c , uint32_t * uint32 );
8
8
9
- static ngx_int_t ngx_http_redirectionio_read_string (ngx_connection_t * c , char * string , ssize_t buf_size );
9
+ static ngx_int_t ngx_http_redirectionio_read_string (ngx_connection_t * c , char * string , ssize_t buf_size , ssize_t * readed );
10
10
11
11
ngx_int_t ngx_http_redirectionio_pool_construct (void * * rp , void * params ) {
12
12
ngx_pool_t * pool ;
@@ -157,55 +157,69 @@ void ngx_http_redirectionio_read_handler(ngx_event_t *rev) {
157
157
ngx_connection_t * c ;
158
158
ngx_http_request_t * r ;
159
159
ngx_http_redirectionio_ctx_t * ctx ;
160
- char * read ;
161
- uint32_t rlen ;
162
160
ngx_int_t rv ;
163
161
164
162
c = rev -> data ;
165
163
r = c -> data ;
166
164
ctx = ngx_http_get_module_ctx (r , ngx_http_redirectionio_module );
167
- ctx -> resource -> peer .connection -> read -> handler = ngx_http_redirectionio_dummy_handler ;
168
-
169
165
170
166
if (rev -> timedout ) {
171
- ngx_log_error (NGX_LOG_ERR , r -> connection -> log , 0 , "[redirectionio] connection timeout while reading, skipping module for this request" );
172
-
173
167
ctx -> connection_error = 1 ;
174
168
ctx -> read_handler (rev , NULL );
169
+ ctx -> resource -> peer .connection -> read -> handler = ngx_http_redirectionio_dummy_handler ;
170
+
171
+ ngx_log_error (NGX_LOG_ERR , r -> connection -> log , 0 , "[redirectionio] connection timeout while reading, skipping module for this request" );
175
172
176
173
return ;
177
174
}
178
175
179
- if (rev -> timer_set ) {
180
- ngx_del_timer ( rev );
181
- }
176
+ if (ctx -> action_string_len == 0 ) {
177
+ // Read uint32
178
+ rv = ngx_http_redirectionio_read_uint32 ( c , & ctx -> action_string_len );
182
179
183
- // Read uint32
184
- rv = ngx_http_redirectionio_read_uint32 (c , & rlen );
180
+ if (rv != NGX_OK ) {
181
+ ctx -> connection_error = 1 ;
182
+ ctx -> read_handler (rev , NULL );
183
+ ctx -> resource -> peer .connection -> read -> handler = ngx_http_redirectionio_dummy_handler ;
185
184
186
- if (rv != NGX_OK ) {
187
- ctx -> connection_error = 1 ;
188
- ctx -> read_handler (rev , NULL );
185
+ ngx_log_error (NGX_LOG_ERR , r -> connection -> log , 0 , "[redirectionio] connection error while reading length, skipping module for this request" );
189
186
190
- ngx_log_error (NGX_LOG_ERR , r -> connection -> log , 0 , "[redirectionio] connection error while reading length, skipping module for this request" );
187
+ if (rev -> timer_set ) {
188
+ ngx_del_timer (rev );
189
+ }
191
190
192
- return ;
191
+ return ;
192
+ }
193
+
194
+ ctx -> action_string = (char * )ngx_pcalloc (r -> pool , ctx -> action_string_len + 1 );
193
195
}
194
196
195
- // Read string
196
- read = (char * )ngx_pcalloc (r -> pool , rlen + 1 );
197
- rv = ngx_http_redirectionio_read_string (c , read , rlen );
197
+ rv = ngx_http_redirectionio_read_string (c , ctx -> action_string , ctx -> action_string_len , & ctx -> action_string_readed );
198
+
199
+ if (rv == NGX_AGAIN ) {
200
+ return ;
201
+ }
198
202
199
203
if (rv != NGX_OK ) {
200
204
ctx -> connection_error = 1 ;
201
205
ctx -> read_handler (rev , NULL );
206
+ ctx -> resource -> peer .connection -> read -> handler = ngx_http_redirectionio_dummy_handler ;
202
207
203
- ngx_log_error (NGX_LOG_ERR , r -> connection -> log , 0 , "[redirectionio] connection error while reading length, skipping module for this request" );
208
+ if (rev -> timer_set ) {
209
+ ngx_del_timer (rev );
210
+ }
211
+
212
+ ngx_log_error (NGX_LOG_ERR , r -> connection -> log , 0 , "[redirectionio] connection error while reading string: %d, skipping module for this request" , rv );
204
213
205
214
return ;
206
215
}
207
216
208
- ctx -> read_handler (rev , (const char * )read );
217
+ if (rev -> timer_set ) {
218
+ ngx_del_timer (rev );
219
+ }
220
+
221
+ ctx -> resource -> peer .connection -> read -> handler = ngx_http_redirectionio_dummy_handler ;
222
+ ctx -> read_handler (rev , (const char * )ctx -> action_string );
209
223
}
210
224
211
225
static void ngx_http_redirectionio_dummy_handler (ngx_event_t * wev ) {
@@ -233,19 +247,17 @@ static ngx_int_t ngx_http_redirectionio_read_uint32(ngx_connection_t *c, uint32_
233
247
return NGX_OK ;
234
248
}
235
249
236
- static ngx_int_t ngx_http_redirectionio_read_string (ngx_connection_t * c , char * string , ssize_t buf_size ) {
250
+ static ngx_int_t ngx_http_redirectionio_read_string (ngx_connection_t * c , char * string , ssize_t buf_size , ssize_t * readed ) {
237
251
ssize_t srlen = buf_size ;
238
- ssize_t sdrlen = 0 ;
239
252
240
- while (sdrlen < buf_size ) {
241
- srlen = ngx_recv (c , (u_char * )(string + sdrlen ), srlen );
253
+ while (* readed < buf_size ) {
254
+ srlen = ngx_recv (c , (u_char * )(string + * readed ), buf_size - * readed );
242
255
243
- if (srlen <= 0 ) {
256
+ if (srlen < 0 ) {
244
257
return srlen ;
245
258
}
246
259
247
- sdrlen += srlen ;
248
- srlen = buf_size - sdrlen ;
260
+ * readed += srlen ;
249
261
}
250
262
251
263
* (string + buf_size ) = '\0' ;
0 commit comments