Diff

Differences From Artifact [af10919239]:

To Artifact [f27d202156]:


10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
..
98
99
100
101
102
103
104







105
106
107
108
109
110
111
112
113
114
115
116
117
118
119

120
121
122
123
124
125
126
...
292
293
294
295
296
297
298

299
300
301
302
303
304
305
...
341
342
343
344
345
346
347


348
349
350
351
352
353








354
355
356
357
358
359
360
...
462
463
464
465
466
467
468
469
470


471



472
473
474





475
476
477
478
479
480
481
482
483
484
#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 "::"

/* Arguments for worker threads */
struct filed_worker_thread_args {
	int fd;
};
................................................................................

		return(-1);
	}

	return(fd);
}








/* Initialize logging thread */
static int filed_logging_thread_init(void) {
	/* XXX:TODO: Unimplemented */
	return(0);
}

/* Log a message */
#define filed_log_msg_debug(x, ...) { fprintf(stderr, x, __VA_ARGS__); fprintf(stderr, "\n"); fflush(stderr); }
static void filed_log_msg(const char *buffer) {
	/* XXX:TODO: Unimplemented */
	fprintf(stderr, "%s\n", buffer);

	return;
}


/* Format time per RFC2616 */
static char *filed_format_time(char *buffer, size_t buffer_len, const time_t timeinfo) {
	struct tm timeinfo_tm, *timeinfo_tm_p;

	timeinfo_tm_p = gmtime_r(&timeinfo, &timeinfo_tm);
	if (timeinfo_tm_p == NULL) {
		return("unknown");
................................................................................
	);
}

/* Handle a single request from a client */
static void filed_handle_client(int fd) {
	struct filed_fileinfo *fileinfo, fileinfo_b;
	ssize_t sendfile_ret;

	off_t sendfile_offset;
	char *path, path_b[1010];
	char *date_current, date_current_b[64];
	FILE *fp;

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

		filed_log_msg("PROCESS_REPLY_COMPLETE FD=... STATUS=200");

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

		sendfile_offset = 0;


		sendfile_ret = sendfile(fd, fileinfo->fd, &sendfile_offset, fileinfo->len);
		if (sendfile_ret < 0 || ((size_t) sendfile_ret) != fileinfo->len) {
			filed_log_msg("SEND_COMPLETE STATUS=ERROR IFD=... OFD=... BYTES=... BYTES_SENT=...");
		} else {
			filed_log_msg("SEND_COMPLETE STATUS=OK IFD=... OFD=... BYTES=...");
		}









		close(fileinfo->fd);

		filed_log_msg("CLOSE_FILE FD=...");
	}

	filed_log_msg("CLOSE_CONNECTION FD=...");
................................................................................
	if (init_ret != 0) {
		perror("filed_init");

		return(3);
	}

	/* Create logging thread */
	/* XXX:TODO: Check for errors */
	filed_logging_thread_init();






	/* Create worker threads */
	/* XXX:TODO: Check for errors */
	filed_worker_threads_init(fd, thread_count);






	/* Wait for threads to exit */
	/* XXX:TODO: Monitor thread usage */
	while (1) {
		sleep(60);
	}

	/* Return in failure */
	return(2);
}







|







 







>
>
>
>
>
>
>






<








>







 







>







 







>
>
|
|
<
<
|
|
>
>
>
>
>
>
>
>







 







<
|
>
>

>
>
>

<
|
>
>
>
>
>










10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
..
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117

118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
...
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
...
349
350
351
352
353
354
355
356
357
358
359


360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
...
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
#include <string.h>
#include <fcntl.h>
#include <stdio.h>
#include <time.h>

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

/* Arguments for worker threads */
struct filed_worker_thread_args {
	int fd;
};
................................................................................

		return(-1);
	}

	return(fd);
}

/* Log a message */
#define FILED_DONT_LOG
#ifdef FILED_DONT_LOG
#  define filed_logging_thread_init() 0
#  define filed_log_msg_debug(x, ...) /**/
#  define filed_log_msg(x) /**/
#else
/* Initialize logging thread */
static int filed_logging_thread_init(void) {
	/* XXX:TODO: Unimplemented */
	return(0);
}


#define filed_log_msg_debug(x, ...) { fprintf(stderr, x, __VA_ARGS__); fprintf(stderr, "\n"); fflush(stderr); }
static void filed_log_msg(const char *buffer) {
	/* XXX:TODO: Unimplemented */
	fprintf(stderr, "%s\n", buffer);

	return;
}

#endif
/* Format time per RFC2616 */
static char *filed_format_time(char *buffer, size_t buffer_len, const time_t timeinfo) {
	struct tm timeinfo_tm, *timeinfo_tm_p;

	timeinfo_tm_p = gmtime_r(&timeinfo, &timeinfo_tm);
	if (timeinfo_tm_p == NULL) {
		return("unknown");
................................................................................
	);
}

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

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

		filed_log_msg("PROCESS_REPLY_COMPLETE FD=... STATUS=200");

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

		sendfile_offset = 0;
		sendfile_len = fileinfo->len;
		while (1) {
			sendfile_ret = sendfile(fd, fileinfo->fd, &sendfile_offset, sendfile_len);
			if (sendfile_ret <= 0) {


				break;
			}

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

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

		close(fileinfo->fd);

		filed_log_msg("CLOSE_FILE FD=...");
	}

	filed_log_msg("CLOSE_CONNECTION FD=...");
................................................................................
	if (init_ret != 0) {
		perror("filed_init");

		return(3);
	}

	/* Create logging thread */

	init_ret = filed_logging_thread_init();
	if (init_ret != 0) {
		perror("filed_logging_thread_init");

		return(4);
	}

	/* Create worker threads */

	init_ret = filed_worker_threads_init(fd, thread_count);
	if (init_ret != 0) {
		perror("filed_worker_threads_init");

		return(4);
	}

	/* Wait for threads to exit */
	/* XXX:TODO: Monitor thread usage */
	while (1) {
		sleep(60);
	}

	/* Return in failure */
	return(2);
}