InterviewSolution
| 1. |
How Can I Set The Timeout For The Connect() System Call? |
Answer»
There are three possibilities:
If the connection succeeds: The socket will select() as writable (and will also select as readable if data arrives) If the connection fails: 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. There are three possibilities: If the connection succeeds: The socket will select() as writable (and will also select as readable if data arrives) If the connection fails: 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. |
|