Diff

Differences From Artifact [8a7d495917]:

To Artifact [c383e2203f]:


8
9
10
11
12
13
14

15
16
17
18
19
20
21
#include <strings.h>
#include <signal.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <fcntl.h>
#include <stdio.h>

#include <time.h>

/* Default values */
#define MAX_FAILURE_COUNT 30
#define PORT 8080
#define THREAD_COUNT 10
#define BIND_ADDR "::"







>







8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <strings.h>
#include <signal.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <fcntl.h>
#include <stdio.h>
#include <errno.h>
#include <time.h>

/* Default values */
#define MAX_FAILURE_COUNT 30
#define PORT 8080
#define THREAD_COUNT 10
#define BIND_ADDR "::"
462
463
464
465
466
467
468















469
470
471
472
473
474
475
476
477










478



















479
480
481
482
483
484
485
					(unsigned long long) fileinfo->len
				);
			}
			fprintf(fp, "\r\n");
			fflush(fp);

			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;
				}







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>









>
>
>
>
>
>
>
>
>
>
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
					(unsigned long long) fileinfo->len
				);
			}
			fprintf(fp, "\r\n");
			fflush(fp);

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

#ifdef FILED_NONBLOCK_HTTP
			int socket_flags;
			fd_set rfd, wfd;
			char sinkbuf[8192];
			ssize_t read_ret;

			FD_ZERO(&rfd);
			FD_ZERO(&wfd);
			FD_SET(fd, &rfd);
			FD_SET(fd, &wfd);

			socket_flags = fcntl(fd, F_GETFL);
			fcntl(fd, F_SETFL, socket_flags | O_NONBLOCK);
#endif

			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) {
#ifdef FILED_NONBLOCK_HTTP
					if (errno == EAGAIN) {
						sendfile_ret = 0;

						while (1) {
							select(fd + 1, &rfd, &wfd, NULL, NULL);
							if (FD_ISSET(fd, &rfd)) {
								read_ret = read(fd, sinkbuf, sizeof(sinkbuf));

								if (read_ret <= 0) {
									break;
								}
							}

							if (FD_ISSET(fd, &wfd)) {
								read_ret = 1;

								break;
							}
						}

						if (read_ret <= 0) {
							break;
						}
					} else {
						break;
					}
#else
					break;
#endif
				}

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