How can I put a timeout on connect()? 이란 것을 보고 의문 사항이 있어서 질문을 드려 봅니다.
pro-gramming TCP/IP applications in unix with the sockets interface에 대한 질문과 응답에 대해서 보다가 이런 질문이 있었습니다.
6.2. How can I put a timeout on connect()?
Andrew Gierth (andrew@erlenstar.demon.co.uk) has outlined the
following procedure for using select() with connect(), which will
allow you to put a timeout on the connect() call:
First, create the socket and put it into non-blocking mode, then call
connect(). There are three possibilities:
o connect succeeds: the connection has been successfully made (this
usually only happens when connecting to the same machine)
o connect fails: obvious
o connect returns -1/EINPROGRESS. The connection attempt has begun,
but not yet completed.
If the connection succeeds:
o the socket will select() as writable (and will also select as
readable if data arrives)
If the connection fails:
o the socket will select as readable *and* writable, but either a
read or write will return the error code from the connection
attempt. Also, you can use getsockopt(SO_ERROR) to get the error
status - but be careful; some systems return the error code in the
result parameter of getsockopt(), but others (incorrectly) cause
the getsockopt call itself to fail with the stored value as the
error.
여기서 마지막 If the connection fails: 이부분에 마지막 문장인
but others (incorrectly) cause the getsockopt call itself to fail with the stored value as the
error.
자기 자신을 호출할때가 있다고 하는대 자기 자신의 호출을 막는 방법이 있나요? 혹은, 이런 경우 생기는 경우가 따로 있나요?
며칠전에이와 비슷한 문제로 질문을 올렸는데 아직 해결을 하지못해 질문 드립니다.
조금 다르게 번역하셔야 합니다. "근데 조심하세요.
조금 다르게 번역하셔야 합니다.
"근데 조심하세요. 어떤 시스템에서는 getsockopt() 인자로 오류 코드를 받는 반면 다른 시스템에서는 저장된 값(역자주: 지금 경우 connect()의 결과값)을 오류값으로 해서 getsockopt 호출 자체가 실패를 반환하게 합니다 (잘못된 방식임)."
$PWD `date`
댓글 달기