您当前的位置:首页 > IT编程 > C++
| C语言 | Java | VB | VC | python | Android | TensorFlow | C++ | oracle | 学术与代码 | cnn卷积神经网络 | gnn | 图像修复 | Keras | 数据集 | Neo4j | 自然语言处理 | 深度学习 | 医学CAD | 医学影像 | 超参数 | pointnet | pytorch | 异常检测 | Transformers | 情感分类 | 知识图谱 |

自学教程:C++ tcp_err函数代码示例

51自学网 2021-06-03 08:42:14
  C++
这篇教程C++ tcp_err函数代码示例写得很实用,希望能帮到您。

本文整理汇总了C++中tcp_err函数的典型用法代码示例。如果您正苦于以下问题:C++ tcp_err函数的具体用法?C++ tcp_err怎么用?C++ tcp_err使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。

在下文中一共展示了tcp_err函数的29个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: tcp_do_accept

static int tcp_do_accept(struct socket * listen_sock,			message * m,			struct tcp_pcb * newpcb){	struct socket * newsock;	unsigned sock_num;	int ret;	debug_tcp_print("socket num %ld", get_sock_num(listen_sock));	if ((ret = copy_from_user(m->m_source, &sock_num, sizeof(sock_num),				(cp_grant_id_t) m->IO_GRANT, 0)) != OK)		return EFAULT;	if (!is_valid_sock_num(sock_num))		return EBADF;	newsock = get_sock(sock_num);	assert(newsock->pcb); /* because of previous open() */		/* we really want to forget about this socket */	tcp_err((struct tcp_pcb *)newsock->pcb, NULL);	tcp_abandon((struct tcp_pcb *)newsock->pcb, 0);		tcp_arg(newpcb, newsock);	tcp_err(newpcb, tcp_error_callback);	tcp_sent(newpcb, tcp_sent_callback);	tcp_recv(newpcb, tcp_recv_callback);	tcp_nagle_disable(newpcb);	tcp_accepted(((struct tcp_pcb *)(listen_sock->pcb)));	newsock->pcb = newpcb;	debug_tcp_print("Accepted new connection using socket %d/n", sock_num);	return OK;}
开发者ID:universe-long-zhuo,项目名称:C-Example01,代码行数:35,


示例2: TCPConnected

//*****************************************************************************//// Finalizes the TCP connection in client mode.//// /param pvArg is the state data for this connection.// /param psPcb is the pointer to the TCP control structure.// /param iErr is not used in this implementation.//// This function is called when the lwIP TCP/IP stack has completed a TCP// connection.//// /return This function will return an lwIP defined error code.////*****************************************************************************static err_tTCPConnected(void *pvArg, struct tcp_pcb *psPcb, err_t iErr){    //    // Check if there was a TCP error.    //    if(iErr != ERR_OK)    {        //        // Clear out all of the TCP callbacks.        //        tcp_sent(psPcb, NULL);        tcp_recv(psPcb, NULL);        tcp_err(psPcb, NULL);        //        // Close the TCP connection.        //        tcp_close(psPcb);        if(psPcb == g_sEnet.psTCP)        {            g_sEnet.psTCP = 0;        }        //        // And return.        //        return (ERR_OK);    }    //    // Setup the TCP receive function.    //    tcp_recv(psPcb, TCPReceive);    //    // Setup the TCP error function.    //    tcp_err(psPcb, TCPError);    //    // Setup the TCP sent callback function.    //    tcp_sent(psPcb, TCPSent);    //    // Connection is complete.    //    g_sEnet.eState = iEthTCPConnectComplete;    //    // Return a success code.    //    return(ERR_OK);}
开发者ID:AlexGeControl,项目名称:tiva-c,代码行数:70,


示例3: tcp_err

void EthernetClient::stop(){	if(cpcb == NULL)		return;	_connected = false;	/* Stop frees any resources including any unread buffers */	err_t err;	if(cpcb) {		tcp_err(cpcb, NULL);		if(cs->p) {			tcp_recved(cpcb, cs->p->tot_len);			pbuf_free(cs->p);			cs->p = NULL;		}		err = tcp_close(cpcb);	}	if (err != ERR_OK) {		/* Error closing, try again later in poll (every 2 sec) */		tcp_poll(cpcb, do_poll, 4);	} else {		cpcb = NULL;	}}
开发者ID:Nandopolis,项目名称:Energia,代码行数:28,


示例4: espconn_client_close

