recv함수 호출 에러 후 errno가 0인데.

nyulnim의 이미지


select 후에 recv를 호출했습니다.
recv함수 return 값이 -1 인데, errno가 0으로 세팅되어 있습니다.
(보통 recv 리턴값이 양수일 경우 읽은 byte수, 0 일 경우 socket의 단절,
-1일 경우 에러라고 알고 있습니다)
r

errno가 0이면 에러가 아닌 것인데,
recv 함수는 왜 -1을 리턴했을까요?

이런 경우 있으셨던 분 조언을 구합니다.
참고로 멀티쓰레드 프로그램인데, errno가 전역변수라서 -D_REENTRANT 옵션은 주고 테스트했습니다.

bushi의 이미지

errno 는 항상 thread-safe 입니다.

       errno is defined by the ISO C standard to be  a  modifiable  lvalue  of
       type  int,  and  must not be explicitly declared; errno may be a macro.
       errno is thread-local; setting it in one thread  does  not  affect  its
       value in any other thread.

잘 못 만드셨으리라 짐작됩니다.

OTL