Diff

Differences From Artifact [5e37a15236]:

To Artifact [b68d97d7c3]:


53
54
55
56
57
58
59

60
61
62
63
64
65
66
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67







+







			off_t offset;   /*** Range start ***/
			ssize_t length; /*** Range length ***/
		} range;
	} headers;
};

/* Global variables */
/** Open File cache **/
struct filed_fileinfo *filed_fileinfo_fdcache;
unsigned int filed_fileinfo_fdcache_size = CACHE_SIZE;

/* Initialize process */
static int filed_init(void) {
	unsigned int idx;
	int mutex_init_ret;
376
377
378
379
380
381
382
383

384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
377
378
379
380
381
382
383

384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403


404
405
406
407
408
409
410







-
+



















-
-







	);
}

/* Handle a single request from a client */
static void filed_handle_client(int fd, struct filed_http_request *request) {
	struct filed_fileinfo *fileinfo;
	ssize_t sendfile_ret;
	size_t sendfile_len;
	size_t sendfile_len, sendfile_sent;
	off_t sendfile_offset;
	char *path;
	char *date_current, date_current_b[64];
	int http_code;
	FILE *fp;

	/* Determine current time */
	date_current = filed_format_time(date_current_b, sizeof(date_current_b), time(NULL));

	/* Open socket as ANSI I/O for ease of use */
	fp = fdopen(fd, "w+b");
	if (fp == NULL) {
		close(fd);

		return;
	}

	request = filed_get_http_request(fp, request);

	fflush(fp);

	path = request->path;

	filed_log_msg("PROCESS_REPLY_START FD=... PATH=... RANGE_START=... RANGE_LENGTH=...");

	if (path == NULL) {
		filed_error_page(fp, date_current, 500);

468
469
470
471
472
473
474

475
476
477
478
479
480
481

482
483
484
485
486
487
488
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489







+







+








			filed_log_msg("PROCESS_REPLY_COMPLETE FD=... STATUS=20X");

			filed_log_msg("SEND_START IFD=... OFD=... BYTES=...");

			sendfile_offset = request->headers.range.offset;
			sendfile_len = request->headers.range.length;
			sendfile_sent = 0;
			while (1) {
				sendfile_ret = sendfile(fd, fileinfo->fd, &sendfile_offset, sendfile_len);
				if (sendfile_ret <= 0) {
					break;
				}

				sendfile_len -= sendfile_ret;
				sendfile_sent += sendfile_ret;
				if (sendfile_len == 0) {
					break;
				}
			}

			filed_log_msg("SEND_COMPLETE STATUS=... IFD=... OFD=... BYTES=... BYTES_SENT=...");
		}