Exemple #1
0
        private static void Error(object arg, err_t err)
        {
            TcpCep _this = (TcpCep)arg;

            Task wtask = null;

            foreach (Task task in _this.m_SendTaskQueue)
            {
                if ((task.rtsk.tskwait != TSKWAIT.TTW_TCP) ||
                    (task.rtsk.wid != _this.m_CepID))
                {
                    continue;
                }

                wtask = task;
                break;
            }

            bool ok = false;

            if (wtask != null)
            {
                ok = wtask.ReleaseWait();
            }

            if (_this.m_TPcb != null)
            {
                _this.m_lwIP.tcp.tcp_close(_this.m_TPcb);
            }
        }
Exemple #2
0
        private static err_t Connected(object arg, tcp_pcb tpcb, err_t err)
        {
            TcpCep _this = (TcpCep)arg;

            if (err != err_t.ERR_OK)
            {
                err = _this.m_lwIP.tcp.tcp_close(tpcb);
                return(err);
            }

            Task wtask = null;

            foreach (Task task in _this.m_SendTaskQueue)
            {
                if ((task.rtsk.tskwait != TSKWAIT.TTW_TCP) ||
                    (task.rtsk.wid != _this.m_CepID))
                {
                    continue;
                }

                wtask = task;
                break;
            }

            if (wtask != null)
            {
                _this.m_SendTaskQueue.Remove(wtask);

                _this.NewSession(tpcb);
                wtask.ReleaseWait();
            }

            return(err_t.ERR_OK);
        }
Exemple #3
0
        private static err_t RecvData(object arg, tcp_pcb tpcb, pbuf p, err_t err)
        {
            TcpCep _this = (TcpCep)arg;

            if (p == null)
            {
                _this.NetworkToHost(null);
                return(err_t.ERR_OK);
            }

            if (err != err_t.ERR_OK)
            {
                _this.m_lwIP.pbuf_free(p);
                return(err);
            }

            _this.NetworkToHost(p);

            _this.m_lwIP.tcp.tcp_recved(tpcb, p.tot_len);

            return(err_t.ERR_OK);
        }
Exemple #4
0
        internal ER CreateTcpCep(ID cepid, ref T_TCP_CCEP pk_ccep, out ID p_cepid)
        {
            int i;

            //if (pk_ccep == null)
            //	return ER.E_PAR;

            if (cepid == ID.ID_AUTO)
            {
                //if (p_cepid == 0)
                //	return ER.E_PAR;

                cepid.Value = 1;

                for (i = 0; ; i++)
                {
                    if (i >= m_TcpCepTable.Count)
                    {
                        TcpCep tcpCep = new TcpCep(cepid, ref pk_ccep, this, m_lwIP);
                        m_TcpCepTable.Add(tcpCep);
                        break;
                    }

                    if (cepid == m_TcpCepTable[i].CepID)
                    {
                        cepid.Value++;
                    }
                    else
                    {
                        TcpCep tcpCep = new TcpCep(cepid, ref pk_ccep, this, m_lwIP);
                        m_TcpCepTable.Insert(i, tcpCep);
                        break;
                    }
                }
                p_cepid = cepid;
            }
            else
            {
                ID tmpid;

                p_cepid = ID.NULL;

                for (i = 0; i < m_TcpCepTable.Count; i++)
                {
                    tmpid = m_TcpCepTable[i].CepID;

                    if (cepid == tmpid)
                    {
                        return(ER.E_OBJ);
                    }
                    else if (cepid < tmpid)
                    {
                        break;
                    }
                }
                TcpCep tcpCep = new TcpCep(cepid, ref pk_ccep, this, m_lwIP);
                m_TcpCepTable.Insert(i, tcpCep);
            }

            return(ER.E_OK);
        }
