comparison src/c/driver.c @ 682:5bbb542243e8

Redo channels, making them single-client
author Adam Chlipala <adamc@hcoop.net>
date Sun, 29 Mar 2009 11:37:29 -0400
parents 729e65db2e2f
children 9a2c18dab11d
comparison
equal deleted inserted replaced
681:6c9b8875f347 682:5bbb542243e8
169 if (!strcmp(path, "/.msgs")) { 169 if (!strcmp(path, "/.msgs")) {
170 char *id = uw_Basis_requestHeader(ctx, "UrWeb-Client"); 170 char *id = uw_Basis_requestHeader(ctx, "UrWeb-Client");
171 char *pass = uw_Basis_requestHeader(ctx, "UrWeb-Pass"); 171 char *pass = uw_Basis_requestHeader(ctx, "UrWeb-Pass");
172 172
173 if (id && pass) { 173 if (id && pass) {
174 size_t idn = atoi(id); 174 unsigned idn = atoi(id);
175 uw_client_connect(idn, atoi(pass), sock); 175 uw_client_connect(idn, atoi(pass), sock);
176 dont_close = 1; 176 dont_close = 1;
177 fprintf(stderr, "Processed request for messages by client %d\n\n", (int)idn); 177 fprintf(stderr, "Processed request for messages by client %u\n\n", idn);
178 } 178 }
179 break; 179 break;
180 } 180 }
181 181
182 if (inputs = strchr(path, '?')) { 182 if (inputs = strchr(path, '?')) {
215 --retries_left; 215 --retries_left;
216 } 216 }
217 else { 217 else {
218 printf("Fatal error (out of retries): %s\n", uw_error_message(ctx)); 218 printf("Fatal error (out of retries): %s\n", uw_error_message(ctx));
219 219
220 try_rollback(ctx);
221
220 uw_reset_keep_error_message(ctx); 222 uw_reset_keep_error_message(ctx);
221 uw_write_header(ctx, "HTTP/1.1 500 Internal Server Error\n\r"); 223 uw_write_header(ctx, "HTTP/1.1 500 Internal Server Error\n\r");
222 uw_write_header(ctx, "Content-type: text/plain\r\n"); 224 uw_write_header(ctx, "Content-type: text/plain\r\n");
223 uw_write(ctx, "Fatal error (out of retries): "); 225 uw_write(ctx, "Fatal error (out of retries): ");
224 uw_write(ctx, uw_error_message(ctx)); 226 uw_write(ctx, uw_error_message(ctx));
225 uw_write(ctx, "\n"); 227 uw_write(ctx, "\n");
226 228
227 try_rollback(ctx);
228
229 break; 229 break;
230 } 230 }
231 } else if (fk == UNLIMITED_RETRY) 231 } else if (fk == UNLIMITED_RETRY)
232 printf("Error triggers unlimited retry: %s\n", uw_error_message(ctx)); 232 printf("Error triggers unlimited retry: %s\n", uw_error_message(ctx));
233 else if (fk == FATAL) { 233 else if (fk == FATAL) {
234 printf("Fatal error: %s\n", uw_error_message(ctx)); 234 printf("Fatal error: %s\n", uw_error_message(ctx));
235
236 try_rollback(ctx);
235 237
236 uw_reset_keep_error_message(ctx); 238 uw_reset_keep_error_message(ctx);
237 uw_write_header(ctx, "HTTP/1.1 500 Internal Server Error\r\n"); 239 uw_write_header(ctx, "HTTP/1.1 500 Internal Server Error\r\n");
238 uw_write_header(ctx, "Content-type: text/html\r\n"); 240 uw_write_header(ctx, "Content-type: text/html\r\n");
239 uw_write(ctx, "<html><head><title>Fatal Error</title></head><body>"); 241 uw_write(ctx, "<html><head><title>Fatal Error</title></head><body>");
240 uw_write(ctx, "Fatal error: "); 242 uw_write(ctx, "Fatal error: ");
241 uw_write(ctx, uw_error_message(ctx)); 243 uw_write(ctx, uw_error_message(ctx));
242 uw_write(ctx, "\n</body></html>"); 244 uw_write(ctx, "\n</body></html>");
243 245
244 try_rollback(ctx);
245
246 break; 246 break;
247 } else { 247 } else {
248 printf("Unknown uw_handle return code!\n"); 248 printf("Unknown uw_handle return code!\n");
249
250 try_rollback(ctx);
249 251
250 uw_reset_keep_request(ctx); 252 uw_reset_keep_request(ctx);
251 uw_write_header(ctx, "HTTP/1.1 500 Internal Server Error\n\r"); 253 uw_write_header(ctx, "HTTP/1.1 500 Internal Server Error\n\r");
252 uw_write_header(ctx, "Content-type: text/plain\r\n"); 254 uw_write_header(ctx, "Content-type: text/plain\r\n");
253 uw_write(ctx, "Unknown uw_handle return code!\n"); 255 uw_write(ctx, "Unknown uw_handle return code!\n");
254 256
255 try_rollback(ctx);
256
257 break; 257 break;
258 } 258 }
259 259
260 uw_reset_keep_request(ctx);
261
262 if (try_rollback(ctx)) 260 if (try_rollback(ctx))
263 break; 261 break;
262
263 uw_reset_keep_request(ctx);
264 } 264 }
265 265
266 uw_send(ctx, sock); 266 uw_send(ctx, sock);
267 267
268 printf("Done with client.\n\n"); 268 printf("Done with client.\n\n");