zhangmeng
2020-08-20 57e6102fc10909d6e13a4efe463a915c0e47e2ab
library.go
@@ -66,7 +66,12 @@
   chReply chan TransInfo
}
func recvRoutine(ctx context.Context, sock *DgramSocket, wg *sync.WaitGroup, ch chan<- TransInfo) {
const (
   routineSub   = "sub"
   routineReply = "reply"
)
func recvRoutine(ctx context.Context, sock *DgramSocket, wg *sync.WaitGroup, ch chan<- TransInfo, id string) {
   for {
      select {
      case <-ctx.Done():
@@ -80,6 +85,10 @@
                  info: &info,
                  port: peer,
               }
               // if id == routineReply {
               //    fmt.Println("repley server recv:", info)
               // }
            }
         } else {
            // time.Sleep(10 * time.Millisecond)
@@ -152,7 +161,7 @@
   // 启动接收线程
   wg.Add(1)
   go recvRoutine(ctx, sockReply, wg, chSub)
   go recvRoutine(ctx, sockReply, wg, chReply, routineReply)
   repS := &sockServer{
      sock: sockReply,
      info: info.ProcInfo,
@@ -179,7 +188,7 @@
   }
   // 启动接收线程
   wg.Add(1)
   go recvRoutine(ctx, sockSub, wg, chSub)
   go recvRoutine(ctx, sockSub, wg, chSub, routineSub)
   subC := &sockClient{
      sock: sockSub,
      peer: -1,
@@ -360,6 +369,11 @@
                  return nil
               }
            }
         } else {
            try++
            if try > count {
               return nil
            }
         }
      }
   }