public ER Connect(T_IPV4EP p_myaddr, T_IPV4EP p_dstaddr, TMO tmout) { err_t err; ip_addr ma = new ip_addr(0); ip_addr sa = new ip_addr(0); ma.addr = lwip.lwip_htonl(p_myaddr.ipaddr); err = m_lwIP.tcp.tcp_bind(m_Pcb, ma, lwip.lwip_htons(p_myaddr.portno)); if (err != err_t.ERR_OK) { return(ER.E_OBJ); } sa.addr = lwip.lwip_htonl(p_dstaddr.ipaddr); err = m_lwIP.tcp.tcp_connect(m_Pcb, sa, lwip.lwip_htons(p_dstaddr.portno), Connected); if (err != err_t.ERR_OK) { return(ER.E_OBJ); } Task task = m_Nucleus.GetTask(ID.TSK_SELF); if ((tmout != 0) && (task == null)) { return(ER.E_CTX); } if (task == null) { return(ER.E_TMOUT); } if (tmout == 0) { return(ER.E_TMOUT); } SetState(true, new TMO(tcp.TCP_TMR_INTERVAL), task, Intarval); ER ret = task.Wait(m_SendTaskQueue, TSKWAIT.TTW_TCP, m_CepID, tmout); switch (ret) { case ER.E_OK: if ((m_TPcb == null) || (m_TPcb.state != tcp_state.ESTABLISHED)) { return(ER.E_RLWAI); } break; case ER.E_TMOUT: return(ER.E_TMOUT); default: return(ER.E_RLWAI); } return(ER.E_OK); }
private void recv(object arg, udp_pcb pcb, pbuf p, ip_addr addr, ushort port) { System.Diagnostics.Debug.Assert((arg == this) && (pcb == m_Pcb)); pointer data = new pointer(new byte[sizeof(ushort) + T_IPV4EP.length + p.tot_len], 0); T_IPV4EP p_dstaddr = new T_IPV4EP(data, sizeof(ushort)); pointer p_dat = new pointer(data, sizeof(ushort) + T_IPV4EP.length); data.SetValue(p.tot_len); p_dstaddr.ipaddr = lwip.lwip_ntohl(addr.addr); 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); }
public ER SendData(T_IPV4EP p_dstaddr, pointer p_dat, int len, TMO tmout) { pbuf buf; ip_addr addr = new ip_addr(lwip.lwip_htonl(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); }
public ER ReceiveData(T_IPV4EP 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_IPV4EP.length); pointer.memcpy(p_dat, data + sizeof(ushort) + T_IPV4EP.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); }
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); }
public ER Accept(TcpRep tcpRep, T_IPV4EP p_dstaddr, TMO tmout) { tcp_pcb_listen pcb = m_lwIP.tcp.tcp_listen(m_Pcb); return(tcpRep.Accept(pcb, this, p_dstaddr, tmout)); }