In golang, how would you handle error return by TCPConn.Read/Write? this document did not say anything about read/write errors.
1条回答 默认 最新
- dream0776 2015-07-17 13:29关注
Read
andWrite
on aTCPConn
could return most of errors that your combination of OS, hardware and drivers could return, along with somenet
package errors, andio.EOF
when applicable. So it's really up to you to know what errors to look for, and how to handle them. Every layer of network API, even the berkeley socket api, is a leaky abstraction, and you can't make full use of it without understanding how the actual sockets and network protocols work.Usually you only need be concerned with
io.EOF
, which is returned byConn.Read
when the connection is closed. On a TCP socket, this is the equivalent ofrecv
returning 0 bytes on a blocking connection.Any other errors that you could handle are usually wrapped in a
net.Error
, which provides theTemporary()
andTimeout()
methods. Often the real error type is a*net.OpError
, which can provide even more information about when the error occurred, as well as encapsulate the actual error returned by the operation.本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报
悬赏问题
- ¥15 vs2022无法联网
- ¥15 TCP的客户端和服务器的互联
- ¥15 VB.NET操作免驱摄像头
- ¥15 笔记本上移动热点开关状态查询
- ¥85 类鸟群Boids——仿真鸟群避障的相关问题
- ¥15 CFEDEM自带算例错误,如何解决?
- ¥15 有没有会使用flac3d软件的家人
- ¥20 360摄像头无法解绑使用,请教解绑当前账号绑定问题,
- ¥15 docker实践项目
- ¥15 利用pthon计算薄膜结构的光导纳