mmsss
mmsss

Reputation: 273

Why must I remove [close_out out_channel]?

I wrote the code to send the message in ocaml.

 let out_channel = Unix.out_channel_of_descr sockfd in
 Marshal.to_channel out_channel message [];
 flush out_channel;
 close_out out_channel

However, I got warning.

 GLib-WARNING **: poll(2) failed due to: Bad file descriptor.

I knew the warning was due to [close_out out_channel], and I didn't get the warning when I remove [close_out out_channel] from the code. I don't know why I must remove [close_out out_channel]. Could you tell why?

Upvotes: 1

Views: 181

Answers (1)

Jeffrey Scofield
Jeffrey Scofield

Reputation: 66823

You are making an OCaml channel from sockfd. When you close the channel, you close sockfd. This will confuse whatever layer created sockfd. So things go wrong after that. Whoever is in charge of sockfd is also in charge of closing it. Just leaving out close_out out_channel is actually the right thing to do, I think. But flush out_channel is good.

Upvotes: 1

Related Questions