mirror of
https://github.com/arduino/Arduino.git
synced 2025-01-30 19:52:13 +01:00
Fix issues when tcp error occurred
This commit is contained in:
parent
2645a5b26e
commit
457de8502a
Binary file not shown.
Binary file not shown.
@ -181,6 +181,8 @@ void* getTTCP(uint8_t sock)
|
|||||||
}
|
}
|
||||||
|
|
||||||
int getSock(void * _ttcp)
|
int getSock(void * _ttcp)
|
||||||
|
{
|
||||||
|
if (_ttcp != NULL)
|
||||||
{
|
{
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for (; i<MAX_SOCK_NUM; i++)
|
for (; i<MAX_SOCK_NUM; i++)
|
||||||
@ -188,6 +190,7 @@ int getSock(void * _ttcp)
|
|||||||
if (_ttcp == mapSockTCP[i])
|
if (_ttcp == mapSockTCP[i])
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,9 +31,15 @@
|
|||||||
unsigned int startTime = 0;
|
unsigned int startTime = 0;
|
||||||
extern bool ifStatus;
|
extern bool ifStatus;
|
||||||
static uint8_t tcp_poll_retries = 0;
|
static uint8_t tcp_poll_retries = 0;
|
||||||
|
static int isDataSentCount = 0;
|
||||||
|
|
||||||
bool pending_close = false;
|
bool pending_close = false;
|
||||||
|
|
||||||
|
static void atcp_init()
|
||||||
|
{
|
||||||
|
pending_close = false;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Clean up and free the ttcp structure
|
* Clean up and free the ttcp structure
|
||||||
*/
|
*/
|
||||||
@ -127,7 +133,7 @@ static void tcp_send_data(struct ttcp *ttcp) {
|
|||||||
uint32_t len;
|
uint32_t len;
|
||||||
|
|
||||||
len = ttcp->left;
|
len = ttcp->left;
|
||||||
INFO_TCP("left=%d len:%d tcp_sndbuf:%d\n", ttcp->left, len, tcp_sndbuf(ttcp->tpcb));
|
INFO_TCP_VER("left=%d len:%d tcp_sndbuf:%d\n", ttcp->left, len, tcp_sndbuf(ttcp->tpcb));
|
||||||
|
|
||||||
|
|
||||||
/* don't send more than we have in the payload */
|
/* don't send more than we have in the payload */
|
||||||
@ -141,14 +147,16 @@ static void tcp_send_data(struct ttcp *ttcp) {
|
|||||||
|
|
||||||
uint8_t count = 0;
|
uint8_t count = 0;
|
||||||
do {
|
do {
|
||||||
|
startTime = timer_get_ms();
|
||||||
err = tcp_write(ttcp->tpcb, ttcp->payload, len, TCP_WRITE_FLAG_COPY);
|
err = tcp_write(ttcp->tpcb, ttcp->payload, len, TCP_WRITE_FLAG_COPY);
|
||||||
INFO_TCP("%d) tcp_write len:%d err:%d\n", count++, len, err);
|
INFO_TCP_VER("%d) tcp_write len:%d err:%d\n", count++, len, err);
|
||||||
if (err == ERR_MEM)
|
if (err == ERR_MEM)
|
||||||
{
|
{
|
||||||
len /= 2;
|
len /= 2;
|
||||||
ttcp->buff_sent = 0;
|
ttcp->buff_sent = 0;
|
||||||
}else{
|
}else{
|
||||||
ttcp->buff_sent = 1;
|
ttcp->buff_sent = 1;
|
||||||
|
isDataSentCount = 0;
|
||||||
}
|
}
|
||||||
} while (err == ERR_MEM && len > 1);
|
} while (err == ERR_MEM && len > 1);
|
||||||
|
|
||||||
@ -239,24 +247,30 @@ static void cleanSockState_cb(void *ctx) {
|
|||||||
int sock = getSock(ttcp);
|
int sock = getSock(ttcp);
|
||||||
if (sock != -1)
|
if (sock != -1)
|
||||||
clearMapSockTcp(sock);
|
clearMapSockTcp(sock);
|
||||||
printk("TTCP [%p]: cleanSockState_cb %d\n", ttcp, sock);
|
INFO_TCP("TTCP [%p]: cleanSockState_cb %d\n", ttcp, sock);
|
||||||
_connected = false;
|
_connected = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void cleanSockStateDelayed(void * arg)
|
||||||
|
{
|
||||||
|
INFO_TCP("arg %p\n", arg);
|
||||||
|
timer_sched_timeout_cb(1000, TIMEOUT_ONESHOT,
|
||||||
|
cleanSockState_cb, arg);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Only used in TCP mode.
|
* Only used in TCP mode.
|
||||||
*/
|
*/
|
||||||
static void atcp_conn_err_cb(void *arg, err_t err) {
|
static void atcp_conn_err_cb(void *arg, err_t err) {
|
||||||
struct ttcp* ttcp = arg;
|
struct ttcp* ttcp = arg;
|
||||||
|
|
||||||
printk("TTCP [%p]: connection error: %d\n",
|
WARN("TTCP [%p]: connection error: %d arg:%p\n",
|
||||||
ttcp, err);
|
ttcp, err, arg);
|
||||||
|
|
||||||
if (ifStatus == false)
|
if (ifStatus == false)
|
||||||
printk("Abort connection\n");
|
printk("Abort connection\n");
|
||||||
cleanSockState_cb(ttcp);
|
cleanSockState_cb(ttcp);
|
||||||
//ttcp->tpcb = NULL; /* free'd by lwip upon return */
|
pending_close = false;
|
||||||
//ard_tcp_done(ttcp, err);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void close_conn(struct ttcp *_ttcp) {
|
static void close_conn(struct ttcp *_ttcp) {
|
||||||
@ -294,20 +308,15 @@ void closeConnections()
|
|||||||
static err_t atcp_recv_cb(void *arg, struct tcp_pcb *pcb, struct pbuf *p,
|
static err_t atcp_recv_cb(void *arg, struct tcp_pcb *pcb, struct pbuf *p,
|
||||||
err_t err) {
|
err_t err) {
|
||||||
struct ttcp* ttcp = arg;
|
struct ttcp* ttcp = arg;
|
||||||
/* p will be NULL when remote end is done */
|
|
||||||
if (p == NULL) {
|
INFO_TCP("pcb:%p p: %p err:%d\n", pcb, p, err);
|
||||||
INFO_TCP("atcp_recv_cb p=NULL\n");
|
if (err == ERR_OK && p != NULL) {
|
||||||
//ard_tcp_done(ttcp, 0);
|
|
||||||
close_conn(ttcp);
|
|
||||||
return ERR_OK;
|
|
||||||
}
|
|
||||||
DATA_LED_ON();
|
DATA_LED_ON();
|
||||||
/* for print_stats() */
|
/* for print_stats() */
|
||||||
ttcp->recved += p->tot_len;
|
ttcp->recved += p->tot_len;
|
||||||
|
|
||||||
if ((ttcp->verbose)||(verboseDebug & INFO_TCP_FLAG)) {
|
if ((ttcp->verbose)||(verboseDebug & INFO_TCP_FLAG)) {
|
||||||
INFO_TCP("Recv:%d\n",p->tot_len);
|
INFO_TCP("Recv:%d\n",p->tot_len);
|
||||||
//INFO_TCP("%s\n",(char*)p->payload);
|
|
||||||
DUMP_TCP(p->payload, p->tot_len);
|
DUMP_TCP(p->payload, p->tot_len);
|
||||||
ttcp->print_cnt++;
|
ttcp->print_cnt++;
|
||||||
}
|
}
|
||||||
@ -316,6 +325,14 @@ static err_t atcp_recv_cb(void *arg, struct tcp_pcb *pcb, struct pbuf *p,
|
|||||||
tcp_recved(pcb, p->tot_len);
|
tcp_recved(pcb, p->tot_len);
|
||||||
pbuf_free(p);
|
pbuf_free(p);
|
||||||
DATA_LED_OFF();
|
DATA_LED_OFF();
|
||||||
|
}
|
||||||
|
|
||||||
|
/* p will be NULL when remote end is done */
|
||||||
|
if (err == ERR_OK && p == NULL) {
|
||||||
|
INFO_TCP("atcp_recv_cb p=NULL\n");
|
||||||
|
close_conn(ttcp);
|
||||||
|
}
|
||||||
|
|
||||||
return ERR_OK;
|
return ERR_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -328,6 +345,14 @@ static err_t atcp_poll(void *arg, struct tcp_pcb *pcb) {
|
|||||||
struct ttcp* _ttcp = arg;
|
struct ttcp* _ttcp = arg;
|
||||||
++tcp_poll_retries;
|
++tcp_poll_retries;
|
||||||
|
|
||||||
|
if (tcp_poll_retries > 4) {
|
||||||
|
INFO_TCP("ARD TCP [%p] arg=%p retries=%d\n",
|
||||||
|
pcb, arg, tcp_poll_retries);
|
||||||
|
tcp_poll_retries = 0;
|
||||||
|
tcp_abort(pcb);
|
||||||
|
return ERR_ABRT;
|
||||||
|
}
|
||||||
|
|
||||||
if (pending_close)
|
if (pending_close)
|
||||||
{
|
{
|
||||||
err_t err = tcp_close(pcb);
|
err_t err = tcp_close(pcb);
|
||||||
@ -336,14 +361,12 @@ static err_t atcp_poll(void *arg, struct tcp_pcb *pcb) {
|
|||||||
else
|
else
|
||||||
pending_close = false;
|
pending_close = false;
|
||||||
|
|
||||||
INFO_TCP("ARD TCP [%p-%p] try to close pending:%d\n", pcb, _ttcp->tpcb, pending_close);
|
INFO_TCP("ARD TCP [%p-%p] try to close pending:%d\n", pcb, (_ttcp)?_ttcp->tpcb:0, pending_close);
|
||||||
|
}else{
|
||||||
|
INFO_TCP("ARD TCP [%p-%p] arg=%p retries=%d\n", (_ttcp)?_ttcp->tpcb:0, pcb, arg, tcp_poll_retries);
|
||||||
|
if (_ttcp) tcp_send_data(_ttcp);
|
||||||
|
else WARN("ttcp NULL!");
|
||||||
}
|
}
|
||||||
if (tcp_poll_retries > 4) {
|
|
||||||
tcp_abort(pcb);
|
|
||||||
return ERR_ABRT;
|
|
||||||
}
|
|
||||||
//tcp_send_data(_ttcp);
|
|
||||||
INFO_TCP("ARD TCP [%p] arg=%p retries=%d\n", pcb, arg, tcp_poll_retries);
|
|
||||||
|
|
||||||
return ERR_OK;
|
return ERR_OK;
|
||||||
}
|
}
|
||||||
@ -386,6 +409,7 @@ static int atcp_start(struct ttcp* ttcp) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
tcp_arg(ttcp->tpcb, ttcp);
|
tcp_arg(ttcp->tpcb, ttcp);
|
||||||
|
atcp_init();
|
||||||
|
|
||||||
if (ttcp->mode == TTCP_MODE_TRANSMIT) {
|
if (ttcp->mode == TTCP_MODE_TRANSMIT) {
|
||||||
tcp_err(ttcp->tpcb, atcp_conn_err_cb);
|
tcp_err(ttcp->tpcb, atcp_conn_err_cb);
|
||||||
@ -662,11 +686,10 @@ uint8_t getModeTcp(void* p) {
|
|||||||
|
|
||||||
uint8_t isDataSent(void* p) {
|
uint8_t isDataSent(void* p) {
|
||||||
struct ttcp *_ttcp = (struct ttcp *)p;
|
struct ttcp *_ttcp = (struct ttcp *)p;
|
||||||
static int isDataSentCount = 0;
|
|
||||||
|
|
||||||
if ((_ttcp)&&(!_ttcp->buff_sent))
|
if ((_ttcp)&&(!_ttcp->buff_sent))
|
||||||
{
|
{
|
||||||
INFO_TCP("%d) Wait to send data\n", ++isDataSentCount);
|
INFO_TCP_VER("%d) Wait to send data\n", ++isDataSentCount);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -695,7 +718,6 @@ int sendTcpData(void* p, uint8_t* buf, uint16_t len) {
|
|||||||
INFO_TCP_VER("buf:%p len:%d\n", buf, len);
|
INFO_TCP_VER("buf:%p len:%d\n", buf, len);
|
||||||
DUMP_TCP(buf,len);
|
DUMP_TCP(buf,len);
|
||||||
|
|
||||||
startTime = timer_get_ms();
|
|
||||||
struct ttcp* _ttcp = (struct ttcp*) p;
|
struct ttcp* _ttcp = (struct ttcp*) p;
|
||||||
if ((_ttcp != NULL) && (_ttcp->tpcb != NULL) &&
|
if ((_ttcp != NULL) && (_ttcp->tpcb != NULL) &&
|
||||||
(buf != NULL) && (len != 0) && (_ttcp->payload != NULL)) {
|
(buf != NULL) && (len != 0) && (_ttcp->payload != NULL)) {
|
||||||
|
@ -86,12 +86,6 @@ struct ctx_server {
|
|||||||
bool ifStatus = false;
|
bool ifStatus = false;
|
||||||
bool scanNetCompleted = false;
|
bool scanNetCompleted = false;
|
||||||
|
|
||||||
// to maintain the word alignment
|
|
||||||
//#define PAD_CTX_SIZE 0x18
|
|
||||||
//#define PAD_NETIF_SIZE 0x3c
|
|
||||||
#define PAD_CTX_SIZE 0
|
|
||||||
#define PAD_NETIF_SIZE 0
|
|
||||||
|
|
||||||
static bool initSpiComplete = false;
|
static bool initSpiComplete = false;
|
||||||
|
|
||||||
// variable used as enable flag for debug prints
|
// variable used as enable flag for debug prints
|
||||||
@ -396,11 +390,11 @@ main(void)
|
|||||||
#else
|
#else
|
||||||
printk("Arduino Wifi Startup... [%s]\n", __TIMESTAMP__);
|
printk("Arduino Wifi Startup... [%s]\n", __TIMESTAMP__);
|
||||||
|
|
||||||
size_t size_ctx_server = sizeof(struct ctx_server)+PAD_CTX_SIZE;
|
size_t size_ctx_server = sizeof(struct ctx_server);
|
||||||
hs = calloc(1, size_ctx_server);
|
hs = calloc(1, size_ctx_server);
|
||||||
ASSERT(hs, "out of memory");
|
ASSERT(hs, "out of memory");
|
||||||
|
|
||||||
size_t size_netif = sizeof(struct netif)+PAD_NETIF_SIZE;
|
size_t size_netif = sizeof(struct netif);
|
||||||
hs->net_cfg.netif = calloc(1, size_netif);
|
hs->net_cfg.netif = calloc(1, size_netif);
|
||||||
ASSERT(hs->net_cfg.netif, "out of memory");
|
ASSERT(hs->net_cfg.netif, "out of memory");
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user