/****************************************************************************** * FunctionName : espconn_clear_opt * Description : clear the option for connections so that we don't end up bouncing * all connections at the same time . * Parameters : espconn -- the espconn used to set the connection * opt -- the option for clear * Returns : the result *******************************************************************************/ sint8 ICACHE_FLASH_ATTR espconn_clear_opt(struct espconn *espconn, uint8 opt) { espconn_msg *pnode = NULL; struct tcp_pcb *tpcb; bool value = false; if (espconn == NULL) { return ESPCONN_ARG;; } else if (espconn->type != ESPCONN_TCP) return ESPCONN_ARG; /*Find the node depend on the espconn message*/ value = espconn_find_connection(espconn, &pnode); if (value) { pnode->pcommon.espconn_opt &= ~opt; tpcb = pnode->pcommon.pcb; if (espconn_keepalive_enabled(pnode)) espconn_keepalive_disable(tpcb); if (espconn_delay_enabled(pnode)) tcp_nagle_enable(tpcb); return ESPCONN_OK; } else return ESPCONN_ARG; }
socket_error_t lwipv4_socket_set_option(struct socket *socket, const socket_proto_level_t level, const socket_option_type_t type, const void *option, const size_t optionSize) { (void) level; (void) optionSize; socket_error_t err = SOCKET_ERROR_UNIMPLEMENTED; switch (type) { case SOCKET_OPT_NAGLE: { if (socket->family != SOCKET_STREAM) return SOCKET_ERROR_UNIMPLEMENTED; /* Check the pointer. If it is NULL, disable Nagle's Algorithm. If not, enable Nagle's Algorithm. * This approach is used because configuration data could be passed via a structure */ if(option == NULL) { tcp_nagle_disable((struct tcp_pcb *) socket->impl); } else { tcp_nagle_enable((struct tcp_pcb *) socket->impl); } err = SOCKET_ERROR_NONE; break; } default: break; } return err; }
int8_t AsyncServer::_accept(tcp_pcb* pcb, int8_t err){ tcp_accepted(_pcb); if(_connect_cb){ if (_noDelay) tcp_nagle_disable(pcb); else tcp_nagle_enable(pcb); AsyncClient *c = new AsyncClient(pcb); if(c){ _in_lwip_thread = true; c->_in_lwip_thread = true; _connect_cb(_connect_cb_arg, c); c->_in_lwip_thread = false; _in_lwip_thread = false; return ERR_OK; } } if(tcp_close(pcb) != ERR_OK){ tcp_abort(pcb); } log_e("FAIL"); return ERR_OK; }
void AsyncServer::setNoDelay(bool nodelay){ if (!_pcb) return; if (nodelay) tcp_nagle_disable(_pcb); else tcp_nagle_enable(_pcb); }
static void altcp_tcp_nagle_enable(struct altcp_pcb *conn) { if (conn && conn->state) { struct tcp_pcb *pcb = (struct tcp_pcb *)conn->state; ALTCP_TCP_ASSERT_CONN(conn); tcp_nagle_enable(pcb); } }
static int ol_tcp_set_opts(outlet_t *ol, uint8_t *data, int dlen) { uint8_t *p = data; int left = dlen; int saved_active = ol->active; while (left > 0) { int opt = *p++; left--; if (left < 4) return -BAD_ARG; uint32_t val = GET_UINT_32(p); p += 4; left -= 4; switch (opt) { case INET_OPT_RCVBUF: if (val >= 0x80000000) return -BAD_ARG; if (val > ol->max_recv_bufsize) { memnode_t *node = nalloc_N(val); if (node == 0) { // We may return -NO_MEMORY here; a more conservative // approach is to ignore the option and continue printk("ol_tcp_set_opts: cannot expand recv_buffer to %d byte(s)\n", val); continue; } ol->recv_bufsize = val; assert(ol->recv_buf_off <= ol->recv_bufsize); // no truncation memcpy(node->starts, ol->recv_buffer, ol->recv_buf_off); ol->max_recv_bufsize = (void *)node->ends -(void *)node->starts; ol->recv_buffer = (uint8_t *)node->starts; nfree(ol->recv_buf_node); ol->recv_buf_node = node; // ol->recv_buf_off stays the same } else ol->recv_bufsize = val; break; case INET_OPT_PRIORITY: // // There is a priority setting in a PCB. It is always set to high // value to avoid closing of open connections when the stack runs // out of memory. Thus the option is ignored. // //printk("tcp_set_opts: unsupported option SO_PRIORITY ignored\n"); break; case INET_OPT_TOS: ol->tcp->tos = (uint8_t)val; break; case TCP_OPT_NODELAY: // // Nagle's algo fights silly window syndrome. What is its // relationship to not delaying send? // if (val) tcp_nagle_disable(ol->tcp); else tcp_nagle_enable(ol->tcp); break; default: if (inet_set_opt(ol, opt, val) < 0) return -BAD_ARG; } } // // If 'active' option was set among other options, then act immediately to // deliver a buffered packet, if any. // if (saved_active == INET_PASSIVE && ol->active != INET_PASSIVE) { proc_t *cont_proc = scheduler_lookup(ol->owner); assert(cont_proc != 0); recv_bake_packets(ol, cont_proc); } return 0; }