第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

golang 的 func (c *IPConn) Write(b []byte)

golang 的 func (c *IPConn) Write(b []byte)

Go
阿波羅的戰(zhàn)車(chē) 2021-12-20 16:43:36
我猜 int 是寫(xiě)入的字節(jié)數(shù)。我認(rèn)為函數(shù)會(huì)阻塞,直到緩沖區(qū)完全寫(xiě)入套接字或套接字關(guān)閉,所以我認(rèn)為這個(gè)數(shù)字沒(méi)有任何關(guān)系(不像在交流套接字中我需要用未寫(xiě)入的字節(jié)重試寫(xiě)入)。我想唯一可以返回的錯(cuò)誤是在寫(xiě)入失敗的情況下,因?yàn)樘捉幼忠殃P(guān)閉?這些似乎都沒(méi)有出現(xiàn)在https://golang.org/pkg/net/#IPConn.Write的文檔中,還是我找錯(cuò)了地方?
查看完整描述

2 回答

?
BIG陽(yáng)

TA貢獻(xiàn)1859條經(jīng)驗(yàn) 獲得超6個(gè)贊

包io


import "io" 

類型作家


type Writer interface {

        Write(p []byte) (n int, err error)

}

Writer 是封裝了基本 Write 方法的接口。


Write 將 len(p) 個(gè)字節(jié)從 p 寫(xiě)入底層數(shù)據(jù)流。它返回從 p (0 <= n <= len(p)) 寫(xiě)入的字節(jié)數(shù)以及導(dǎo)致寫(xiě)入提前停止的任何錯(cuò)誤。如果 Write 返回 n < len(p),則它必須返回一個(gè)非 nil 錯(cuò)誤。寫(xiě)入不得修改切片數(shù)據(jù),即使是臨時(shí)修改。


實(shí)現(xiàn)不能保留 p。


包網(wǎng)


導(dǎo)入“網(wǎng)”


類型連接


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 是一個(gè)通用的面向流的網(wǎng)絡(luò)連接。


多個(gè) goroutine 可以同時(shí)調(diào)用 Conn 上的方法。


func (*IPConn) 寫(xiě)


func (c *IPConn) Write(b []byte) (int, error)

Write 實(shí)現(xiàn)了 Conn Write 方法。


它是 io.Writer 接口的實(shí)現(xiàn)。Write 將 len(p) 個(gè)字節(jié)從 p 寫(xiě)入底層數(shù)據(jù)流。它返回從 p (0 <= n <= len(p)) 寫(xiě)入的字節(jié)數(shù) (n) 以及遇到導(dǎo)致寫(xiě)入提前停止的任何 > 錯(cuò)誤 (err)。


特別是,對(duì)于 net.Conn 接口, func (*IPConn) Write 將數(shù)據(jù)寫(xiě)入連接??梢允箤?xiě)入超時(shí)并在固定時(shí)間限制后使用 Timeout() == true 返回錯(cuò)誤;請(qǐng)參閱 SetDeadline 和 SetWriteDeadline。


查看完整回答
反對(duì) 回復(fù) 2021-12-20
?
胡說(shuō)叔叔

TA貢獻(xiàn)1804條經(jīng)驗(yàn) 獲得超8個(gè)贊

它用于基于 SetWriteDeadline 的超時(shí)。如果超時(shí)并寫(xiě)入了一些字節(jié),您就會(huì)知道寫(xiě)入了多少字節(jié)。


查看完整回答
反對(duì) 回復(fù) 2021-12-20
  • 2 回答
  • 0 關(guān)注
  • 549 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)