caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] Ocaml 3.06 bug
@ 2002-09-20 13:47 Cezary Kaliszyk
  2002-10-01  9:57 ` Xavier Leroy
  0 siblings, 1 reply; 4+ messages in thread
From: Cezary Kaliszyk @ 2002-09-20 13:47 UTC (permalink / raw)
  To: caml-list

[-- Attachment #1: Type: text/plain, Size: 913 bytes --]


Concerning Ocaml version 3.06 on i686/Linux

There is a bug in the Unix library, which makes my program exit with
no warning message.

It happens when I call Unix.write two times on a descriptor closed
by the other side.

When I connect to the server and close the connection during 5 seconds
(ie using telnet) the server somehow exits the 'while true do'. The first
write is ok, the second exits the program.

Putting a "try .. with _ -> ()" inside the loop doesn't correct it.

It works the same way when compiled with ocamlc and ocamlopt.

The maximally simplifided server code producing the error:


open Unix;;
let addr = ADDR_INET (inet_addr_any, 1717);;
let sock = socket PF_INET SOCK_STREAM 0;;
bind sock addr;
listen sock 10;
while true do
  let (desc,caller) = accept sock in sleep 5;
  let _ = write desc "asd" 0 3 in
  let _ = write desc "qwe" 0 3 in ()
done;;


-- 

[-- Attachment #2: Type: application/pgp-signature, Size: 254 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Caml-list] Ocaml 3.06 bug
  2002-09-20 13:47 [Caml-list] Ocaml 3.06 bug Cezary Kaliszyk
@ 2002-10-01  9:57 ` Xavier Leroy
  2002-10-01 16:53   ` Thaddeus L. Olczyk
  0 siblings, 1 reply; 4+ messages in thread
From: Xavier Leroy @ 2002-10-01  9:57 UTC (permalink / raw)
  To: Cezary Kaliszyk; +Cc: caml-list

> There is a bug in the Unix library, which makes my program exit with
> no warning message.
> 
> It happens when I call Unix.write two times on a descriptor closed
> by the other side.

It's not an OCaml bug, it's a Unix feature.  Writes on a socket that
corresponds to a closed connection generates a SIGPIPE signal, whose
default effect is to kill your process.  

There are ways to catch SIGPIPE or to replace it by an error code
generated by Unix.write; please consult a Unix programming guide
(e.g. Steven's books).

- Xavier Leroy
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Caml-list] Ocaml 3.06 bug
  2002-10-01  9:57 ` Xavier Leroy
@ 2002-10-01 16:53   ` Thaddeus L. Olczyk
  2002-10-01 17:41     ` Luc Maranget
  0 siblings, 1 reply; 4+ messages in thread
From: Thaddeus L. Olczyk @ 2002-10-01 16:53 UTC (permalink / raw)
  To: caml-list

On Tue, 01 Oct 2002 11:57:28 +0200, Xavier Leroy
<xavier.leroy@inria.fr> wrote:

>> There is a bug in the Unix library, which makes my program exit with
>> no warning message.
>> 
>> It happens when I call Unix.write two times on a descriptor closed
>> by the other side.
>
>It's not an OCaml bug, it's a Unix feature.  Writes on a socket that
>corresponds to a closed connection generates a SIGPIPE signal, whose
>default effect is to kill your process.  
>
>There are ways to catch SIGPIPE or to replace it by an error code
>generated by Unix.write; please consult a Unix programming guide
>(e.g. Steven's books).
>
You are begging the question.
Reading Stevens won't help much if you don't know how signals are
handled in OCaml.
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Caml-list] Ocaml 3.06 bug
  2002-10-01 16:53   ` Thaddeus L. Olczyk
@ 2002-10-01 17:41     ` Luc Maranget
  0 siblings, 0 replies; 4+ messages in thread
From: Luc Maranget @ 2002-10-01 17:41 UTC (permalink / raw)
  To: olczyk; +Cc: caml-list

> You are begging the question.
> Reading Stevens won't help much if you don't know how signals are
> handled in OCaml.
> -------------------


Well I have done similar things recently.
The Unix library provides more or less unix system calls,
so I use man 2...

In your case, if I understand well.

First, ignore SIGPIPE, we are real hackers, we look at return codes
of every IO operation (in C).

In Caml, it's something like :
Sys.set_signal Sys.sigpipe Sys.Signal_ignore 


Then, write, flush, printf etc. should normally return some error
code.

In C, you then need to have a look at the errno variable.
In Caml this means raising some exception, namely Sys_error "message".

To get information on those error codes, you can do ``man 2 write''
for instance. The "message" string gives a readable (?) interpretation
of the error code.


Hope this helps. Apologize for any over-simplification.

--Luc


-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2002-10-01 17:42 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-09-20 13:47 [Caml-list] Ocaml 3.06 bug Cezary Kaliszyk
2002-10-01  9:57 ` Xavier Leroy
2002-10-01 16:53   ` Thaddeus L. Olczyk
2002-10-01 17:41     ` Luc Maranget

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).