| 1239 | } |
| 1240 | |
| 1241 | static void |
| 1242 | handle_read(int cnum, struct timeval *nowP) |
| 1243 | { |
| 1244 | char buf[30000]; /* must be larger than throttle / 2 */ |
| 1245 | int bytes_to_read, bytes_read, bytes_handled; |
| 1246 | float elapsed; |
| 1247 | ClientData client_data; |
| 1248 | long checksum; |
| 1249 | |
| 1250 | tmr_reset(nowP, connections[cnum].idle_timer); |
| 1251 | |
| 1252 | if (do_throttle) |
| 1253 | bytes_to_read = throttle / 2.0; |
| 1254 | else |
| 1255 | bytes_to_read = sizeof(buf); |
| 1256 | if (!connections[cnum].did_response) { |
| 1257 | connections[cnum].did_response = 1; |
| 1258 | connections[cnum].response_at = *nowP; |
| 1259 | if (connections[cnum].did_connect) { |
| 1260 | if (connections[cnum].keep_alive == keep_alive) { |
| 1261 | num_ka_conns++; |
| 1262 | if (num_ka_conns > max_parallel) { |
| 1263 | max_parallel = num_ka_conns; |
| 1264 | } |
| 1265 | } |
| 1266 | } |
| 1267 | if (connections[cnum].keep_alive == 0) { |
| 1268 | num_ka_conns--; |
| 1269 | } |
| 1270 | } |
| 1271 | if (urls[connections[cnum].url_num].protocol == PROTO_HTTPS) |
| 1272 | bytes_read = SSL_read(connections[cnum].ssl, buf, bytes_to_read - 1); |
| 1273 | else |
| 1274 | bytes_read = read(connections[cnum].conn_fd, buf, bytes_to_read - 1); |
| 1275 | if (bytes_read <= 0) { |
| 1276 | connections[cnum].reusable = 0; |
| 1277 | close_connection(cnum); |
| 1278 | return; |
| 1279 | } |
| 1280 | |
| 1281 | buf[bytes_read] = 0; |
| 1282 | for (bytes_handled = 0; bytes_handled < bytes_read;) { |
| 1283 | switch (connections[cnum].conn_state) { |
| 1284 | case CNST_HEADERS: |
| 1285 | /* State machine to read until we reach the file part. Looks for |
| 1286 | ** Content-Length header too. |
| 1287 | */ |
| 1288 | for (; bytes_handled < bytes_read && connections[cnum].conn_state == CNST_HEADERS; ++bytes_handled) { |
| 1289 | switch (connections[cnum].header_state) { |
| 1290 | case HDST_LINE1_PROTOCOL: |
| 1291 | switch (buf[bytes_handled]) { |
| 1292 | case ' ': |
| 1293 | case '\t': |
| 1294 | connections[cnum].header_state = HDST_LINE1_WS; |
| 1295 | break; |
| 1296 | case '\n': |
| 1297 | connections[cnum].header_state = HDST_LF; |
| 1298 | break; |
no test coverage detected