我想在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