func (s *MexSocket) StartReadService(mode int) { var mex message.Message defer close(s.incoming) for { select { case <-s.quitChan: return default: if mode == ModeServer { mex = message.NewRequestEmpty() } else if mode == ModeClient { mex = message.NewAnswerEmpty() } else { break } n, lastErr := s.Read(mex) if lastErr == nil && n > 0 { s.incoming <- mex } else if lastErr == io.EOF { go s.Close() return } else { go s.queueErr(lastErr) } } } }
func TestCreateEmpty(t *testing.T) { req := message.NewRequestEmpty().(*message.Request) ans := message.NewAnswerEmpty().(*message.Answer) if assert.NotNil(t, req, "Empty Request should not be nil") { assert.Equal(t, req.Type(), message.Empty, "MessageType should be Empty") } assert.Nil(t, req.Receivers, "Receivers should be nil") assert.Nil(t, req.Body, "Body should be nil") if assert.NotNil(t, ans, "Empty Answer should not be nil") { assert.Equal(t, ans.Type(), message.Empty, "MessageType should be Empty") } assert.Nil(t, ans.Payload, "Payload should be nil") }