3
소켓과 통신하는 두 개의 노드가 있습니다. 각 노드에는 읽기 스레드와 쓰기 스레드가있어 서로 통신합니다. 다음은 읽기 스레드의 코드입니다. 통신은 두 노드 사이에서 해당 코드로 올바르게 작동합니다. 하지만이 스레드에서 선택 함수를 추가하려면 및 그 날 문제가 (선택에 대한 코드를 주석주고있다. 그냥 기능을 추가하려면 주석 처리하지 않습니다.) 문제는 한 노드가 메시지를 수신하지 않고 시간 제한 만 수행한다는 것입니다. 다른 노드는 다른 노드에서 메시지를 가져 오지만 결코 시간 초과되지는 않습니다. 그 문제는 select (메모를 유지/* * /)하지 않고 (두 노드가 메시지를 보내고받습니다) 없습니다.선택 소켓 프로그래밍
아무도 문제를 지적 할 수 있습니까? 감사.
void *Read_Thread(void *arg_passed)
{
int numbytes;
unsigned char *buf;
buf = (unsigned char *)malloc(MAXDATASIZE);
/*
fd_set master;
int fdmax;
FD_ZERO(&master);
*/
struct RWThread_args_template *my_args = (struct RWThread_args_template *)arg_passed;
/*
FD_SET(my_args->new_fd, &master);
struct timeval tv;
tv.tv_sec = 2;
tv.tv_usec = 0;
int s_rv = 0;
fdmax = my_args->new_fd;
*/
while(1)
{
/*
s_rv = -1;
if((s_rv = select(fdmax+1, &master, NULL, NULL, &tv)) == -1)
{
perror("select");
exit(1);
}
if(s_rv == 0)
{
printf("Read: Timed out\n");
continue;
}
else
{
printf("Read: Received msg\n");
}
*/
if((numbytes = recv(my_args->new_fd, buf, MAXDATASIZE-1, 0)) == -1)
{
perror("recv");
exit(1);
}
buf[numbytes] = '\0';
printf("Read: received '%s'\n", buf);
}
pthread_exit(NULL);
}
예. 문제를 해결했습니다. 감사! – Romonov