From 74b626cd9d5b82d82af00583eebd0fde41d73beb Mon Sep 17 00:00:00 2001 From: "jackdaw@loafle.com" Date: Tue, 11 Apr 2017 12:20:05 +0900 Subject: [PATCH] . --- socket_health_crawler.go | 66 +++++++++++++++++++++++++++------------- 1 file changed, 45 insertions(+), 21 deletions(-) diff --git a/socket_health_crawler.go b/socket_health_crawler.go index b796f52..b5d4a86 100644 --- a/socket_health_crawler.go +++ b/socket_health_crawler.go @@ -9,6 +9,11 @@ import ( type SocketHeahthCrawler struct { CrawlerImpl + m matcher.Matcher +} + +func (s *SocketHeahthCrawler) SetMatcher(m matcher.Matcher) { + s.m = m } func (s *SocketHeahthCrawler) getConnection(params map[string]interface{}) (net.Conn, error) { @@ -44,38 +49,57 @@ func (s *SocketHeahthCrawler) getConnection(params map[string]interface{}) (net. } } -func (s *SocketHeahthCrawler) CheckHeahth(params map[string]interface{}, mat matcher.Matcher) (bool, error) { +func (s *SocketHeahthCrawler) CheckHeahth(params map[string]interface{}) (bool, error) { conn, err := s.getConnection(params) if err != nil { return false, err } defer conn.Close() - - if mat.IsPrePacket() == true { + + if s.m.IsPrePacket() == true { bytes := make([]byte, 1024) n, _ := conn.Read(bytes) p := packet.NewPacket(bytes, n) - if mat.Match(0, p, nil) == false { + if s.m.Match(0, p, nil) == false { return false, nil + } else { + + for i := 1 ; i < s.m.PacketCount(); i++ { + pack := s.m.Packet(i) + conn.Write(pack.Buffer) + bytes := make([]byte, 1024) + n, _ := conn.Read(bytes) + + if s.m.IsNoResponse(i) == true { // empty last response + break + } + + p := packet.NewPacket(bytes, n) + if s.m.Match(i, p, nil) == false { + return false, nil + } + } + + } + + } else { + for i := 0 ; i < s.m.PacketCount(); i++ { + pack := s.m.Packet(i) + conn.Write(pack.Buffer) + bytes := make([]byte, 1024) + n, _ := conn.Read(bytes) + + if s.m.IsNoResponse(i) == true { // empty last response + break + } + + p := packet.NewPacket(bytes, n) + if s.m.Match(i, p, nil) == false { + return false, nil + } } } - - for i := 0; i < mat.PacketCount(); i++ { - pack := mat.Packet(i) - conn.Write(pack.Buffer) - bytes := make([]byte, 1024) - n, _ := conn.Read(bytes) - - if mat.IsNoResponse(i) == true { // empty last response - break - } - - p := packet.NewPacket(bytes, n) - if mat.Match(i, p, nil) == false { - return false, nil - } - } - + return true, nil }