Exemple #5
0
        public void OnSysTime()
        {
            bool Retry = false;

            m_SysTime.Value += m_SysTmrIntv;

            do
            {
                foreach (CyclicHandler Cyc in m_CyclicHandlerTable)
                {
                    if (Cyc != null)
                    {
                        Retry = Cyc.OnTime(m_SysTmrIntv) || Retry;
                    }
                }
            } while (Retry);

            foreach (Task Task in m_TaskTable)
            {
                if ((Task != null) &&
                    ((Task.rtsk.tskstat == TSKSTAT.TTS_WAI) || (Task.rtsk.tskstat == TSKSTAT.TTS_WAS)))
                {
                    Task.Progress(m_SysTmrIntv);
                }
            }

            foreach (UdpCep UdpCep in m_UdpCepTable)
            {
                if ((UdpCep != null) && (UdpCep.State))
                {
                    UdpCep.Progress(m_SysTmrIntv);
                }
            }

            foreach (Udp6Cep Udp6Cep in m_Udp6CepTable)
            {
                if ((Udp6Cep != null) && (Udp6Cep.State))
                {
                    Udp6Cep.Progress(m_SysTmrIntv);
                }
            }

            foreach (TcpCep TcpCep in m_TcpCepTable)
            {
                if ((TcpCep != null) && (TcpCep.State))
                {
                    TcpCep.Progress(m_SysTmrIntv);
                }
            }

            foreach (Task Task in m_TaskTable)
            {
                if ((Task != null) &&
                    ((Task.rtsk.tskstat == TSKSTAT.TTS_WAI) || (Task.rtsk.tskstat == TSKSTAT.TTS_WAS)))
                {
                    Task.CallTimeOut();
                }
            }

            foreach (UdpCep UdpCep in m_UdpCepTable)
            {
                if ((UdpCep != null) && (UdpCep.State))
                {
                    UdpCep.CallTimeOut();
                }
            }

            foreach (Udp6Cep Udp6Cep in m_Udp6CepTable)
            {
                if ((Udp6Cep != null) && (Udp6Cep.State))
                {
                    Udp6Cep.CallTimeOut();
                }
            }

            foreach (TcpCep TcpCep in m_TcpCepTable)
            {
                if ((TcpCep != null) && (TcpCep.State))
                {
                    TcpCep.CallTimeOut();
                }
            }
        }
Exemple #6
0
        internal ER Accept(tcp_pcb_listen pcb, TcpCep cep, T_IPV4EP p_dstaddr, TMO tmout)
        {
            ER ret;

            m_Pcb    = pcb;
            m_TcpCep = cep;

            tcp.tcp_accept(pcb, Accepting);

            Task task = m_Nucleus.GetTask(ID.TSK_SELF);

            if ((tmout != 0) && (task == null))
            {
                return(ER.E_CTX);
            }

            //if (p_dstaddr == null)
            //	return ER.E_PAR;

            if ((m_TskQueue.First == null) && (m_AcceptQueue.First != null))
            {
                m_NewPcb = m_AcceptQueue.First.Value;
                m_AcceptQueue.RemoveFirst();
                p_dstaddr.ipaddr = lwip.lwip_ntohl(m_NewPcb.remote_ip.addr);
                p_dstaddr.portno = lwip.lwip_ntohs(m_NewPcb.remote_port);
            }
            else
            {
                if (task == null)
                {
                    return(ER.E_TMOUT);
                }

                if (tmout == 0)
                {
                    return(ER.E_TMOUT);
                }

                ret = task.Wait(m_TskQueue, TSKWAIT.TTW_ACP, m_RepID, tmout);

                switch (ret)
                {
                case ER.E_OK:
                    if (m_AcceptQueue.First == null)
                    {
                        return(ER.E_RLWAI);
                    }
                    m_NewPcb = m_AcceptQueue.First.Value;
                    m_AcceptQueue.RemoveFirst();
                    p_dstaddr.ipaddr = lwip.lwip_ntohl(m_NewPcb.remote_ip.addr);
                    p_dstaddr.portno = lwip.lwip_ntohs(m_NewPcb.remote_port);
                    break;

                case ER.E_TMOUT:
                    return(ER.E_TMOUT);

                default:
                    return(ER.E_RLWAI);
                }
            }

            return(ER.E_OK);
        }