这是我的代码的一般结构:
if (contentLength > 0)
{
// Send POST data
size_t sizeRead = 0;
char buffer[1024];
while ((sizeRead < contentLength) && (!feof(stream)))
{
size_t diff = contentLength - sizeRead;
if (diff > 1024)
diff = 1024;
// Debuging
fprintf(stderr, "sizeRead: %zu\n", sizeRead);
fprintf(stderr, "contentLength: %ul\n", contentLength);
fprintf(stderr, "diff: %zu\n", diff);
size_t read = fread(buffer, 1, diff, stream);
sizeRead += read;
exit(1);
// Write to pipe
fwrite(buffer, 1, read, cgiPipePost);
exit(1);
}
}
但是,程序在到达 fread() 行时会挂起。如果我在该行之前添加一个 exit(),则该程序存在。如果我在之后添加它,程序会挂起,直到我发送 SIGINT 信号。
任何帮助将不胜感激,我已经坚持了很长一段时间了。
谢谢