2 回答
TA贡献1859条经验 获得超6个赞
包io
import "io"
类型作家
type Writer interface {
Write(p []byte) (n int, err error)
}
Writer 是封装了基本 Write 方法的接口。
Write 将 len(p) 个字节从 p 写入底层数据流。它返回从 p (0 <= n <= len(p)) 写入的字节数以及导致写入提前停止的任何错误。如果 Write 返回 n < len(p),则它必须返回一个非 nil 错误。写入不得修改切片数据,即使是临时修改。
实现不能保留 p。
包网
导入“网”
类型连接
type Conn interface {
// Read reads data from the connection.
// Read can be made to time out and return a Error with Timeout() == true
// after a fixed time limit; see SetDeadline and SetReadDeadline.
Read(b []byte) (n int, err error)
// Write writes data to the connection.
// Write can be made to time out and return a Error with Timeout() == true
// after a fixed time limit; see SetDeadline and SetWriteDeadline.
Write(b []byte) (n int, err error)
// Close closes the connection.
// Any blocked Read or Write operations will be unblocked and return errors.
Close() error
// LocalAddr returns the local network address.
LocalAddr() Addr
// RemoteAddr returns the remote network address.
RemoteAddr() Addr
// SetDeadline sets the read and write deadlines associated
// with the connection. It is equivalent to calling both
// SetReadDeadline and SetWriteDeadline.
//
// A deadline is an absolute time after which I/O operations
// fail with a timeout (see type Error) instead of
// blocking. The deadline applies to all future I/O, not just
// the immediately following call to Read or Write.
//
// An idle timeout can be implemented by repeatedly extending
// the deadline after successful Read or Write calls.
//
// A zero value for t means I/O operations will not time out.
SetDeadline(t time.Time) error
// SetReadDeadline sets the deadline for future Read calls.
// A zero value for t means Read will not time out.
SetReadDeadline(t time.Time) error
// SetWriteDeadline sets the deadline for future Write calls.
// Even if write times out, it may return n > 0, indicating that
// some of the data was successfully written.
// A zero value for t means Write will not time out.
SetWriteDeadline(t time.Time) error
}
Conn 是一个通用的面向流的网络连接。
多个 goroutine 可以同时调用 Conn 上的方法。
func (*IPConn) 写
func (c *IPConn) Write(b []byte) (int, error)
Write 实现了 Conn Write 方法。
它是 io.Writer 接口的实现。Write 将 len(p) 个字节从 p 写入底层数据流。它返回从 p (0 <= n <= len(p)) 写入的字节数 (n) 以及遇到导致写入提前停止的任何 > 错误 (err)。
特别是,对于 net.Conn 接口, func (*IPConn) Write 将数据写入连接。可以使写入超时并在固定时间限制后使用 Timeout() == true 返回错误;请参阅 SetDeadline 和 SetWriteDeadline。
- 2 回答
- 0 关注
- 378 浏览
添加回答
举报