Could it just be that the failure is because you are getting EAGAIN because the connection hasn't completed yet? I have a vague recollection of some systems doing this, which really is the `right' thing to do because the connection takes a few exchanges and so can be slow. Did you try this code on a Sun?