File tree Expand file tree Collapse file tree 1 file changed +8
-2
lines changed
Expand file tree Collapse file tree 1 file changed +8
-2
lines changed Original file line number Diff line number Diff line change @@ -15,6 +15,8 @@ import (
1515 "github.com/hyperf/roc/serializer"
1616)
1717
18+ var SocketNil = errors .New ("the socket is nil" )
19+
1820type Client struct {
1921 Packer roc.PackerInterface
2022 IdGenerator roc.IdGeneratorInterface
@@ -69,7 +71,7 @@ func NewTcpClient(address string) (*Client, error) {
6971
7072func (c * Client ) SendPacket (p * roc.Packet ) (uint32 , error ) {
7173 if c .Socket == nil {
72- return 0 , errors . New ( "the socket is nil" )
74+ return 0 , SocketNil
7375 }
7476
7577 bt := c .Packer .Pack (p )
@@ -155,6 +157,10 @@ func (c *Client) Loop() {
155157 for {
156158 buf , err := c .readAll (4 )
157159 if err != nil {
160+ if errors .Is (err , SocketNil ) {
161+ time .Sleep (5 * time .Second )
162+ }
163+
158164 if err != io .EOF {
159165 log .Printf ("Error reading %s" , err )
160166 }
@@ -188,7 +194,7 @@ func (c *Client) Loop() {
188194
189195func (c * Client ) readAll (length int ) ([]byte , error ) {
190196 if c .Socket == nil {
191- return nil , errors . New ( "the socket is nil" )
197+ return nil , SocketIsNil {}
192198 }
193199
194200 ret := make ([]byte , 0 , length )
You can’t perform that action at this time.
0 commit comments