2013-10-18 71 views
1

我試圖用我編譯的fcgi應用程序使用fastcgi庫(http://www.fastcgi.com/)上傳文件。用FastCGI和Lighttpd上傳大文件

當我上傳一個小文件(< 500KB)時,上傳成功。但是,當我上傳大於500KB的文件時,我收到503錯誤(服務不可用)。我可以確認整個文件已經以1MB塊的形式上傳到lighttpd的臨時目錄。

對於我的測試,最大請求大小設置爲30MB,我的測試文件大小爲14MB。

立即文件塊已經被上傳後,在日誌結果如下:

(mod_fastcgi.c.3058) got proc: pid: 2171 socket: unix:/tmp/fcgi.sock-0 load: 1 
(network_writev.c.303) write failed: Bad address 7 
(mod_fastcgi.c.3098) write failed: Bad address 14 
(mod_fastcgi.c.1490) released proc: pid: 2171 socket: unix:/tmp/fcgi.sock-0 load: 0 

而且組裝上傳文件爲500KB〜。

請問任何人請爲我說明這一點?

我FCGI應用程序如下:

#include "fcgi_stdio.h" 
#include <stdlib.h> 
#include <fcntl.h> 
#include <sys/types.h> 
#include <sys/stat.h> 


void main(void) 
{ 

    int count = 0; 
    while(FCGI_Accept() >= 0) { 
     char *contentLength = getenv("CONTENT_LENGTH"); 
     int len; 

     if (contentLength != NULL) { 
      len = strtol(contentLength, NULL, 10); 
     } 
     else { 
      len = 0; 
     } 
     printf("Content-type: text/html\r\n" 
       "\r\n" 
       "<title>FastCGI Hello!</title>" 
       "<h1>FastCGI Hello!</h1>" 
       "Request number %d running on host <i>%s</i>\n", 
       ++count, getenv("SERVER_NAME")); 

     printf("<br />CONTENT_LENGTH = %d <br />\r\n", len); 
     printf("<form enctype='multipart/form-data' method='post' action='?'><input type='text' name='text1' /><input type='file' name='file1'/><input type='submit' /></form>"); 
     printf("<hr />"); 

     fflush(stdout); 

     FCGI_FILE * fileOut = FCGI_fopen("/tmp/fcgi.out", "w"); 
     if (fileOut) { 
      int done = 0; 
      while(done < len) { 
       char buffer[1024]; 
       int i; 
       int packetRead; 

       packetRead = FCGI_fread(buffer, 1, sizeof(buffer), stdin); 
       if (packetRead < 0) { 
        break; 
       } 
       if (packetRead > 0) { 
        FCGI_fwrite(buffer, 1, packetRead, fileOut); 
        done += packetRead; 
       } 


      } 
      FCGI_fclose(fileOut); 
     } 

     FCGI_Finish(); 
    }  
} 

在此先感謝。

回答

0

當您提供的地址位置無效時,寫入錯誤錯誤地址會上升。

我不知道FCGI_fread和FCGI_fwrite,但他們的POSIX當量

FCGI_fread(buffer, 1, sizeof(buffer), stdin); 
FCGI_fwrite(buffer, 1, packetRead, fileOut); 

應該

FCGI_fread(&buffer, 1, sizeof(buffer), stdin); 
FCGI_fwrite(&buffer, 1, packetRead, fileOut); 

可能是沒有什麼幫助。

其次:

size_t  FCGI_fread(void *ptr, size_t size, size_t nmemb, FCGI_FILE *fp); 
size_t  FCGI_fwrite(void *ptr, size_t size, size_t nmemb, FCGI_FILE *fp); 

可能會更好:

FCGI_fread(&buffer, sizeof(char), sizeof(buffer), stdin); 
FCGI_fwrite(&buffer, sizeof(char), packetRead, fileOut); 
+0

由於緩衝區的類型爲數組(的字符),我相信,通過無符號是正確的。奇怪的是,寫入確實發生在指定的輸出文件上,但僅在寫入錯誤被拋出之前的大約500KB之前發生。 – wei