我想在c中制作一个微小的http服务器,但我得到了与httperf的CONNRESET错误,为什么?C HTTP服务器/连接重置
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <signal.h>
#include <unistd.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <fcntl.h>
#define SOCKERROR -1
#define SD_RECEIVE 0
#define SD_SEND 1
#define SD_BOTH 2
int server;
int client;
...
int main(int argc, char *argv[])
{
int status;
int accepted;
struct addrinfo hint;
struct addrinfo *info;
struct sockaddr addr;
socklen_t addrsize;
int yes = 1;
...
// client
addrsize = sizeof addr;
while (1)
{
memset(&accepted, 0, sizeof accepted);
memset(&addr, 0, sizeof addr);
accepted = accept(server, &addr, &addrsize);
if (accepted == SOCKERROR) {
warn("Accept", errno);
} else {
shutdown(accepted, SD_SEND);
close(accepted);
}
}
// shutdown
...
return EXIT_SUCCESS;
}
的httperf将发送数据,您的应用程序忽略它......我想象perf工具正在超时/缓冲区正在变满,并且连接正在关闭。如果忽略发送到套接字的IO,最终一方会放弃,操作系统不会永久地缓冲它。 – forsvarir 2011-05-19 09:11:49