Overview
Comment: | Added support for a "no logging" compile-time option (for now) and updated to support sendfile restarts |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA1: |
c7e703e4e5c6dcb188f7b97b9b722030 |
User & Date: | rkeene on 2014-02-05 09:01:12 |
Other Links: | manifest | tags |
Context
2014-02-05
| ||
09:04 | Additional improvements check-in: a00671c11b user: rkeene tags: trunk | |
09:01 | Added support for a "no logging" compile-time option (for now) and updated to support sendfile restarts check-in: c7e703e4e5 user: rkeene tags: trunk | |
08:49 | Updated to cache file descriptors check-in: 565d4b51c2 user: rkeene tags: trunk | |
Changes
Modified filed.c from [af10919239] to [f27d202156].
︙ | ︙ | |||
10 11 12 13 14 15 16 | #include <string.h> #include <fcntl.h> #include <stdio.h> #include <time.h> /* Default values */ #define MAX_FAILURE_COUNT 30 | | | 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | #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; }; |
︙ | ︙ | |||
98 99 100 101 102 103 104 105 106 107 108 109 110 | return(-1); } return(fd); } /* Initialize logging thread */ static int filed_logging_thread_init(void) { /* XXX:TODO: Unimplemented */ return(0); } | > > > > > > > < > | 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 | 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"); |
︙ | ︙ | |||
292 293 294 295 296 297 298 299 300 301 302 303 304 305 | ); } /* 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)); | > | 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 | ); } /* 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)); |
︙ | ︙ | |||
341 342 343 344 345 346 347 | fflush(fp); filed_log_msg("PROCESS_REPLY_COMPLETE FD=... STATUS=200"); filed_log_msg("SEND_START IFD=... OFD=... BYTES=..."); sendfile_offset = 0; | > > | | < | > | > > > | > > > | 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 | 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=..."); |
︙ | ︙ | |||
462 463 464 465 466 467 468 | if (init_ret != 0) { perror("filed_init"); return(3); } /* Create logging thread */ | < | > > > > > < | > > > > > | 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 | 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); } |