* Unix module API: nonblocking connect's errors retrieving
@ 2005-09-22 13:51 Vsevolod Fedorov
2005-09-22 14:14 ` [Caml-list] " Markus Mottl
2005-09-27 16:02 ` Jerome Vouillon
0 siblings, 2 replies; 3+ messages in thread
From: Vsevolod Fedorov @ 2005-09-22 13:51 UTC (permalink / raw)
To: caml-list
[-- Attachment #1: Type: text/plain, Size: 662 bytes --]
Hello, Camlers!
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.
May be is it the time to extend Unix module API?
For example, add function like 'getsockopt_error' or 'int_to_error'?
Seva
[-- Attachment #2: Type: text/html, Size: 1604 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [Caml-list] Unix module API: nonblocking connect's errors retrieving
2005-09-22 13:51 Unix module API: nonblocking connect's errors retrieving Vsevolod Fedorov
@ 2005-09-22 14:14 ` Markus Mottl
2005-09-27 16:02 ` Jerome Vouillon
1 sibling, 0 replies; 3+ messages in thread
From: Markus Mottl @ 2005-09-22 14:14 UTC (permalink / raw)
To: Vsevolod Fedorov; +Cc: caml-list
On 9/22/05, Vsevolod Fedorov <sevaAtWork@mail.ru> wrote:
> The problem is: 'getsockopt_int' returns 'int' while I need Unix.error type.
> I can't map int to error in good way.
I have also run into this same problem a while ago.
> May be is it the time to extend Unix module API?
> For example, add function like 'getsockopt_error' or 'int_to_error'?
There is already a C-function for handling that case in the
OCaml-runtime (unix_error). You only need to write a C-wrapper that
converts the arguments to this function appropriately, and define an
"external"-function in OCaml. Then you can raise the corresponding
Unix_error-exceptions by passing the error code and other arguments
(i.e. name of associated Unix-call and arguments).
But I agree, it would be a very good idea to expose this function in
the standard Unix-module (hint, hint!)...
Best regards,
Markus
--
Markus Mottl http://www.ocaml.info markus.mottl@gmail.com
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [Caml-list] Unix module API: nonblocking connect's errors retrieving
2005-09-22 13:51 Unix module API: nonblocking connect's errors retrieving Vsevolod Fedorov
2005-09-22 14:14 ` [Caml-list] " Markus Mottl
@ 2005-09-27 16:02 ` Jerome Vouillon
1 sibling, 0 replies; 3+ messages in thread
From: Jerome Vouillon @ 2005-09-27 16:02 UTC (permalink / raw)
To: Vsevolod Fedorov; +Cc: caml-list
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
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2005-09-27 16:02 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-09-22 13:51 Unix module API: nonblocking connect's errors retrieving Vsevolod Fedorov
2005-09-22 14:14 ` [Caml-list] " Markus Mottl
2005-09-27 16:02 ` Jerome Vouillon
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox