Example #1
0
        private void recv(object arg, udp_pcb pcb, pbuf p, ip6_addr addr, ushort port)
        {
            System.Diagnostics.Debug.Assert((arg == this) && (pcb == m_Pcb));
            pointer  data      = new pointer(new byte[sizeof(ushort) + T_IPV6EP.length + p.tot_len], 0);
            T_IPV6EP p_dstaddr = new T_IPV6EP(data, sizeof(ushort));
            pointer  p_dat     = new pointer(data, sizeof(ushort) + T_IPV6EP.length);

            data.SetValue(p.tot_len);
            pointer.memcpy(p_dstaddr.ipaddr, addr, T_IPV6ADDR.length);
            p_dstaddr.portno = lwip.lwip_ntohs(port);

            for (pbuf q = p; q != null; q = q.next)
            {
                pointer.memcpy(p_dat, q.payload, q.len);
                p_dat += q.len;
            }

            lock (m_CallBack) {
                m_CallBack.Enqueue(data);
            }

            SetState(true, TMO.TMO_POL, null, OnTimeOut);
        }
Example #2
0
        public ER SendData(T_IPV6EP p_dstaddr, pointer p_dat, int len, TMO tmout)
        {
            pbuf     buf;
            ip6_addr addr = new ip6_addr(p_dstaddr.ipaddr);

            buf = m_lwIP.pbuf_alloc(pbuf_layer.PBUF_TRANSPORT, (ushort)len, pbuf_type.PBUF_POOL);
            if (buf == null)
            {
                return(ER.E_NOMEM);
            }

            int pos = 0;

            for (pbuf q = buf; q != null; q = q.next)
            {
                pointer.memcpy(q.payload, new pointer(p_dat, pos), q.len);
                pos += q.len;
            }

            //m_lwIP.udp.udp_sendto(m_Pcb, buf, addr, p_dstaddr.portno);

            return(ER.E_OK);
        }
Example #3
0
        public ER ReceiveData(T_IPV6EP p_dstaddr, pointer p_dat, int len, TMO tmout)
        {
            ER ret;

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

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

            if ((p_dat == null) || (len < 0))
            {
                return(ER.E_PAR);
            }

            if ((m_TskQueue.First == null) && (m_DatQueue.First != null))
            {
                pointer data;
                lock (m_DatQueue) {
                    data = m_DatQueue.First.Value;
                    m_DatQueue.RemoveFirst();
                }

                int dlen = (ushort)data;
                pointer.memcpy(p_dstaddr, data + sizeof(ushort), T_IPV6EP.length);
                pointer.memcpy(p_dat, data + sizeof(ushort) + T_IPV6EP.length, dlen);

                return((ER)dlen);
            }
            else
            {
                if (task == null)
                {
                    return(ER.E_TMOUT);
                }

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

                ret = task.Wait(m_TskQueue, TSKWAIT.TTW_UDP, m_CepID, tmout);

                switch (ret)
                {
                case ER.E_OK:
                    if (m_DatQueue.First == null)
                    {
                        return(ER.E_RLWAI);
                    }
                    lock (m_DatQueue) {
                        p_dat = new pointer(m_DatQueue.First.Value, 0);
                        m_DatQueue.RemoveFirst();
                    }
                    break;

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

                default:
                    return(ER.E_RLWAI);
                }
            }

            //SetDebugInfo(p_dat, lpszFileName, nLine);

            return(ER.E_OK);
        }