[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lwip-users] stm32: do I have to call tcp_write() even on error?
From: |
bruzzi |
Subject: |
[lwip-users] stm32: do I have to call tcp_write() even on error? |
Date: |
Thu, 7 Jun 2012 08:58:54 -0700 (PDT) |
Hello,
I impelmented modbus over tcp using LwIP library. In case of modbus protocol
error i don't call tcp_write() function, is that correct?
This is my callback function on received packet.
static void modbusserver_send(struct tcp_pcb *tpcb, struct
modbusserver_struct *es)
{
struct pbuf *ptr;
err_t wr_err = ERR_OK;
while ((wr_err == ERR_OK) &&
(es->p != NULL) &&
(es->p->len <= tcp_sndbuf(tpcb)))
{
/* get pointer on pbuf from es structure */
ptr = es->p;
if (wr_err == ERR_OK)
{
u16_t plen;
plen = ptr->len;
if (plen > PROTO_TRAMA_LEN) memcpy(ProtoStatus[PROTO_TCP].InBuf,
ptr->payload, PROTO_TRAMA_LEN);
else memcpy(ProtoStatus[PROTO_TCP].InBuf, ptr->payload, plen);
/* enqueue data for transmission */
if (Proto_Modbus_Main_TCP(PROTO_TCP) == 0) wr_err = tcp_write(tpcb,
ProtoStatus[PROTO_TCP].OutBuf, ProtoStatus[PROTO_TCP].OutCounter, 1);
/* continue with next pbuf in chain (if any) */
es->p = ptr->next;
if(es->p != NULL)
{
/* increment reference count for es->p */
pbuf_ref(es->p);
}
/* free pbuf: will free pbufs up to es->p (because es->p has a
reference
count > 0) */
pbuf_free(ptr);
/* Update tcp window size to be advertized : should be called when
received
data (with the amount plen) has been processed by the application
layer */
tcp_recved(tpcb, plen);
}
else if(wr_err == ERR_MEM)
{
/* we are low on memory, try later / harder, defer to poll */
es->p = ptr;
}
else
{
/* other problem ?? */
}
}
}
Thanks and best regards
ms
--
View this message in context:
http://old.nabble.com/stm32%3A-do-I-have-to-call-tcp_write%28%29-even-on-error--tp33976582p33976582.html
Sent from the lwip-users mailing list archive at Nabble.com.
- [lwip-users] stm32: do I have to call tcp_write() even on error?,
bruzzi <=