Skip to content

Commit 9bce241

Browse files
committed
修改buf的引用模式
1 parent 215c88e commit 9bce241

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

conn.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,11 @@ type Conn struct {
8787
// input/output
8888
in, out halfConn
8989
rawInput MsgBuffer // raw input, starting with a record header
90-
input *MsgBuffer // 指针指向gnet.conn的inboundBuffer
90+
input **MsgBuffer // 指针指向gnet.conn的inboundBuffer
9191
hand MsgBuffer // handshake data waiting to be read
9292
outBuf []byte // scratch buffer used by out.encrypt
9393
buffering bool // whether records are buffered in sendBuf
94-
sendBuf *MsgBuffer // a buffer of records waiting to be sent
94+
sendBuf **MsgBuffer // a buffer of records waiting to be sent
9595

9696
// bytesSent counts the bytes of application data sent.
9797
// packetsSent counts packets.
@@ -535,7 +535,7 @@ func (c *Conn) readRecord() error {
535535
}
536536

537537
func (c *Conn) readChangeCipherSpec() error {
538-
c.input.Reset()
538+
(*c.input).Reset()
539539
return c.readRecordOrCCS(true)
540540
}
541541

@@ -680,7 +680,7 @@ func (c *Conn) readRecordOrCCS(expectChangeCipherSpec bool) error {
680680
// Note that data is owned by c.rawInput, following the Next call above,
681681
// to avoid copying the plaintext. This is safe because c.rawInput is
682682
// not read from or written to until c.input is drained.
683-
c.input.Write(data)
683+
(*c.input).Write(data)
684684

685685
case recordTypeHandshake:
686686
if len(data) == 0 || expectChangeCipherSpec {
@@ -700,7 +700,7 @@ func (c *Conn) retryReadRecord(expectChangeCipherSpec bool) error {
700700
c.sendAlert(alertUnexpectedMessage)
701701
return c.in.setErrorLocked(errors.New("tls: too many ignored records"))
702702
}
703-
c.input.Reset()
703+
(*c.input).Reset()
704704
if c.rawInput.Len() > 5 {
705705
return c.readRecordOrCCS(expectChangeCipherSpec)
706706
}
@@ -812,13 +812,13 @@ func (c *Conn) maxPayloadSizeForWrite(typ recordType) int {
812812
func (c *Conn) write(data []byte) (n int, err error) {
813813
//必须把所有数据往buf写
814814
n = len(data)
815-
c.sendBuf.Write(data)
815+
(*c.sendBuf).Write(data)
816816
c.bytesSent += int64(n)
817817
return
818818
}
819819

820820
func (c *Conn) flush() (int, error) {
821-
if c.sendBuf.Len() == 0 {
821+
if (*c.sendBuf).Len() == 0 {
822822
return 0, nil
823823
}
824824
n, err := c.conn.Write(nil)

tls.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ type conn interface {
3535
// using conn as the underlying transport.
3636
// The configuration config must be non-nil and must include
3737
// at least one certificate or else set GetCertificate.
38-
func Server(c conn, in, out *MsgBuffer, config *Config) (*Conn, error) {
38+
func Server(c conn, in, out **MsgBuffer, config *Config) (*Conn, error) {
3939
tlsconn := &Conn{
4040
conn: c,
4141
config: config,
@@ -46,7 +46,7 @@ func Server(c conn, in, out *MsgBuffer, config *Config) (*Conn, error) {
4646

4747
return tlsconn, nil
4848
}
49-
func Client(c conn, in, out *MsgBuffer, config *Config) *Conn {
49+
func Client(c conn, in, out **MsgBuffer, config *Config) *Conn {
5050
tlsconn := &Conn{
5151
conn: c,
5252
config: config,

0 commit comments

Comments
 (0)