Skip to content

Commit

Permalink
网络库优化
Browse files Browse the repository at this point in the history
  • Loading branch information
duanhf2012 committed Nov 25, 2024
1 parent 387e83d commit 000853b
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions network/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,15 +111,15 @@ func (netConn *NetConn) doWrite(b []byte) error {
}

// b must not be modified by the others goroutines
func (netConn *NetConn) Write(b []byte) error {
func (netConn *NetConn) Write(b []byte) (int,error) {
netConn.Lock()
defer netConn.Unlock()
if atomic.LoadInt32(&netConn.closeFlag) == 1 || b == nil {
netConn.ReleaseReadMsg(b)
return errors.New("conn is close")
return 0,errors.New("conn is close")
}

return netConn.doWrite(b)
return len(b),netConn.doWrite(b)
}

func (netConn *NetConn) Read(b []byte) (int, error) {
Expand Down Expand Up @@ -150,15 +150,16 @@ func (netConn *NetConn) WriteMsg(args ...[]byte) error {
if atomic.LoadInt32(&netConn.closeFlag) == 1 {
return errors.New("conn is close")
}
return netConn.msgParser.Write(netConn.conn, args...)
return netConn.msgParser.Write(netConn, args...)
}

func (netConn *NetConn) WriteRawMsg(args []byte) error {
if atomic.LoadInt32(&netConn.closeFlag) == 1 {
return errors.New("conn is close")
}

return netConn.Write(args)
_,err:= netConn.Write(args)
return err
}

func (netConn *NetConn) IsConnected() bool {
Expand Down

0 comments on commit 000853b

Please sign in to comment.