示例#1
0
        private void ProcessRecv(SocketAsyncEventArgs e)
        {
            TCPScanTaskInfo ti = e.UserToken as TCPScanTaskInfo;

            ti.LastTime = DateTime.Now;
            if (e.SocketError != SocketError.Success || e.BytesTransferred < 1)
            {
                if (ti.SendProbes != null && ti.SendProbes.Count != 0 && !ti.IsTotalTimeout)
                {
                    ti.CurrentProbe = ti.SendProbes.Dequeue();
                    this.StartConnect(ti);
                }
                else
                {
                    this.EndTask(ti, new ScanEventArgs(ti.TaskID, ti.EndPoint, ti.CanConnect, e.SocketError.ToString()));
                }
                return;
            }
            MatchResult mr = new MatchResult();

            if (ti.CurrentProbe == null)
            {
                mr = m_configer.MatchData(e.Buffer, e.BytesTransferred, 0, ProbeType.Tcp);
            }
            else
            {
                mr = m_configer.MatchData(e.Buffer, e.BytesTransferred, ti.Port, ProbeType.Tcp, ti.CurrentProbe);
            }
            this.EndTask(ti, new ScanEventArgs(ti.TaskID, ti.EndPoint, mr.Name, mr.RegexLine, mr.DataString, e.Buffer, e.BytesTransferred));
        }
示例#2
0
        private void ProcessRecv(SocketAsyncEventArgs e)
        {
            Socket sock = e.UserToken as Socket;

            if (e.SocketError == SocketError.Success && e.BytesTransferred > 0)
            {
                //add code
                bool            bOK    = true;
                UDPScanTaskInfo ti     = null;
                string          strKey = e.RemoteEndPoint.ToString();
                lock (m_dic_task_running) {
                    if (!m_dic_task_running.ContainsKey(strKey))
                    {
                        bOK = false;
                    }
                    else
                    {
                        ti           = m_dic_task_running[strKey];
                        ti.IsStarted = false;
                        m_dic_task_running.Remove(strKey);
                    }
                }
                if (bOK)
                {
                    MatchResult mr = m_configer.MatchData(e.Buffer, e.BytesTransferred, ((IPEndPoint)e.RemoteEndPoint).Port, ProbeType.Udp);
                    this.EndTask(ti, new ScanEventArgs(ti.TaskID, ti.EndPoint, mr.Name, mr.RegexLine, mr.DataString, e.Buffer, e.BytesTransferred));
                }
            }
            if (!sock.ReceiveFromAsync(e))
            {
                this.ProcessRecv(e);
            }
        }