나는 posix 소켓을 기반으로 클라이언트 프로그램을 작성한다. 프로그램은 여러 스레드를 작성하고 서버를 잠글 것입니다. 그러나, GDB 시간 디버그 동안 프로그램 (오류) "(GDB) N프로그램 수신 신호 SIGPIPE, 파손 된 파이프.?
프로그램 신호 SIGPIPE 깨진 파이프. __kernel_vsyscall에 0xb7fdd424() ([ 0xb74c0b40 (LWP 4864) 스레드 스위칭] 통해 들어온 정보 제공 GDB) "
여기가 무엇을 어떻게 해야할지 코드
#include <arpa/inet.h>
#include <netdb.h>
#include <netinet/in.h>
#include <pthread.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <unistd.h>
int get_hostname_by_ip(char* h , char* ip)
{
struct hostent *he;
struct in_addr **addr_list;
int i;
if ((he = gethostbyname(h)) == NULL)
{
perror("gethostbyname");
return 1;
}
addr_list = (struct in_addr **) he->h_addr_list;
for(i = 0; addr_list[i] != NULL; i++)
{
strcpy(ip , inet_ntoa(*addr_list[i]));
return 0;
}
return 1;
}
void client(char* h, int s)
{
int fd;
struct sockaddr_in addr;
char ch[]="aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
fd = socket(AF_INET, SOCK_STREAM, 0);
addr.sin_family=AF_INET;
char* ip = new char[20];
get_hostname_by_ip(h, ip);
addr.sin_addr.s_addr=inet_addr(ip);
int port = 80;
addr.sin_port=htons(port);
if(connect(fd, (struct sockaddr*)&addr, sizeof(addr)) < 0)
{
perror("connect error");
return;
}
while(1)
{
if(send(fd, ch, sizeof(ch), 0) < 0)
{
perror("send");
}
}
//char buffer[1024];
//if(recv(fd, &buffer, sizeof(buffer), 0) < 0)
//{
// perror("recive");
//}
//printf("nReply from Server: %s\n", buffer);
close(fd);
}
struct info
{
char* h;
int c;
};
void* thread_entry_point(void* i)
{
info* in = (info*)i;
client(in->h, in->c);
}
int main(int argc, char** argv)
{
int s = atoi(argv[2]);
pthread_t t[s];
info in = {argv[1], s};
for(int i = 0; i < s; ++i)
{
pthread_create(&t[i], NULL, thread_entry_point, (void*)&in);
}
pthread_join(t[0], NULL);
return 0;
}
입니까?
이 방법이 유용할까요? if (signal (SIGPIPE, signalHandler) == EINVAL) 어떻게 -1과 EPIPE 오류가 발생합니까? – jongbanaag
@ Dreyfus15 : 신호 처리기를 세우는 방법에 대한 불확실성을 명확히하기 위해 이것에 대한 또 다른 질문을 게시하십시오. – alk