Version française
Home     About     Download     Resources     Contact us    
Browse thread
Unix module API: nonblocking connect's errors retrieving
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Jerome Vouillon <Jerome.Vouillon@p...>
Subject: Re: [Caml-list] Unix module API: nonblocking connect's errors retrieving
Hello,

On Thu, Sep 22, 2005 at 05:51:25PM +0400, Vsevolod Fedorov wrote:
> I have the following problem when using Unix module:
>
> I issuing 'connect' for nonblocked-mode socket.
> This can raise EINPROGRESS error meaning connect is not yet
> complete.  Then (as I taught by manuals) I use 'select' method and
> then 'getsockopt_int sock SO_ERROR' to retreive connect results.
> The problem is: 'getsockopt_int' returns 'int' while I need
> Unix.error type.  I can't map int to error in good way.
>
> Of couse, I can use some workarounds (and I had to use one), but
> they all are not look good.

I'm using the following piece of code as a work-around:

    begin try
      (* This succeeds only if the socket is connected *)
      ignore (Unix.getpeername fd)
    with Unix.Unix_error (Unix.ENOTCONN, _, _) ->
      (* This returns the right error message *)
      ignore (Unix.read fd " " 0 1))
    end

-- Jerome