Project

General

Profile

Feature #953 ยป connections.patch

X-Sendfile and traffic limit patch - Terminar, 2006-12-30 21:46

View differences:

connections.c_ 2006-12-30 23:35:27.000000000 +0100
1334 1334
			case HANDLER_FINISHED:
1335 1335
				/* oops, we don't want this here */
1336 1336
				break;
1337
			case HANDLER_COMEBACK:
1338
				/* jump back, this should be proceeded by mod_staticfile */
1339
				if (con->mode == DIRECT)
1340
				{
1341
				    connection_set_state(srv,con,CON_STATE_HANDLE_REQUEST_HEADER);
1342
				}
1343
				break;
1337 1344
			case HANDLER_WAIT_FOR_EVENT:
1338 1345
				return HANDLER_WAIT_FOR_EVENT;
1339 1346
			default:
......
1343 1350
				break;
1344 1351
			}
1345 1352

  
1346
			chunkqueue_remove_finished_chunks(con->recv);
1347

  
1348
			if (con->state == CON_STATE_ERROR) break;
1349

  
1350
			if (con->recv->is_closed &&
1351
			    con->recv->bytes_in == con->recv->bytes_out) {
1352
				/* everything we read is sent */
1353
				connection_set_state(srv, con, CON_STATE_HANDLE_RESPONSE_HEADER);
1353
			if ( ! (r == HANDLER_COMEBACK && con->mode == DIRECT) )
1354
			{
1355
			    chunkqueue_remove_finished_chunks(con->recv);
1356

  
1357
			    if (con->state == CON_STATE_ERROR) break;
1358

  
1359
			    if (con->recv->is_closed &&
1360
				con->recv->bytes_in == con->recv->bytes_out) {
1361
				    /* everything we read is sent */
1362
				    connection_set_state(srv, con, CON_STATE_HANDLE_RESPONSE_HEADER);
1363
			    }
1354 1364
			}
1355 1365

  
1356 1366
			break;
......
1391 1401

  
1392 1402
			http_stream_encoder(srv, con, con->send, con->send_raw);
1393 1403

  
1394
			switch(network_write_chunkqueue(srv, con, con->send_raw)) {
1395
			case NETWORK_STATUS_SUCCESS:
1396
				/* we send everything from the chunkqueue and the chunkqueue-sender signaled it is finished */
1397
				if (con->send_raw->is_closed) {
1398
					if (con->http_status == 100) {
1399
						/* send out the 100 Continue header and handle the request as normal afterwards */
1400
						con->http_status = 0;
1401

  
1402
						connection_set_state(srv, con, CON_STATE_HANDLE_REQUEST_HEADER);
1403
					} else {
1404
						connection_set_state(srv, con, CON_STATE_RESPONSE_END);
1405
					}
1406
				} else {
1407
					/* still have data to send in send_raw queue */
1408
					fdevent_event_add(srv->ev, con->sock, FDEVENT_OUT);
1409
					return HANDLER_WAIT_FOR_EVENT;
1410
				}
1411
				break;
1412
			case NETWORK_STATUS_FATAL_ERROR: /* error on our side */
1413
				TRACE("%s", "(network-subsys sent us a fatal-error)");
1414
				connection_set_state(srv, con, CON_STATE_ERROR);
1415
				break;
1416
			case NETWORK_STATUS_CONNECTION_CLOSE: /* remote close */
1417
				connection_set_state(srv, con, CON_STATE_ERROR);
1418
				break;
1419
			case NETWORK_STATUS_WAIT_FOR_AIO_EVENT:
1420
				return HANDLER_WAIT_FOR_EVENT;
1421
			case NETWORK_STATUS_WAIT_FOR_EVENT:
1422
				fdevent_event_add(srv->ev, con->sock, FDEVENT_OUT);
1423

  
1424
				return HANDLER_WAIT_FOR_EVENT;
1425
			case NETWORK_STATUS_INTERRUPTED:
1426
			case NETWORK_STATUS_UNSET:
1427
				break;
1404
			/* proceed traffic limit here! this is set in network.c and reset in server.c */
1405
			if (con->traffic_limit_reached == 0)
1406
			{
1407
			    switch(network_write_chunkqueue(srv, con, con->send_raw)) {
1408
			    case NETWORK_STATUS_SUCCESS:
1409
				    /* we send everything from the chunkqueue and the chunkqueue-sender signaled it is finished */
1410
				    if (con->send_raw->is_closed) {
1411
					    if (con->http_status == 100) {
1412
						    /* send out the 100 Continue header and handle the request as normal afterwards */
1413
						    con->http_status = 0;
1414

  
1415
						    connection_set_state(srv, con, CON_STATE_HANDLE_REQUEST_HEADER);
1416
					    } else {
1417
						    connection_set_state(srv, con, CON_STATE_RESPONSE_END);
1418
					    }
1419
				    } else {
1420
					    /* still have data to send in send_raw queue */
1421
					    fdevent_event_add(srv->ev, con->sock, FDEVENT_OUT);
1422
					    return HANDLER_WAIT_FOR_EVENT;
1423
				    }
1424
				    break;
1425
			    case NETWORK_STATUS_FATAL_ERROR: /* error on our side */
1426
				    TRACE("%s", "(network-subsys sent us a fatal-error)");
1427
				    connection_set_state(srv, con, CON_STATE_ERROR);
1428
				    break;
1429
			    case NETWORK_STATUS_CONNECTION_CLOSE: /* remote close */
1430
				    connection_set_state(srv, con, CON_STATE_ERROR);
1431
				    break;
1432
			    case NETWORK_STATUS_WAIT_FOR_AIO_EVENT:
1433
				    return HANDLER_WAIT_FOR_EVENT;
1434
			    case NETWORK_STATUS_WAIT_FOR_EVENT:
1435
				    fdevent_event_add(srv->ev, con->sock, FDEVENT_OUT);
1436

  
1437
				    return HANDLER_WAIT_FOR_EVENT;
1438
			    case NETWORK_STATUS_INTERRUPTED:
1439
			    case NETWORK_STATUS_UNSET:
1440
				    break;
1441
			    }
1442
			
1443
			} else
1444
			{
1445
			    return HANDLER_WAIT_FOR_EVENT;
1428 1446
			}
1429 1447

  
1430 1448

  
    (1-1/1)