func (s *nodeSender) Run() { defer s.Stopped() if RELEASE { ext.AssertE(s.Conn.SetWriteDeadline(time.Now().Add(10 * time.Second))) } WriteBytes(s.Conn, GobEncode(MyInfo())) for !s.StopRequested() { source, target, msg := s.Pop() data := s.Encode(msg) ext.Assert(data != nil) var buf bytes.Buffer enc := gob.NewEncoder(&buf) ext.AssertE(enc.Encode(source)) ext.AssertE(enc.Encode(target)) ext.AssertE(enc.Encode(len(data))) ext.AssertE(enc.Encode(data)) data = buf.Bytes() if s.Compress != nil { data = s.Compress(buf.Bytes()) } if RELEASE { ext.AssertE(s.Conn.SetWriteDeadline(time.Now().Add(time.Minute))) } WriteBytes(s.Conn, data) } }
func (r *nodeReceiver) Run() { defer r.Stopped() defer r.Conn.Close() if RELEASE { ext.AssertE(r.Conn.SetReadDeadline(time.Now().Add(10 * time.Second))) } infoData := ReadBytes(r.Conn) var info nodeInfo GobDecode(infoData, &info) ext.Assert(info.Cookie == MyInfo().Cookie) ext.Assert(info.ID != MyInfo().ID) r.nodeInfo = info AddNode(r.ID, r.nodeInfo) ext.LogDebug("ESTABLISHED\tLOCAL\t%s\tREMOTE\t%s\tINFO\t%v", r.LocalAddr().String(), r.RemoteAddr().String(), r.nodeInfo) for !r.StopRequested() { if RELEASE { ext.AssertE(r.Conn.SetReadDeadline(time.Now().Add(time.Minute))) } data := ReadBytes(r.Conn) if r.Decompress != nil { data = r.Decompress(data) } buf := bytes.NewBuffer(data) dec := gob.NewDecoder(buf) var source, target PID var msgSize int ext.AssertE(dec.Decode(source)) ext.AssertE(dec.Decode(target)) ext.AssertE(dec.Decode(msgSize)) msg := r.Decode(buf.Bytes()) ext.Assert(msg != nil) Cast(source, target, msg) } }
func (w *worker) run() { defer w.Stopped() for !w.StopRequested() { source, target, msg := w.Pop() ext.Assert(source != target) // send to others if source == w.PID { w.BeforeSend(target, msg) w.Push(source, target, msg) } else { w.Handle(source, msg) } } }
func (h *HandlerBase) SendOut(target PID, msg Message) { ext.Assert(h.PID != target) h.Push(h.PID, target, msg) }