[#38080] ポートが閉じているときの例外など — Mitsuru Ogino <ogino@...>

荻野と申します。いつも質問や要望ばかりですみません。

36 messages 2003/08/11
[#38086] Re: ポートが閉じているときの例外など — nobu.nakada@... 2003/08/12

なかだです。

[#38088] Re: ポートが閉じているときの例外など — IWAOKA Masahiro <iwaoka@...> 2003/08/12

いわおかです。

[#38091] Re: ポートが閉じているときの例外など — Mitsuru Ogino <ogino@...> 2003/08/12

荻野です。

[#38092] Re: ポートが閉じているときの例外など — nobu.nakada@... 2003/08/12

なかだです。

[#38093] Re: ポートが閉じているときの例外など — IWAOKA Masahiro <iwaoka@...> 2003/08/12

いわおかです。

[#38095] Re: ポートが閉じているときの例外など — Takahiro Kambe <taca@...> 2003/08/12

In message <20030812150516.GV37221@barber.fe.rn.tuat.ac.jp>

[#38102] Re: ポートが閉じているときの例外など — Tetsuo NAKAGAWA <tet@...> 2003/08/14

中川と申します。

[#38121] Re: ポートが閉じているときの例外など — Takahiro Kambe <taca@...> 2003/08/15

In message <20030814.140757.707824131.tetsuo@sapphire.siz.nes.nec.co.jp>

[#38123] Re: ポートが閉じているときの例外など — nobu.nakada@... 2003/08/16

なかだです。

[#38130] Re: ポートが閉じているときの例外など — Takahiro Kambe <taca@...> 2003/08/16

In message <200308160517.h7G5HcPL012839@sharui.nakada.kanuma.tochigi.jp>

[#38137] Re: ポートが閉じているときの例外など — nobu.nakada@... 2003/08/18

なかだです。

[#38139] Re: ポートが閉じているときの例外など — Takahiro Kambe <taca@...> 2003/08/18

In message <200308180959.h7I9xnb7001977@sharui.nakada.kanuma.tochigi.jp>

[#38122] ruby-tcpwrap and mkmf.rb — Takahiro Kambe <taca@...>

こんにちは。

16 messages 2003/08/16
[#38125] Re: ruby-tcpwrap and mkmf.rb — "Akinori MUSHA" <knu@...> 2003/08/16

At Sat, 16 Aug 2003 12:51:55 +0900,

[#38183] String << の動作につきまして — kuto@...

うと と申します。

44 messages 2003/08/22
[#38187] Re: String << の動作につきまして — Take_tk <ggb03124@...> 2003/08/22

たけ(tk)です。

[#38189] Re: String << の動作につきまして — Tadayoshi Funaba <tadf@...5.so-net.ne.jp> 2003/08/23

ふなばです。

[#38190] Re: String << の動作につきまして — Take_tk <ggb03124@...> 2003/08/23

たけ(tk)です。

[#38191] Re: String << の動作につきまして — Tadayoshi Funaba <tadf@...5.so-net.ne.jp> 2003/08/23

ふなばです。

[#38194] Re: String << の動作につきまして — Take_tk <ggb03124@...> 2003/08/23

たけ(tk)です。

[#38196] Re: String << の動作につきまして — Tadayoshi Funaba <tadf@...5.so-net.ne.jp> 2003/08/23

ふなばです。

[#38203] Re: String << の動作につきまして — 西 啓一朗 <receiver@...> 2003/08/23

ども、西啓一朗@Ktouth Brand. です。

[#38208] Re: String << の動作につきまして — Tadayoshi Funaba <tadf@...5.so-net.ne.jp> 2003/08/23

ふなばです。

[#38211] Re: String << の動作につきまして — 西 啓一朗 <receiver@...> 2003/08/24

ども、西啓一朗@Ktouth Brand. です。

[#38195] 理解の進め方(Re: String << の動作につきまして) — Tadashi Oh-Ya <toy@...>

おおやです。

36 messages 2003/08/23
[#38206] 理解の進め方:シュールな世界 — Take_tk <ggb03124@...> 2003/08/23

たけ(tk)です。

[#38233] シュールな名前 — Take_tk <ggb03124@...> 2003/08/25

たけ(tk)です

[#38198] Tmailで送るメールに日付がつけられなくなりました — 川田誠司 <kawada.seiji@...>

はじめまして

11 messages 2003/08/23

[#38256] かみ砕いた説明をすべき範囲 — 西 啓一朗 <receiver@...>

ども。西啓一朗@Ktouth Brand. です。

41 messages 2003/08/26
[#38258] Re: かみ砕いた説明をすべき範囲 — nobu.nakada@... 2003/08/26

なかだです。

[#38261] Re: かみ砕いた説明をすべき範囲 — Take_tk <ggb03124@...> 2003/08/26

たけ(tk)です

[#38262] Re: かみ砕いた説明をすべき範囲 — nobu.nakada@... 2003/08/26

なかだです。

[#38264] Re: かみ砕いた説明をすべき範囲 — Take_tk <ggb03124@...> 2003/08/26

たけ(tk)です

[#38265] Re: かみ砕いた説明をすべき範囲 — IWAOKA Masahiro <iwaoka@...> 2003/08/26

いわおかです。

[#38267] Re: かみ砕いた説明をすべき範囲 — Take_tk <ggb03124@...> 2003/08/26

たけ(tk)です

[#38273] Re: かみ砕いた説明をすべき範囲 — matz@... (Yukihiro Matsumoto) 2003/08/26

まつもと ゆきひろです

[ruby-list:38114] IO の close

From: Mitsuru Ogino <ogino@...>
Date: 2003-08-14 16:36:00 UTC
List: ruby-list #38114
荻野です。

On 2003.8.14, at 13:52 Asia/Tokyo, Minero Aoki wrote:

> あと、#finish で IOError を投げたりしますけど、

これで思い出したんですが、前から疑問だったんで、この機会に質問
させてください。

リファレンスマニュアルには、

   close

     入出力ポートをクローズします。以後のこのポートに対する入
     出力操作は例外を発生します。ガーベージコレクトの際にはク
     ローズされていないIOポートはクローズされます。
     Traps:closeをGCにまかせる

     self がパイプでプロセスにつながっていれば、そのプロセス
     の終了を待ち合わせます。

     nil を返します。
     <http://www.ruby-lang.org/ja/man-1.6/index.cgi?cmd=view;name=IO>

とのみあり、close の失敗時については触れていません。が、例えば
Debian GNU/Linux Woody の man 2 close には、

RETURN VALUE
        close returns zero on success, or -1 if an error occurred.
(snip)
NOTES
        Not checking the return value of close  is  a  common  but
        nevertheless   serious  programming  error.   File  system
        implementations which use techniques  as  ``write-behind''
        to  increase  performance may lead to write(2) succeeding,
        although the data has not been  written  yet.   The  error
        status  may be reported at a later write operation, but it
        is guaranteed to be reported on  closing  the  file.   Not
        checking  the  return value when closing the file may lead
        to silent loss of data.  This can especially  be  observed
        with NFS and disk quotas.

        A  successful  close  does not guarantee that the data has
        been successfully saved to  disk,  as  the  kernel  defers
        writes.  It  is  not  common for a filesystem to flush the
        buffers when the stream is closed. If you need to be  sure
        that  the  data  is  physically  stored  use  fsync(2)  or
        sync(2), they will get you closer to that  goal  (it  will
        depend on the disk hardware at this point).

とありますが、IO の close は nil を返すとのみあります。

もし、IOError とかを発生させないのであれば、Ruby ではNFS や quota
が絡むと IO は安心して使えないということになりはしないでしょうか。
例外があがるのであれば、これまたリファレンスマニュアルに明記してあ
ると助かります。

qmail の Maildir 関連を読んだのがきっかけです。これらによると
fsync(2) して返値をチェックして close(2) して返値をチェックすべき、
とあります。
<http://man.qmail.jp/jman5/maildir.html>

また Perl (5.005/5.6.1) で man perlfunc すると、

        close FILEHANDLE
        close   Closes the file or pipe associated with the file
                handle, returning true only if stdio successfully
                flushes buffers and closes the system file
                descriptor.

とあり、やはり成功かどうかを返すようです。

# もちろん、Ruby では例外の方が良いと思いますが。

すみませんが、気になるので教えていただければ幸いです。


-- 
荻野 充 (おぎの みつる) ... 「萩(はぎ)」にあらず
Verama Systems

Key fingerprint = 7F26 5414 1805 F31B 1617  10B7 C117 07AE 1691 9BD1


In This Thread