/****************************************************************************** * FunctionName : espconn_client_close * Description  : The connection shall be actively closed. * Parameters   : pcb -- Additional argument to pass to the callback function *                pcb -- the pcb to close * Returns      : none*******************************************************************************/static void ICACHE_FLASH_ATTRespconn_client_close(void *arg, struct tcp_pcb *pcb, uint8 type){    err_t err;    espconn_msg *pclose = arg;	pclose->pcommon.pcb = pcb;	/*avoid recalling the disconnect function*/	tcp_recv(pcb, NULL);	if(type == 0)		err = tcp_close(pcb);	else		{tcp_abort(pcb); err = ERR_OK;}	if (err != ERR_OK) {		/* closing failed, try again later */		tcp_recv(pcb, espconn_client_recv);	} else {		/* closing succeeded */		tcp_sent(pcb, NULL);		tcp_err(pcb, NULL);		/*switch the state of espconn for application process*/		pclose->pespconn->state = ESPCONN_CLOSE;		ets_post(espconn_TaskPrio, SIG_ESPCONN_CLOSE, (uint32_t)pclose);		printf("ets_post close/n");	}}
开发者ID:Nicholas3388,项目名称:LuaNode,代码行数:35,


示例5: _connect_cb

AsyncClient::AsyncClient(tcp_pcb* pcb):  _connect_cb(0)  , _connect_cb_arg(0)  , _discard_cb(0)  , _discard_cb_arg(0)  , _sent_cb(0)  , _sent_cb_arg(0)  , _error_cb(0)  , _error_cb_arg(0)  , _recv_cb(0)  , _recv_cb_arg(0)  , _timeout_cb(0)  , _timeout_cb_arg(0)  , _refcnt(0)  , _pcb_busy(false)  , _pcb_sent_at(0)  , _close_pcb(false)  , _rx_last_packet(0)  , _rx_since_timeout(0)  , prev(NULL)  , next(NULL){  _pcb = pcb;  if(pcb){    tcp_setprio(_pcb, TCP_PRIO_MIN);    tcp_arg(_pcb, this);    tcp_recv(_pcb, (tcp_recv_fn) &_s_recv);    tcp_sent(_pcb, &_s_sent);    tcp_err(_pcb, &_s_error);    tcp_poll(_pcb, &_s_poll, 1);  }}
开发者ID:2fatdotco,项目名称:sxsw2016-arduinoLampLibraries,代码行数:32,


示例6: lwip_accept_cb

