LoginSignup
1
0

More than 3 years have passed since last update.

【Go】コネクションの読み取りにおけるio.Copyの注意点

Posted at

connectionの読み込みにio.Copyでハマってしまったので
どなたかの役に立てれば。。

io.Copy

io.Copy の挙動はこちらによると

Copy copies from src to dst until either EOF is reached on src or an error occurs. It returns the number of bytes copied and the first error encountered while copying, if any.

となっており、 EOF もしくは エラー が返るまでcopyしてくれる。

ConnectionにおけるEOF

読み込みを考えると、
connectionがcloseし切断された時に io.EOF が返ってくる。

そのため、io.Copyで読み込む際は送信側でconnectionをClose()している必要がある。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0