Linux CGI环境,读取最大大小是否固定?

Linux CGI环境,读取最大大小是否固定?,linux,apache,cgi,Linux,Apache,Cgi,在Apache2提供的CGI环境中,我使用用C编写的CGI可执行文件 cgi.c: #define MY_SIZE 102400 #define MY_SIZE_OUT (2 + (MY_SIZE * 2)) int main() { char buf[SIZE + 2]; int n; if (write(1, "Content-type: text/htm

在Apache2提供的CGI环境中,我使用用C编写的CGI可执行文件

cgi.c:

#define         MY_SIZE                 102400
#define         MY_SIZE_OUT             (2 + (MY_SIZE * 2))

    int main()
{
char          buf[SIZE + 2];
int           n;

if (write(1, "Content-type: text/html\n\n", 25) == -1)
        {
          puts("An internal error occured, please report the bug #005");
          goto EXIT;
        }
      if ((n = read(0, buf, MY_SIZE)) == -1)
        {
          puts("An internal error occured, please report the bug #004");
          goto EXIT;
        }

      buf[n] = '\n';
      buf[n + 1] = 0;

      printf("Size of input = %i |--| |%s| max size = %i\n", n, buf, MY_SIZE);

     EXIT:
      return 1;
}
我的POST请求由Ajax代码发送:

ajaxRequest.onreadystatechange = function(){
            if(ajaxRequest.readyState == 4){
                var text;
                var exp;
            text = ajaxRequest.responseText;

            exp = new RegExp("([^ ]+)", "g");
            text = text.replace(exp, "<a class='wd' onClick='man_wd(this);'>$1</a>");
            document.getElementById("out").innerHTML = text;
            }
 }

  document.getElementById("out").innerHTML = "Processing...";
  ajaxRequest.open("POST", "cgi-bin/a.cgi", true);
  ajaxRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
 ajaxRequest.setRequestHeader("Content-length", 5 + document.forms['f_main'].ta_in.value.length);
 ajaxRequest.setRequestHeader("Connection", "close");

  ajaxRequest.send(getPrefix() + " " + document.forms['f_main'].ta_in.value);
我的问题是,当我发送一个超过N个字符的请求时,即使我的大小值为102400,我的CGI EXECATABLE读取的最大字符数也为1060个

我访问了accross php.ini,但帖子大小限制为8Mb

有人有想法吗?

从阅读手册:

read尝试从文件描述符fd中最多读取个字节 从buf开始的缓冲区

因此,可能需要多次调用read

在第1卷中,Stevens建议阅读以下内容:

ssize_t readn (int fd, void *vptr, size_t n)
{
    size_t ret;
    size_t nleft;
    ssize_t nread;
    char *ptr;

    /* Initialize local variables */
    ptr = (char*)vptr;
    nleft = n;
    while (nleft > 0)
    {
        if ((nread = read (fd, ptr, nleft)) < 0)
        {
            if (errno == EINTR)
            {
                /* Read interrupted by system call, call read() again */
                nread = 0;
            }
            else
            {
                /* Other type of errors, return */
                return -1;
            }
        }
        else if (nread == 0)
        {
            /* No more data to read, exit */
            break;
        }

        /* Update counters and call read again */
        nleft -= nread;
        ptr += nread;
    }
    ret = n - nleft;

    return ret;
}

调用读取多次,仅在读取所需数量的数据时停止,或者输入真正结束。

读取尝试的哪部分不清楚?在读取整个输入之前,可以中断读取。男2:很明显我很好,但我不能投票,因为我没有足够的声誉。下次我会做的。非常感谢你的帮助。