static err_t lwip_accept_cb(void *arg, struct tcp_pcb *newpcb, err_t err){	phase_expected(PHASE_EVENTS);	debug("<--- %s(arg 0x%pp, newpcb 0x%pp, err %d)/n",	      __FUNCTION__, arg, newpcb, err);	outlet_t *ol = (outlet_t *)arg;	assert(ol != 0);	assert(err == ERR_OK);	acc_pend_t *pend = get_free_pending(ol);	if (pend == 0)	{		tcp_abort(newpcb);		return ERR_ABRT;	}	pend->pcb = newpcb;	pend->ante = 0;	// The newpcb is being enqueued into	// Data may be received for the newpcb while	// it is still on the queue. Such data is handled by a *temporary* recevive	// callback accept_recv_cb.	tcp_arg(newpcb, pend);	tcp_recv(newpcb, accept_recv_cb);	tcp_err(newpcb, accept_error_cb);	return try_to_bake(ol, pend);}
开发者ID:EarlGray,项目名称:ling,代码行数:31,


示例7: lwiperf_tcp_close

/** Close an iperf tcp session */static voidlwiperf_tcp_close(lwiperf_state_tcp_t* conn, enum lwiperf_report_type report_type){  err_t err;  lwip_tcp_conn_report(conn, report_type);  lwiperf_list_remove(&conn->base);  if (conn->conn_pcb != NULL) {    tcp_arg(conn->conn_pcb, NULL);    tcp_poll(conn->conn_pcb, NULL, 0);    tcp_sent(conn->conn_pcb, NULL);    tcp_recv(conn->conn_pcb, NULL);    tcp_err(conn->conn_pcb, NULL);    err = tcp_close(conn->conn_pcb);    if (err != ERR_OK) {      /* don't want to wait for free memory here... */      tcp_abort(conn->conn_pcb);    }  } else {    /* no conn pcb, this is the server pcb */    err = tcp_close(conn->server_pcb);    LWIP_ASSERT("error", err != ERR_OK);  }  LWIPERF_FREE(lwiperf_state_tcp_t, conn);}
开发者ID:michas2,项目名称:l4re-snapshot,代码行数:26,


示例8: INT_PROTECT_INIT

void EthernetClient::stop() {	/* Stop frees any resources including any unread buffers */	err_t err;	INT_PROTECT_INIT(oldLevel);	/* protect the code from preemption of the ethernet interrupt servicing */	INT_PROTECT(oldLevel);	struct tcp_pcb * cpcb_copy = (tcp_pcb *) SYNC_FETCH_AND_NULL(&cs->cpcb);	struct pbuf * p_copy = (pbuf *) SYNC_FETCH_AND_NULL(&cs->p);	_connected = false;	cs->port = 0;	if (cpcb_copy) {		tcp_err(cpcb_copy, NULL);		if (p_copy) {			tcp_recved(cpcb_copy, p_copy->tot_len);			pbuf_free(p_copy);		}		err = tcp_close(cpcb_copy);		if (err != ERR_OK) {			/* Error closing, try again later in poll (every 2 sec) */			tcp_poll(cpcb_copy, do_poll, 4);		}	}	INT_UNPROTECT(oldLevel);}
开发者ID:energia,项目名称:tivac-core,代码行数:32,


示例9: ol_tcp_animate

void ol_tcp_animate(outlet_t *new_ol, struct tcp_pcb *pcb, struct pbuf *ante){	//	// lwIP tries hard to allocate a new PCB. If there is not enough memory it	// first kills TIME-WAIT connections and then active connections. The	// error_cb callback is used along the way. The callback may sent an exit	// signal to an outlet and the chain of exit signal may reach the current	// outlet. To avoid this the priority of all PCBs is set to TCP_PRIO_MAX+1.	//	tcp_setprio(pcb, TCP_PRIO_MAX +1);	tcp_arg(pcb, new_ol);	// callback arg	tcp_recv(pcb, recv_cb);	tcp_sent(pcb, sent_cb);	tcp_err(pcb, error_cb);	new_ol->tcp = pcb;	if (ante != 0)	// data receive while enqueued	{		uint16_t len = ante->tot_len;		if (len > new_ol->recv_bufsize)		{			debug("ol_tcp_animate: tot_len=%d, recv_bufsize=%d, truncating/n",				  ante->tot_len, new_ol->recv_bufsize);			len = new_ol->recv_bufsize;			}		pbuf_copy_partial(ante, new_ol->recv_buffer, len, 0);		new_ol->recv_buf_off = len;		pbuf_free(ante);	}}
开发者ID:MCRedJay,项目名称:ling,代码行数:32,


示例10: ftpd_dataaccept

static err_t ftpd_dataaccept(void *arg, struct tcp_pcb *pcb, err_t err){	struct ftpd_datastate *fsd = arg;	fsd->msgfs->datapcb = pcb;	fsd->connected = 1;	/* Tell TCP that we wish to be informed of incoming data by a call	   to the http_recv() function. */	tcp_recv(pcb, ftpd_datarecv);	/* Tell TCP that we wish be to informed of data that has been	   successfully sent by a call to the ftpd_sent() function. */	tcp_sent(pcb, ftpd_datasent);	tcp_err(pcb, ftpd_dataerr);	switch (fsd->msgfs->state) {	case FTPD_LIST:		send_next_directory(fsd, pcb, 0);		break;	case FTPD_NLST:		send_next_directory(fsd, pcb, 1);		break;	case FTPD_RETR:		send_file(fsd, pcb);		break;	default:		break;	}	return ERR_OK;}
开发者ID:skyformat99,项目名称:lwip-ftpd,代码行数:33,


示例11: ident_accept

/*-----------------------------------------------------------------------------------*/static err_tident_accept(void *arg, struct tcp_pcb *pcb, err_t err){  struct ident_state *hs;  /* Allocate memory for the structure that holds the state of the     connection. */  hs = mem_malloc(sizeof(struct ident_state));  if(hs == NULL) {    printf("ident_accept: Out of memory/n");    return ERR_MEM;  }    /* Initialize the structure. */  memset (hs, 0, sizeof (*hs));  if (sizeof (hs->remote) != sizeof (pcb->remote_ip))    die ("sizeof (hs.remote) != sizeof (pcb->remote_ip)");  memcpy (&hs->remote, &pcb->remote_ip, sizeof (hs->remote));  /* Tell TCP that this is the structure we wish to be passed for our     callbacks. */  tcp_arg(pcb, hs);  /* Tell TCP that we wish to be informed of incoming data by a call     to the ident_recv() function. */  tcp_recv(pcb, ident_recv);  tcp_err(pcb, conn_err);    tcp_poll(pcb, ident_poll, 10);  return ERR_OK;}
开发者ID:kingcope,项目名称:LikeOS,代码行数:34,


示例12: ard_tcp_abort

/** * Clean up and free the ttcp structure */static void ard_tcp_abort(struct ttcp* ttcp) {	INFO_TCP("Abort ttcb:%p tpcb:%p lpcb:%p/n", ttcp, ttcp->tpcb, ttcp->lpcb);	if (ttcp->tpcb) {		tcp_arg(ttcp->tpcb, NULL);		tcp_sent(ttcp->tpcb, NULL);		tcp_recv(ttcp->tpcb, NULL);		tcp_err(ttcp->tpcb, NULL);		tcp_abort(ttcp->tpcb);	}	if (ttcp->lpcb) {		tcp_arg(ttcp->lpcb, NULL);		tcp_accept(ttcp->lpcb, NULL);		tcp_abort(ttcp->lpcb);	}	if (ttcp->upcb) {		udp_disconnect(ttcp->upcb);		udp_remove(ttcp->upcb);	}	if (ttcp->payload)		free(ttcp->payload);	free(ttcp);}
开发者ID:4bcat,项目名称:Arduino,代码行数:30,


示例13: ard_tcp_destroy

/** * Clean up and free the ttcp structure */static void ard_tcp_destroy(struct ttcp* ttcp) {	err_t err = ERR_OK;	DUMP_TCP_STATE(ttcp);	if (getSock(ttcp)==-1)		WARN("ttcp already deallocated!/n");	if (ttcp->tpcb) {		tcp_arg(ttcp->tpcb, NULL);		tcp_sent(ttcp->tpcb, NULL);		tcp_recv(ttcp->tpcb, NULL);		tcp_err(ttcp->tpcb, NULL);		//TEMPORAQARY		//err = tcp_close(ttcp->tpcb);		INFO_TCP("Closing tpcb: state:0x%x err:%d/n", ttcp->tpcb->state, err);	}	if (ttcp->lpcb) {		tcp_arg(ttcp->lpcb, NULL);		tcp_accept(ttcp->lpcb, NULL);		err = tcp_close(ttcp->lpcb);		INFO_TCP("Closing lpcb: state:0x%x err:%d/n", ttcp->lpcb->state, err);	}	if (ttcp->upcb) {		udp_disconnect(ttcp->upcb);		udp_remove(ttcp->upcb);	}	if (ttcp->payload)		free(ttcp->payload);	free(ttcp);}
开发者ID:4bcat,项目名称:Arduino,代码行数:37,


示例14: accept_v2

static socket_error_t accept_v2(struct socket *listener, struct socket *sock, socket_api_handler_t handler) {    if (sock == NULL || sock->impl == NULL)        return SOCKET_ERROR_NULL_PTR;    switch (sock->family) {    case SOCKET_DGRAM:        return SOCKET_ERROR_UNIMPLEMENTED;    case SOCKET_STREAM:    {      struct tcp_pcb *tcp = (struct tcp_pcb *)sock->impl;      struct tcp_pcb *lpcb = (struct tcp_pcb *)listener->impl;      /* NOTE: tcp_accepted() is replaced with an empty statement in release,       * so we need a cast-to-void to remove the unused variable warning */      (void) lpcb;      tcp_accepted(lpcb);      tcp_arg(tcp, (void*) sock);      tcp_err(tcp, tcp_error_handler);      tcp_sent(tcp, irqTCPSent);      tcp_recv(tcp, irqTCPRecv);      break;    }    default:        return SOCKET_ERROR_BAD_FAMILY;    }    sock->handler = (void*)handler;    sock->rxBufChain = NULL;    return SOCKET_ERROR_NONE;}
开发者ID:Koenma413,项目名称:sal-stack-lwip,代码行数:27,


示例15: tcp_server_accept

//lwIP tcp_accept()的回调函数err_t tcp_server_accept(void *arg,struct tcp_pcb *newpcb,err_t err){	err_t ret_err;	struct tcp_server_struct *es;  	LWIP_UNUSED_ARG(arg);	LWIP_UNUSED_ARG(err);	tcp_setprio(newpcb,TCP_PRIO_MIN);//设置新创建的pcb优先级	es=(struct tcp_server_struct*)mem_malloc(sizeof(struct tcp_server_struct)); //分配内存 	if(es!=NULL) //内存分配成功	{		es->state=ES_TCPSERVER_ACCEPTED;  	//接收连接		es->pcb=newpcb;		es->p=NULL;				tcp_arg(newpcb,es);		tcp_recv(newpcb,tcp_server_recv);	//初始化tcp_recv()的回调函数		tcp_err(newpcb,tcp_server_error); 	//初始化tcp_err()回调函数		tcp_poll(newpcb,tcp_server_poll,1);	//初始化tcp_poll回调函数		tcp_sent(newpcb,tcp_server_sent);  	//初始化发送回调函数		  		tcp_server_flag|=1<<5;				//标记有客户端连上了		lwipdev.remoteip[0]=newpcb->remote_ip.addr&0xff; 		//IADDR4		lwipdev.remoteip[1]=(newpcb->remote_ip.addr>>8)&0xff;  	//IADDR3		lwipdev.remoteip[2]=(newpcb->remote_ip.addr>>16)&0xff; 	//IADDR2		lwipdev.remoteip[3]=(newpcb->remote_ip.addr>>24)&0xff; 	//IADDR1 		ret_err=ERR_OK;	}else ret_err=ERR_MEM;
开发者ID:FeatherHunter,项目名称:STM32F4,代码行数:28,


示例16: http_accept

/*-----------------------------------------------------------------------------------*/static err_thttp_accept(void *arg, struct tcp_pcb *pcb, err_t err){    struct http_state *hs;    /* Allocate memory for the structure that holds the state of the       connection. */    hs = mem_malloc(sizeof(struct http_state));    if (hs == NULL)    {        return ERR_MEM;    }    /* Initialize the structure. */    hs->file = NULL;    hs->left = 0;    /* Tell TCP that this is the structure we wish to be passed for our       callbacks. */    tcp_arg(pcb, hs);    /* Tell TCP that we wish to be informed of incoming data by a call       to the http_recv() function. */    tcp_recv(pcb, http_recv);    tcp_err(pcb, conn_err);    tcp_poll(pcb, http_poll, 10);    return ERR_OK;}
开发者ID:sun182,项目名称:therme,代码行数:32,


示例17: tcpecho_raw_accept

static err_ttcpecho_raw_accept(void *arg, struct tcp_pcb *newpcb, err_t err){  err_t ret_err;  struct tcpecho_raw_state *es;  LWIP_UNUSED_ARG(arg);  if ((err != ERR_OK) || (newpcb == NULL)) {    return ERR_VAL;  }  /* Unless this pcb should have NORMAL priority, set its priority now.     When running out of pcbs, low priority pcbs can be aborted to create     new pcbs of higher priority. */  tcp_setprio(newpcb, TCP_PRIO_MIN);  es = (struct tcpecho_raw_state *)mem_malloc(sizeof(struct tcpecho_raw_state));  if (es != NULL) {    es->state = ES_ACCEPTED;    es->pcb = newpcb;    es->retries = 0;    es->p = NULL;    /* pass newly allocated es to our callbacks */    tcp_arg(newpcb, es);    tcp_recv(newpcb, tcpecho_raw_recv);    tcp_err(newpcb, tcpecho_raw_error);    tcp_poll(newpcb, tcpecho_raw_poll, 0);    tcp_sent(newpcb, tcpecho_raw_sent);    ret_err = ERR_OK;  } else {    ret_err = ERR_MEM;  }  return ret_err;}
开发者ID:yarrick,项目名称:lwip-contrib,代码行数:34,


示例18: TCP_accept

/**  * @brief  This function is the implementation of tcp_accept LwIP callback  * @param  arg: not used  * @param  newpcb: pointer on tcp_pcb struct for the newly created tcp connection  * @param  err: not used   * @retval err_t: error status  */static err_t		TCP_accept(void *arg, struct tcp_pcb *newpcb, err_t err) {		err_t ret_err;		TCP *es;				LWIP_UNUSED_ARG(arg);		LWIP_UNUSED_ARG(err);		tcp_setprio(newpcb, TCP_PRIO_MIN);					/* set priority for the newly accepted tcp connection newpcb */		es = (TCP *)mem_malloc(sizeof(TCP));				/* allocate structure es to maintain tcp connection informations */		if (es != NULL) {			es->state = ES_ACCEPTED;			es->pcb = newpcb;			es->tx = NULL;			es->rx = NULL;			tcp_arg(newpcb, es);											/* pass newly allocated es structure as argument to newpcb */			tcp_recv(newpcb, TCP_recv);								/* initialize lwip tcp_recv callback function for newpcb  */ 			tcp_err(newpcb, TCP_error);								/* initialize lwip tcp_err callback function for newpcb  */			tcp_poll(newpcb, TCP_poll, 1);						/* initialize lwip tcp_poll callback function for newpcb */			es->io=((func*)arg)(NULL);								// prvi klic			if(es->io) {															// tole je lahko tut drugace				es->f=(func *)arg;				_thread_add(es->f,es->io,"user app.",0);				_thread_add(_tcp_flush,es,"tcp flush",0);			}						ret_err = ERR_OK;		} else {			ret_err = ERR_MEM;												/* return memory error */		}		return ret_err;  	}
开发者ID:yallawalla,项目名称:stm32,代码行数:39,


示例19: socks_tcp_connect

voidsocks_tcp_connect(struct socks_data *data){	struct tcp_pcb *pcb;	err_t ret;	bufferevent_disable(data->bev, EV_READ);	LWIP_DEBUGF(SOCKS_DEBUG, ("%s: %s:%d/n", __func__,				ipaddr_ntoa(&data->ipaddr), data->port));	pcb = tcp_new();	if (!pcb)		data->connect_failed(data);	pcb->flags |= TF_NODELAY;	if (data->keep_alive) {		pcb->so_options |= SOF_KEEPALIVE;		pcb->keep_intvl = data->keep_alive;		pcb->keep_idle = data->keep_alive;	}	ret = tcp_connect(pcb, &data->ipaddr, data->port, socks_tcp_connect_ok);	if (ret < 0) {		tcp_abort(pcb);		data->connect_failed(data);	} else {		data->pcb = pcb;		tcp_arg(pcb, data);		tcp_err(pcb, socks_tcp_connect_err);	}}
开发者ID:stxh,项目名称:tunsocks,代码行数:32,


示例20: net_tcp_err_cb

static void net_tcp_err_cb(void *arg, err_t err){    struct tls_netconn *conn = (struct tls_netconn *)arg;    struct tcp_pcb *pcb = conn->pcb.tcp;      u8 event = NET_EVENT_TCP_CONNECT_FAILED;    TLS_DBGPRT_INFO("tcp err = %d/n", err);    if (pcb) {        tcp_arg(pcb, NULL);        tcp_sent(pcb, NULL);        tcp_recv(pcb, NULL);        tcp_err(pcb, NULL);		if (!conn->client) {		    tcp_accept(pcb, NULL);		}		if(err == ERR_OK)		{	      tcp_close(pcb);		}				if(conn->state != NETCONN_STATE_NONE)		{           conn->state = NETCONN_STATE_NONE;           event = NET_EVENT_TCP_DISCONNECT;		}		net_send_event_to_hostif(conn, event);		if(conn->skd->errf != NULL)		{			conn->skd->errf(conn->skt_num, err);		}		conn->pcb.tcp = NULL;        net_free_socket(conn);    }}
开发者ID:sdhczw,项目名称:winnermicro,代码行数:35,


示例21: lwip_bind

int lwip_bind(int s, struct sockaddr *name, socklen_t namelen) {	sockfd_t	* fd;	struct ip_addr	ip;	int		port, rv = 0;	s = sock_for_fd(s);	if (s < 0) {		errno = EBADF;		return -1;	}	fd = fds + s;	// Make sure it's an internet address we understand.	if (namelen != sizeof(struct sockaddr_in)) {		errno = ENAMETOOLONG;		return -1;	}	// Get access	mutex_lock(fd->mutex);	// Copy it over	memcpy(&fd->name, name, namelen);	// Convert this to an lwIP-happy format	ip.addr = ((struct sockaddr_in *)name)->sin_addr.s_addr;	port = ((struct sockaddr_in *)name)->sin_port;	// Are we TCP or UDP?	switch (fd->type) {	case SOCK_STREAM:		fd->tcppcb = tcp_new();		tcp_arg(fd->tcppcb, (void *)s);		tcp_recv(fd->tcppcb, recv_tcp);		tcp_sent(fd->tcppcb, sent_tcp);		tcp_poll(fd->tcppcb, poll_tcp, 4);	// 4 == 4 TCP timer intervals		tcp_err(fd->tcppcb, err_tcp);		if (tcp_bind(fd->tcppcb, &ip, ntohs(port)) != ERR_OK) {			if (tcp_close(fd->tcppcb) != ERR_OK)				tcp_abort(fd->tcppcb);			fd->tcppcb = NULL;			errno = EINVAL;			rv = -1; goto out;		}		break;	case SOCK_DGRAM:		fd->udppcb = udp_new();		udp_recv(fd->udppcb, recv_udp, (void *)s);		udp_bind(fd->udppcb, &ip, ntohs(port));		break;	default:		assert( 0 );		errno = EINVAL;		rv = -1; goto out;	}out:	mutex_unlock(fd->mutex);	return rv;}
开发者ID:foreverlikeyou9999,项目名称:kos-ports,代码行数:60,


示例22: lwiperf_tcp_accept

/** This is called when a new client connects for an iperf tcp session */static err_tlwiperf_tcp_accept(void *arg, struct tcp_pcb *newpcb, err_t err){  lwiperf_state_tcp_t *s, *conn;  if ((err != ERR_OK)  || (newpcb == NULL) || (arg == NULL)) {    return ERR_VAL;  }  s = (lwiperf_state_tcp_t*)arg;  conn = (lwiperf_state_tcp_t*)LWIPERF_ALLOC(lwiperf_state_tcp_t);  if (conn == NULL) {    return ERR_MEM;  }  memset(conn, 0, sizeof(lwiperf_state_tcp_t));  conn->base.tcp = 1;  conn->base.server = 1;  conn->base.related_server_state = &s->base;  conn->server_pcb = s->server_pcb;  conn->conn_pcb = newpcb;  conn->time_started = sys_now();  conn->report_fn = s->report_fn;  conn->report_arg = s->report_arg;  /* setup the tcp rx connection */  tcp_arg(newpcb, conn);  tcp_recv(newpcb, lwiperf_tcp_recv);  tcp_poll(newpcb, lwiperf_tcp_poll, 2U);  tcp_err(conn->conn_pcb, lwiperf_tcp_err);  lwiperf_list_add(&conn->base);  return ERR_OK;}
开发者ID:michas2,项目名称:l4re-snapshot,代码行数:33,


示例23: net_accept_cb

static err_t net_accept_cb(void *arg, struct tcp_pcb *newpcb, err_t err) {  lnet_userdata *ud = (lnet_userdata*)arg;  if (!ud || ud->type != TYPE_TCP_SERVER || !ud->pcb) return ERR_ABRT;  if (ud->self_ref == LUA_NOREF || ud->server.cb_accept_ref == LUA_NOREF) return ERR_ABRT;  lua_State *L = lua_getstate();  lua_rawgeti(L, LUA_REGISTRYINDEX, ud->server.cb_accept_ref);  lnet_userdata *nud = net_create(L, TYPE_TCP_CLIENT);  lua_pushvalue(L, 2);  nud->self_ref = luaL_ref(L, LUA_REGISTRYINDEX);  nud->tcp_pcb = newpcb;  tcp_arg(nud->tcp_pcb, nud);  tcp_err(nud->tcp_pcb, net_err_cb);  tcp_recv(nud->tcp_pcb, net_tcp_recv_cb);  tcp_sent(nud->tcp_pcb, net_sent_cb);  nud->tcp_pcb->so_options |= SOF_KEEPALIVE;  nud->tcp_pcb->keep_idle = ud->server.timeout * 1000;  nud->tcp_pcb->keep_cnt = 1;  tcp_accepted(ud->tcp_pcb);  lua_call(L, 1, 0);  return net_connected_cb(nud, nud->tcp_pcb, ERR_OK);}
开发者ID:Dxploto,项目名称:nodemcu-firmware,代码行数:25,


示例24: http_accept

static err_t http_accept(void *arg, tcp_pcb *pcb, err_t err){  LWIP_UNUSED_ARG(arg);  LWIP_UNUSED_ARG(err);  tcp_setprio(pcb, TCP_PRIO_MIN);  //RepRapNetworkMessage("http_accept/n");  HttpState *hs = (HttpState*)mem_malloc(sizeof(HttpState));  if (hs == NULL)  {	  RepRapNetworkMessage("Out of memory!/n");	  return ERR_MEM;  }  /* Initialize the structure. */  hs->pcb = pcb;  hs->file = NULL;  hs->left = 0;  hs->retries = 0;  hs->sendingRs = NULL;  tcp_accepted(listening_pcb);	// tell TCP to accept further connections  tcp_arg(pcb, hs);				// tell TCP that this is the structure we wish to be passed for our callbacks  tcp_recv(pcb, http_recv);		// tell TCP that we wish to be informed of incoming data by a call to the http_recv() function  tcp_err(pcb, conn_err);  tcp_poll(pcb, http_poll, 4);  return ERR_OK;}
开发者ID:DannyGH,项目名称:RepRapFirmware,代码行数:30,


示例25: ttcp_destroy

/** * Clean up and free the ttcp structure */static voidttcp_destroy(struct ttcp* ttcp){        if (ttcp->tpcb) {                tcp_arg(ttcp->tpcb, NULL);                tcp_sent(ttcp->tpcb, NULL);                tcp_recv(ttcp->tpcb, NULL);                tcp_err(ttcp->tpcb, NULL);                tcp_close(ttcp->tpcb);        }        if (ttcp->lpcb) {                tcp_arg(ttcp->lpcb, NULL);                tcp_accept(ttcp->lpcb, NULL);                tcp_close(ttcp->lpcb);        }        if (ttcp->upcb) {                udp_disconnect(ttcp->upcb);                udp_remove(ttcp->upcb);        }        if (ttcp->payload)                free(ttcp->payload);        timer_cancel_timeout(ttcp->tid);        free(ttcp);}
开发者ID:ThucVD2704,项目名称:femto-usb-blink-example,代码行数:30,


示例26: mg_lwip_accept_cb

static err_t mg_lwip_accept_cb(void *arg, struct tcp_pcb *newtpcb, err_t err) {  struct mg_connection *lc = (struct mg_connection *) arg;  (void) err;  DBG(("%p conn %p from %s:%u", lc, newtpcb, ipaddr_ntoa(&newtpcb->remote_ip),       newtpcb->remote_port));  struct mg_connection *nc = mg_if_accept_new_conn(lc);  if (nc == NULL) {    tcp_abort(newtpcb);    return ERR_ABRT;  }  struct mg_lwip_conn_state *cs = (struct mg_lwip_conn_state *) nc->sock;  cs->pcb.tcp = newtpcb;  tcp_arg(newtpcb, nc);  tcp_err(newtpcb, mg_lwip_tcp_error_cb);  tcp_sent(newtpcb, mg_lwip_tcp_sent_cb);  tcp_recv(newtpcb, mg_lwip_tcp_recv_cb);#ifdef SSL_KRYPTON  if (lc->ssl_ctx != NULL) {    nc->ssl = SSL_new(lc->ssl_ctx);    if (nc->ssl == NULL || SSL_set_fd(nc->ssl, (intptr_t) nc) != 1) {      LOG(LL_ERROR, ("SSL error"));      tcp_close(newtpcb);    }  } else#endif  {    mg_lwip_accept_conn(nc, newtpcb);  }  return ERR_OK;}
开发者ID:MrZANE42,项目名称:smart.js,代码行数:30,


示例27: BRIDGE_UART_Accept

/** * Callback function called when Server (THIS) receives a valid connection from a client *  or a server connects to this client in CLIENT mode * * @param argument sent by lwIP * @param tcp connection descriptor * @param reception error flag * @return error type on callback to be processed by lwIP */static err_tBRIDGE_UART_Accept(void *arg, struct tcp_pcb *pcb, err_t err){  struct bridge_state *hs;    /* Allocate memory for the structure that holds the state of the connection */  hs = mem_malloc(sizeof(struct bridge_state));    if (hs == NULL)   {    return ERR_MEM;  }  /* Initialize the structure. */  hs->data = NULL;  hs->left = 0;  hs->retries = 0;  /*uart structure*/  p_uart_tx_state.tx_pcb = pcb;  p_uart_tx_state.p_bridge_state = hs;  /* Tell TCP that this is the structure we wish to be passed for our callbacks */  tcp_arg(pcb, hs);  /*called function when RX*/  tcp_recv(pcb, BRIDGE_UART_ETH_RX);  tcp_err(pcb, BRIDGE_UART_ETH_ERROR);  tcp_setprio(pcb,TCP_PRIO_MAX);    return ERR_OK;}
开发者ID:patriciobos,项目名称:TpFinal,代码行数:43,


示例28: iperfserver_accept

err_tiperfserver_accept(void *arg, struct tcp_pcb *newpcb, err_t err){  err_t ret_err;  struct iperfserver_state *es;  LWIP_UNUSED_ARG(arg);  LWIP_UNUSED_ARG(err);  /* commonly observed practive to call tcp_setprio(), why? */  tcp_setprio(newpcb, TCP_PRIO_MIN);  es = (struct iperfserver_state *)mem_malloc(sizeof(struct iperfserver_state));  if (es != NULL)  {    es->state = ES_ACCEPTED;    es->pcb = newpcb;    es->retries = 0;    es->p = NULL;    /* pass newly allocated es to our callbacks */    tcp_arg(newpcb, es);    tcp_recv(newpcb, iperfserver_recv);    tcp_err(newpcb, iperfserver_error);      ret_err = ERR_OK;  }  else  {    ret_err = ERR_MEM;  }  return ret_err;  }
开发者ID:MFDM,项目名称:SE2-SV1314,代码行数:32,


示例29: log_w

bool AsyncClient::connect(IPAddress ip, uint16_t port){    if (_pcb){        log_w("already connected, state %d", _pcb->state);        return false;    }    if(!_start_async_task()){        log_e("failed to start task");        return false;    }    ip_addr_t addr;    addr.type = IPADDR_TYPE_V4;    addr.u_addr.ip4.addr = ip;    tcp_pcb* pcb = tcp_new_ip_type(IPADDR_TYPE_V4);    if (!pcb){        log_e("pcb == NULL");        return false;    }    tcp_arg(pcb, this);    tcp_err(pcb, &_tcp_error);    if(_in_lwip_thread){        tcp_connect(pcb, &addr, port,(tcp_connected_fn)&_s_connected);    } else {        _tcp_connect(pcb, &addr, port,(tcp_connected_fn)&_s_connected);    }    return true;}
开发者ID:RitterRBC,项目名称:Arduino,代码行数:29,



注:本文中的tcp_err函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


C++ tcp_flag_word函数代码示例
C++ tcp_connect函数代码示例
万事OK自学网:51自学网_软件自学网_CAD自学网自学excel、自学PS、自学CAD、自学C语言、自学css3实例,是一个通过网络自主学习工作技能的自学平台,网友喜欢的软件自学网站。