Diff

Differences From Artifact [8a7d495917]:

To Artifact [c383e2203f]:


     8      8   #include <strings.h>
     9      9   #include <signal.h>
    10     10   #include <stdlib.h>
    11     11   #include <unistd.h>
    12     12   #include <string.h>
    13     13   #include <fcntl.h>
    14     14   #include <stdio.h>
           15  +#include <errno.h>
    15     16   #include <time.h>
    16     17   
    17     18   /* Default values */
    18     19   #define MAX_FAILURE_COUNT 30
    19     20   #define PORT 8080
    20     21   #define THREAD_COUNT 10
    21     22   #define BIND_ADDR "::"
................................................................................
   462    463   					(unsigned long long) fileinfo->len
   463    464   				);
   464    465   			}
   465    466   			fprintf(fp, "\r\n");
   466    467   			fflush(fp);
   467    468   
   468    469   			filed_log_msg("PROCESS_REPLY_COMPLETE FD=... STATUS=20X");
          470  +
          471  +#ifdef FILED_NONBLOCK_HTTP
          472  +			int socket_flags;
          473  +			fd_set rfd, wfd;
          474  +			char sinkbuf[8192];
          475  +			ssize_t read_ret;
          476  +
          477  +			FD_ZERO(&rfd);
          478  +			FD_ZERO(&wfd);
          479  +			FD_SET(fd, &rfd);
          480  +			FD_SET(fd, &wfd);
          481  +
          482  +			socket_flags = fcntl(fd, F_GETFL);
          483  +			fcntl(fd, F_SETFL, socket_flags | O_NONBLOCK);
          484  +#endif
   469    485   
   470    486   			filed_log_msg("SEND_START IFD=... OFD=... BYTES=...");
   471    487   
   472    488   			sendfile_offset = request->headers.range.offset;
   473    489   			sendfile_len = request->headers.range.length;
   474    490   			sendfile_sent = 0;
   475    491   			while (1) {
   476    492   				sendfile_ret = sendfile(fd, fileinfo->fd, &sendfile_offset, sendfile_len);
   477    493   				if (sendfile_ret <= 0) {
          494  +#ifdef FILED_NONBLOCK_HTTP
          495  +					if (errno == EAGAIN) {
          496  +						sendfile_ret = 0;
          497  +
          498  +						while (1) {
          499  +							select(fd + 1, &rfd, &wfd, NULL, NULL);
          500  +							if (FD_ISSET(fd, &rfd)) {
          501  +								read_ret = read(fd, sinkbuf, sizeof(sinkbuf));
          502  +
          503  +								if (read_ret <= 0) {
          504  +									break;
          505  +								}
          506  +							}
          507  +
          508  +							if (FD_ISSET(fd, &wfd)) {
          509  +								read_ret = 1;
          510  +
          511  +								break;
          512  +							}
          513  +						}
          514  +
          515  +						if (read_ret <= 0) {
          516  +							break;
          517  +						}
          518  +					} else {
          519  +						break;
          520  +					}
          521  +#else
   478    522   					break;
          523  +#endif
   479    524   				}
   480    525   
   481    526   				sendfile_len -= sendfile_ret;
   482    527   				sendfile_sent += sendfile_ret;
   483    528   				if (sendfile_len == 0) {
   484    529   					break;
   485    530   				}