r17091 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r17090‎ | r17091 | r17092 >
Date:18:31, 18 October 2006
Author:river
Status:old
Tags:
Comment:
cleanups
Modified paths:
  • /trunk/willow/src/include/whttp_entity.h (modified) (history)
  • /trunk/willow/src/include/willow.h (modified) (history)
  • /trunk/willow/src/include/wnet.h (modified) (history)
  • /trunk/willow/src/willow/confparse.cc (modified) (history)
  • /trunk/willow/src/willow/wbackend.cc (modified) (history)
  • /trunk/willow/src/willow/wcache.cc (modified) (history)
  • /trunk/willow/src/willow/wconfig.cc (modified) (history)
  • /trunk/willow/src/willow/whttp.cc (modified) (history)
  • /trunk/willow/src/willow/whttp_entity.cc (modified) (history)
  • /trunk/willow/src/willow/wnet.cc (modified) (history)
  • /trunk/willow/src/willow/wnet_libevent.cc (modified) (history)

Diff [purge]

Index: trunk/willow/src/willow/wnet.cc
@@ -274,18 +274,9 @@
275275 {
276276 struct wrtbuf *buf;
277277 int i;
278 -#ifdef WILLOW_DEBUG
279 - char *p;
280 -#endif
281278
282279 buf = (wrtbuf *)e->fde_wdata;
283280 while ((i = write(e->fde_fd, (char *)buf->wb_buf + buf->wb_done, buf->wb_size - buf->wb_done)) > -1) {
284 -#ifdef WILLOW_DEBUG_no
285 - (void)fprintf(stderr, "write buf: [");
286 - for (p = ((char *)buf->wb_buf + buf->wb_done); p < ((char *)buf->wb_buf + buf->wb_done + i); ++p)
287 - (void)fputc(*p, stderr);
288 - (void)fputs("]\n", stderr);
289 -#endif
290281 buf->wb_done += i;
291282 WDEBUG((WLOG_DEBUG, "%d of %d done", buf->wb_done, buf->wb_size));
292283 if (buf->wb_done == (off_t)buf->wb_size) {
Index: trunk/willow/src/willow/wbackend.cc
@@ -37,7 +37,6 @@
3838 static struct backend *next_backend(string const &url);
3939 static uint32_t carp_urlhash(string const &);
4040 static uint32_t carp_hosthash(string const &);
41 -static uint32_t carp_combine(string const &, uint32_t);
4241 static void carp_recalc(string const &url);
4342 static void carp_calc(void);
4443 static int becarp_cmp(backend const *a, backend const *b);
@@ -159,11 +158,10 @@
160159 wlog(WLOG_WARNING, "%s: [%d] %s; retry in %d seconds",
161160 cbd->bc_backend->be_name.c_str(), error, strerror(error), config.backend_retry);
162161 cbd->bc_backend->be_dead = 1;
163 - cbd->bc_backend->be_time = time(NULL) + config.backend_retry;
 162+ cbd->bc_backend->be_time = retry;
164163 if (get_backend(cbd->bc_url, cbd->bc_func, cbd->bc_data, 0) == -1) {
165164 cbd->bc_func(NULL, NULL, cbd->bc_data);
166165 }
167 -
168166 wfree(cbd);
169167 return;
170168 }
@@ -227,14 +225,6 @@
228226 return rotl(h, 21);
229227 }
230228
231 -static uint32_t
232 -carp_combine(string const &url, uint32_t host)
233 -{
234 - uint32_t c = carp_urlhash(url) ^ host;
235 - c += c * 0x62531965;
236 - return rotl(c, 21);
237 -}
238 -
239229 static void
240230 carp_calc(void)
241231 {
Index: trunk/willow/src/willow/confparse.cc
@@ -117,8 +117,8 @@
118118 if_true(std::string const &if_)
119119 {
120120 if_entry *e;
121 -char const *dir, *od;
122 - dir = od = if_.c_str();
 121+char const *dir;
 122+ dir = if_.c_str();
123123 dir += sizeof("%if");
124124 while (isspace(*dir))
125125 dir++;
@@ -202,9 +202,6 @@
203203 bool is_template
204204 ) {
205205 tree_entry *n, *e;
206 -value *value;
207 -void *pp = NULL;
208 -const char *key;
209206 if ((e = t.find(block, templatename)) == NULL)
210207 return e;
211208 n = t.find_or_new(block, name, pos, unnamed, true);
@@ -217,9 +214,6 @@
218215 find_untouched(tree &t)
219216 {
220217 int i = 0;
221 -const char *key;
222 -value *val;
223 -void *pp = NULL;
224218 vector<tree_entry>::const_iterator it, end;
225219 map<string, value>::const_iterator vit, vend;
226220 for (it = t.entries.begin(), end = t.entries.end(); it != end; ++it) {
@@ -264,7 +258,6 @@
265259 bool
266260 tree::add(tree_entry const &item)
267261 {
268 -value *existing;
269262 /* if the entry already exists, do nothing */
270263 if (find_item(item) != NULL)
271264 return false;
Index: trunk/willow/src/willow/wcache.cc
@@ -30,7 +30,6 @@
3131
3232 #define CACHEDIR "__objects__"
3333
34 -static void dberror(const char *, int);
3534 static int cache_next_id(void);
3635 static void run_expiry(int, short, void*);
3736 static void wcache_evict(struct cache_object *);
@@ -95,7 +94,6 @@
9695 {
9796 char *path;
9897 int plen;
99 - int i;
10098
10199 plen = strlen(config.caches[0].dir) + 1 + sizeof(CACHEDIR) + 1 + 6 + int_max_len;
102100 path = (char *)wmalloc(plen + 1);
@@ -113,7 +111,7 @@
114112 struct cache_state state;
115113
116114 for (cd = config.caches; cd < config.caches + config.ncaches; ++cd) {
117 - size_t len, dlen;
 115+ size_t dlen;
118116 char *dir;
119117
120118 dlen = strlen(cd->dir) + sizeof(CACHEDIR) + 2 + 6 /* 0/1/2/ */;
@@ -179,7 +177,6 @@
180178 wcache_init(int readstate)
181179 {
182180 struct cachedir *cd;
183 - int i;
184181
185182 if (config.ncaches == 0) {
186183 wlog(WLOG_WARNING, "no cache directories specified");
@@ -289,11 +286,12 @@
290287 wlog(WLOG_WARNING, "opening cache dir %s: %s", stpath, strerror(errno));
291288 exit(8);
292289 }
293 - fprintf(stfil, "%lld %lld\n", state->cs_id, state->cs_size);
 290+ fprintf(stfil, "%llu %llu\n", (w_size_t) state->cs_id, (w_size_t)state->cs_size);
294291 TAILQ_FOREACH(obj, &objects, entries) {
295292 if (!obj->co_complete)
296293 continue;
297 - fprintf(stfil, "%s %s %d %lu %lu %d %lu\n", obj->co_key, obj->co_path, obj->co_size,
 294+ fprintf(stfil, "%s %s %lu %lu %lu %d %lu\n", obj->co_key, obj->co_path,
 295+ (unsigned long) obj->co_size,
298296 (unsigned long) obj->co_time, (unsigned long) obj->co_lru, obj->co_id,
299297 (unsigned long) obj->co_expires);
300298 }
@@ -306,10 +304,7 @@
307305 FILE *stfil;
308306 char *stpath;
309307 int stlen;
310 -struct cache_object *obj;
311 - int i;
312308 char *s;
313 - size_t l;
314309
315310 stlen = strlen(config.caches[0].dir) + 1 + 5 + 1;
316311 if ((stpath = (char *)wmalloc(stlen)) == NULL)
@@ -322,7 +317,7 @@
323318 return;
324319 }
325320
326 - if (fscanf(stfil, "%lld %lld\n", &state->cs_id, &state->cs_size) != 2) {
 321+ if (fscanf(stfil, "%llu %llu\n", &state->cs_id, &state->cs_size) != 2) {
327322 wlog(WLOG_ERROR, "data format error in cache state file %s", stpath);
328323 exit(8);
329324 }
@@ -410,8 +405,6 @@
411406 run_expiry(int fd, short ev, void *data)
412407 {
413408 w_size_t wantsize;
414 - int i;
415 -struct cache_object *obj;
416409
417410 WDEBUG((WLOG_DEBUG, "expire: start, run every %d, cache is %lld bytes large",
418411 config.cache_expevery, state.cs_size));
Index: trunk/willow/src/willow/wconfig.cc
@@ -59,7 +59,7 @@
6060 nl->port = port;
6161 nl->name = e.item_key;
6262 nl->addr.sin_family = AF_INET;
63 - nl->addr.sin_port = htons(nl->port);
 63+ nl->addr.sin_port = htons((unsigned short)nl->port);
6464 nl->addr.sin_addr.s_addr = inet_addr(nl->name.c_str());
6565 wlog(WLOG_NOTICE, "listening on %s:%d", e.item_key.c_str(), port);
6666 }
@@ -89,8 +89,6 @@
9090 config.ncaches++;
9191 }
9292
93 -extern int parse_error;
94 -
9593 bool
9694 read_config(string const &file)
9795 {
Index: trunk/willow/src/willow/whttp_entity.cc
@@ -87,12 +87,7 @@
8888 static int write_zlib_eof(struct http_entity *);
8989 static int write_data(struct http_entity *, void *buf, size_t len);
9090
91 -static void entity_send_headers_done(struct fde *, void *, int);
92 -static void entity_send_fde_write_done(struct fde *, void *, int);
93 -static void entity_send_buf_done(struct fde *, void *, int);
94 -static void entity_send_fde_read(struct fde *);
9591 static void entity_send_file_done(struct fde *, void *, int);
96 -static void entity_send_target_read(struct bufferevent *, void *);
9792 static void entity_send_target_write(struct bufferevent *, void *);
9893 static void entity_send_target_error(struct bufferevent *, short, void *);
9994
@@ -104,6 +99,7 @@
105100 /* -4 */ "Invalid request type",
106101 /* -5 */ "Too many headers",
107102 /* -6 */ "Forwarding loop detected",
 103+ /* -7 */ "Invalid Accept-Encoding",
108104 };
109105
110106 const char *ent_encodings[] = {
@@ -173,16 +169,11 @@
174170 entity_read_callback, NULL, entity_error_callback, entity);
175171 bufferevent_disable(entity->_he_frombuf, EV_WRITE);
176172 bufferevent_enable(entity->_he_frombuf, EV_READ);
177 -// wnet_register(entity->he_source.fde.fde->fde_fd, FDE_READ, entity_read_callback, entity);
178 - //entity_read_callback(entity->he_source.fde);
179173 }
180174
181175 void
182176 entity_send(fde *fde, http_entity *entity, header_cb cb, void *data, int flags)
183177 {
184 - char status[4];
185 - int wn_flags = 0;
186 - char *hdr;
187178 struct header_list *hl;
188179 int window = 15;
189180
@@ -539,14 +530,6 @@
540531 }
541532
542533 static void
543 -entity_send_target_read(struct bufferevent *buf, void *d)
544 -{
545 - /*
546 - * Read from target possible. This never happens.
547 - */
548 -}
549 -
550 -static void
551534 entity_send_target_write(struct bufferevent *buf, void *d)
552535 {
553536 struct http_entity *entity = (http_entity *)d;
@@ -873,13 +856,13 @@
874857 write(fd, &i, sizeof(i));
875858
876859 while (head->hl_next) {
877 - int i, j;
 860+ int j, k;
878861 head = head->hl_next;
879 - i = strlen(head->hl_name);
880 - write(fd, &i, sizeof(i));
 862+ k = strlen(head->hl_name);
 863+ write(fd, &k, sizeof(k));
881864 j = strlen(head->hl_value);
882865 write(fd, &j, sizeof(j));
883 - write(fd, head->hl_name, i);
 866+ write(fd, head->hl_name, k);
884867 write(fd, head->hl_value, j);
885868 }
886869 }
@@ -887,21 +870,21 @@
888871 int
889872 header_undump(header_list *head, int fd, off_t *len)
890873 {
891 - int i = 0, j = 0, n = 0;
 874+ int i = 0, j = 0, sz = 0;
892875 struct header_list *it = head;
893876 ssize_t r;
894877
895878 *len = 0;
896879 bzero(head, sizeof(*head));
897 - if ((r = read(fd, &n, sizeof(n))) < 0) {
 880+ if ((r = read(fd, &sz, sizeof(sz))) < 0) {
898881 wlog(WLOG_WARNING, "reading cache file: %s", strerror(errno));
899882 return -1; /* XXX */
900883 }
901884
902885 *len += r;
903 - WDEBUG((WLOG_DEBUG, "header_undump: %d entries", n));
 886+ WDEBUG((WLOG_DEBUG, "header_undump: %d entries", sz));
904887
905 - while (n--) {
 888+ while (sz--) {
906889 char *n, *v, *s;
907890 int k;
908891
@@ -967,7 +950,7 @@
968951 if (isspace(*line)) {
969952 char *s = line;
970953 if (!entity->he_headers.hl_next) {
971 - error = -1;
 954+ error = ENT_ERR_INVHDR;
972955 goto error;
973956 }
974957 while (isspace(*s))
@@ -1022,7 +1005,7 @@
10231006 } else if (!strcasecmp(hdr[0], "Accept-Encoding")) {
10241007 if (!entity->he_flags.response &&
10251008 qvalue_parse(&entity->he_rdata.request.accept_encoding, value) == -1) {
1026 - error = -1;
 1009+ error = ENT_ERR_INVAE;
10271010 WDEBUG((WLOG_DEBUG, "a-e parse failed"));
10281011 goto error;
10291012 }
@@ -1052,7 +1035,7 @@
10531036 if (value)
10541037 wfree(value);
10551038 free(line);
1056 - return -1;
 1039+ return -error;
10571040 }
10581041
10591042 free(line);
Index: trunk/willow/src/willow/wnet_libevent.cc
@@ -42,9 +42,11 @@
4343
4444 static void fde_ev_callback(int, short, void *);
4545
46 -void sig_exit(int, short, void *);
 46+static void
 47+sig_exit(int, short, void *);
4748
48 -void sig_exit(int sig, short what, void *d)
 49+void
 50+sig_exit(int sig, short what, void *d)
4951 {
5052 exit(0);
5153 }
@@ -52,8 +54,6 @@
5355 void
5456 wnet_init_select(void)
5557 {
56 - int i;
57 -
5858 signal(SIGPIPE, SIG_IGN);
5959 event_init();
6060
Index: trunk/willow/src/willow/whttp.cc
@@ -91,9 +91,9 @@
9292 int cl_cfd; /* FD of cache file for writing, or 0 */
9393 struct cache_object *cl_co; /* Cache object */
9494 struct {
95 - int f_cached:1;
96 - int f_closed:1;
97 - int f_http11:1; /* Client understands HTTP/1.1 */
 95+ unsigned int f_cached:1;
 96+ unsigned int f_closed:1;
 97+ unsigned int f_http11:1; /* Client understands HTTP/1.1 */
9898 } cl_flags;
9999 size_t cl_dsize; /* Object size */
100100 enum encoding cl_enc;
@@ -101,7 +101,6 @@
102102 };
103103
104104 static struct http_client freelist;
105 -static struct http_client deadlist;
106105
107106 static void client_close(struct http_client *);
108107 static void proxy_start_backend(struct backend *, struct fde *, void *);
@@ -239,7 +238,6 @@
240239 client_read_done(http_entity *entity, void *data, int res)
241240 {
242241 struct http_client *client = (http_client *)data;
243 -struct cache_object *cobj;
244242 char *pragma, *cache_control, *ifmod;
245243 struct qvalue_head *acceptenc;
246244 struct qvalue *val;
@@ -464,8 +462,6 @@
465463 client_headers_done(http_entity *entity, void *data, int res)
466464 {
467465 struct http_client *client = (http_client *)data;
468 - char *cache_path;
469 - size_t plen;
470466
471467 WDEBUG((WLOG_DEBUG, "client_headers_done: called"));
472468
@@ -499,9 +495,9 @@
500496 */
501497 if ((lastmod = entity->he_h_last_modified) != NULL) {
502498 struct tm tim;
503 - char *res;
504 - res = strptime(lastmod, "%a, %d %b %Y %H:%M:%S", &tim);
505 - if (res) {
 499+ char *lm;
 500+ lm = strptime(lastmod, "%a, %d %b %Y %H:%M:%S", &tim);
 501+ if (lm) {
506502 WDEBUG((WLOG_DEBUG, "last-modified: %d", mktime(&tim)));
507503 client->cl_co->co_time = mktime(&tim);
508504 }
@@ -552,7 +548,7 @@
553549 header_add(&client->cl_entity.he_headers, wstrdup("Via"), wstrdup(via_hdr));
554550 header_add(&client->cl_entity.he_headers, wstrdup("X-Cache"), wstrdup(cache_hit_hdr));
555551 if (!client->cl_enc && !header_find(&client->cl_entity.he_headers, "Content-Length")) {
556 - snprintf(size, sizeof(size), "%d", client->cl_co->co_size);
 552+ snprintf(size, sizeof(size), "%lu", (unsigned long) client->cl_co->co_size);
557553 header_add(&client->cl_entity.he_headers, wstrdup("Content-Length"), wstrdup(size));
558554 }
559555
Index: trunk/willow/src/include/willow.h
@@ -16,6 +16,10 @@
1717
1818 #include <sstream>
1919
 20+#ifdef __INTEL_COMPILER
 21+# pragma warning (disable: 869 981 304 383 1418 1469 810)
 22+#endif
 23+
2024 template<typename To, typename From>
2125 To lexical_cast(From const &f)
2226 {
@@ -25,7 +29,7 @@
2630 strm >> t;
2731 return t;
2832 }
29 -
 33+
3034 typedef unsigned long long w_size_t;
3135
3236 #ifdef WDEBUG_ALLOC
Index: trunk/willow/src/include/wnet.h
@@ -62,9 +62,9 @@
6363 int fde_epflags;
6464 struct readbuf fde_readbuf;
6565 struct {
66 - int open:1;
67 - int held:1;
68 - int pend:1;
 66+ unsigned int open:1;
 67+ unsigned int held:1;
 68+ unsigned int pend:1;
6969 } fde_flags;
7070 struct event fde_ev;
7171 };
Index: trunk/willow/src/include/whttp_entity.h
@@ -35,6 +35,7 @@
3636 #define ENT_ERR_INVREQ -4 /* invalid request type */
3737 #define ENT_ERR_2MANY -5 /* too many headers */
3838 #define ENT_ERR_LOOP -6 /* forwarding loop detected */
 39+#define ENT_ERR_INVAE -7 /* invalid accept-encoding */
3940
4041 #define TE_CHUNKED 0x1 /* Chunked encoding */
4142
@@ -77,7 +78,7 @@
7879 E_DEFLATE,
7980 E_X_DEFLATE,
8081 E_GZIP,
81 - E_X_GZIP,
 82+ E_X_GZIP
8283 };
8384
8485 struct http_entity {
@@ -131,13 +132,13 @@
132133 } he_source;
133134
134135 struct {
135 - int cachable:1;
136 - int response:1;
137 - int error:1;
138 - int hdr_only:1;
139 - int eof:1;
140 - int drained:1;
141 - int chunked:1;
 136+ unsigned int cachable:1;
 137+ unsigned int response:1;
 138+ unsigned int error:1;
 139+ unsigned int hdr_only:1;
 140+ unsigned int eof:1;
 141+ unsigned int drained:1;
 142+ unsigned int chunked:1;
142143 } he_flags;
143144
144145 int he_te; /* transfer encoding */