Lvnszn commented on a change in pull request #82:
URL: https://github.com/apache/dubbo-getty/pull/82#discussion_r749855691
##########
File path: session.go
##########
@@ -418,11 +422,27 @@ func (s *session) WriteBytes(pkg []byte) (int, error) {
return 0, ErrSessionClosed
}
- lg, err := s.Connection.send(pkg)
+ totalSize := len(pkg)
+ if totalSize == 0 {
+ return 0, nil
+ }
+ writeSize := 0
+ s.wlock.Lock()
+ defer s.wlock.Unlock()
+ for totalSize >= maxPacketLen {
Review comment:
addressed.
##########
File path: session.go
##########
@@ -418,11 +422,27 @@ func (s *session) WriteBytes(pkg []byte) (int, error) {
return 0, ErrSessionClosed
}
- lg, err := s.Connection.send(pkg)
+ totalSize := len(pkg)
+ if totalSize == 0 {
+ return 0, nil
+ }
+ writeSize := 0
+ s.wlock.Lock()
+ defer s.wlock.Unlock()
+ for totalSize >= maxPacketLen {
+ _, err := s.Connection.send(pkg[writeSize:(writeSize +
maxPacketLen)])
+ if err != nil {
+ return writeSize, perrors.Wrapf(err,
"s.Connection.Write(pkg len:%d)", len(pkg))
+ }
+ totalSize -= maxPacketLen
+ writeSize += maxPacketLen
+ }
+ lg, err := s.Connection.send(pkg[writeSize:])
if err != nil {
- return 0, perrors.Wrapf(err, "s.Connection.Write(pkg len:%d)",
len(pkg))
+ return writeSize, perrors.Wrapf(err, "s.Connection.Write(pkg
len:%d)", len(pkg))
}
- return lg, nil
+
+ return writeSize + lg, nil
Review comment:
add a var for return, PTAL.
##########
File path: session.go
##########
@@ -418,11 +422,23 @@ func (s *session) WriteBytes(pkg []byte) (int, error) {
return 0, ErrSessionClosed
}
- lg, err := s.Connection.send(pkg)
+ s.wlock.Lock()
+ defer s.wlock.Unlock()
+ totalSize, writeSize := len(pkg), 0
+ for totalSize >= maxPacketLen {
+ _, err := s.Connection.send(pkg[writeSize:(writeSize +
maxPacketLen)])
+ if err != nil {
+ return writeSize, perrors.Wrapf(err,
"s.Connection.Write(pkg len:%d)", len(pkg))
+ }
+ totalSize -= maxPacketLen
+ writeSize += maxPacketLen
+ }
+ lg, err := s.Connection.send(pkg[writeSize:])
Review comment:
Addressed.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]