Mercurial > urweb
comparison src/c/driver.c @ 671:729e65db2e2f
Transactionalize channel operations
author | Adam Chlipala <adamc@hcoop.net> |
---|---|
date | Tue, 24 Mar 2009 14:44:45 -0400 |
parents | b0c1a46b1f15 |
children | 5bbb542243e8 |
comparison
equal
deleted
inserted
replaced
670:f73913d97a40 | 671:729e65db2e2f |
---|---|
51 static pthread_mutex_t queue_mutex = PTHREAD_MUTEX_INITIALIZER; | 51 static pthread_mutex_t queue_mutex = PTHREAD_MUTEX_INITIALIZER; |
52 static pthread_cond_t queue_cond = PTHREAD_COND_INITIALIZER; | 52 static pthread_cond_t queue_cond = PTHREAD_COND_INITIALIZER; |
53 | 53 |
54 #define MAX_RETRIES 5 | 54 #define MAX_RETRIES 5 |
55 | 55 |
56 int uw_db_begin(uw_context); | |
57 int uw_db_commit(uw_context); | |
58 int uw_db_rollback(uw_context); | |
59 | |
60 static int try_rollback(uw_context ctx) { | 56 static int try_rollback(uw_context ctx) { |
61 int r = uw_db_rollback(ctx); | 57 int r = uw_rollback(ctx); |
62 | 58 |
63 if (r) { | 59 if (r) { |
64 printf("Error running SQL ROLLBACK\n"); | 60 printf("Error running SQL ROLLBACK\n"); |
65 uw_reset(ctx); | 61 uw_reset(ctx); |
66 uw_write(ctx, "HTTP/1.1 500 Internal Server Error\n\r"); | 62 uw_write(ctx, "HTTP/1.1 500 Internal Server Error\n\r"); |
204 } | 200 } |
205 | 201 |
206 printf("Serving URI %s....\n", path); | 202 printf("Serving URI %s....\n", path); |
207 | 203 |
208 while (1) { | 204 while (1) { |
209 if (uw_db_begin(ctx)) { | |
210 printf("Error running SQL BEGIN\n"); | |
211 if (retries_left) | |
212 --retries_left; | |
213 else { | |
214 fk = FATAL; | |
215 uw_reset(ctx); | |
216 uw_write_header(ctx, "HTTP/1.1 500 Internal Server Error\n\r"); | |
217 uw_write_header(ctx, "Content-type: text/plain\r\n\r\n"); | |
218 uw_write(ctx, "Error running SQL BEGIN\n"); | |
219 | |
220 break; | |
221 } | |
222 } | |
223 | |
224 uw_write_header(ctx, "HTTP/1.1 200 OK\r\n"); | 205 uw_write_header(ctx, "HTTP/1.1 200 OK\r\n"); |
225 | 206 |
226 strcpy(path_copy, path); | 207 strcpy(path_copy, path); |
227 fk = uw_begin(ctx, path_copy); | 208 fk = uw_begin(ctx, path_copy); |
228 if (fk == SUCCESS) { | 209 if (fk == SUCCESS) { |
229 if (uw_db_commit(ctx)) { | 210 uw_commit(ctx); |
230 fk = FATAL; | |
231 | |
232 printf("Error running SQL COMMIT\n"); | |
233 uw_reset(ctx); | |
234 uw_write_header(ctx, "HTTP/1.1 500 Internal Server Error\n\r"); | |
235 uw_write_header(ctx, "Content-type: text/plain\r\n"); | |
236 uw_write(ctx, "Error running SQL COMMIT\n"); | |
237 } | |
238 | |
239 break; | 211 break; |
240 } else if (fk == BOUNDED_RETRY) { | 212 } else if (fk == BOUNDED_RETRY) { |
241 if (retries_left) { | 213 if (retries_left) { |
242 printf("Error triggers bounded retry: %s\n", uw_error_message(ctx)); | 214 printf("Error triggers bounded retry: %s\n", uw_error_message(ctx)); |
243 --retries_left; | 215 --retries_left; |