Пример #1
0
static void ICACHE_FLASH_ATTR httpdDisconCb(void *arg) {
#if 0
	//Stupid esp sdk passes through wrong arg here, namely the one of the *listening* socket.
	//If it ever gets fixed, be sure to update the code in this snippet; it's probably out-of-date.
	HttpdConnData *conn=httpdFindConnData(arg);
	os_printf("Disconnected, conn=%p\n", conn);
	if (conn==NULL) return;
	conn->conn=NULL;
	if (conn->cgi!=NULL) conn->cgi(conn); //flush cgi data
#endif
	//Just look at all the sockets and kill the slot if needed.
	int i;
	for (i=0; i<MAX_CONN; i++) {
		if (connData[i].conn!=NULL) {
			//Why the >=ESPCONN_CLOSE and not ==? Well, seems the stack sometimes de-allocates
			//espconns under our noses, especially when connections are interrupted. The memory
			//is then used for something else, and we can use that to capture *most* of the
			//disconnect cases.
			if (connData[i].conn->state==ESPCONN_NONE || connData[i].conn->state>=ESPCONN_CLOSE) {
				connData[i].conn=NULL;
				if (connData[i].cgi!=NULL) connData[i].cgi(&connData[i]); //flush cgi data
				httpdRetireConn(&connData[i]);
			}
		}
	}
}
//Callback called when the data on a socket has been successfully
//sent.
static void ICACHE_FLASH_ATTR httpdSentCb(void *arg) {
	int r;
	HttpdConnData *conn=httpdFindConnData(arg);
	char sendBuff[MAX_SENDBUFF_LEN];

//	os_printf("Sent callback on conn %p\n", conn);
	if (conn==NULL) return;
	conn->priv->sendBuff=sendBuff;
	conn->priv->sendBuffLen=0;

	if (conn->cgi==NULL) { //Marked for destruction?
		os_printf("Conn %p is done. Closing.\n", conn->conn);
		espconn_disconnect(conn->conn);
		httpdRetireConn(conn);
		return; //No need to call xmitSendBuff.
	}

	r=conn->cgi(conn); //Execute cgi fn.
	if (r==HTTPD_CGI_DONE) {
		conn->cgi=NULL; //mark for destruction.
	}
	if (r==HTTPD_CGI_NOTFOUND || r==HTTPD_CGI_AUTHENTICATED) {
		os_printf("ERROR! CGI fn returns code %d after sending data! Bad CGI!\n", r);
		conn->cgi=NULL; //mark for destruction.
	}
	xmitSendBuff(conn);
}
Пример #3
0
/************************************************
*	name:			httpdDisconCb
*	parameters:		ptArgument - argument
*	return value:	none
*	purpose:		callback for disconnect to check all sockets and kill if needed
************************************************/
static void ICACHE_FLASH_ATTR	httpdDisconCb(void *	ptArgument)
{
	/*	initialization	*/
	int 	iIndex = 0;

	for (iIndex = 0; HTTPD_MAX_CONNECTIONS > iIndex; iIndex++)
	{
		if (NULL != g_ptConnectionData[iIndex].ptEspConnection)
		{
			/* Why the >=ESPCONN_CLOSE and not ==? Well, seems the stack sometimes de-allocates
			espconns under our noses, especially when connections are interrupted. The memory
			is then used for something else, and we can use that to capture *most* of the
			disconnect cases. */
			if ((ESPCONN_NONE == g_ptConnectionData[iIndex].ptEspConnection->state) || (ESPCONN_CLOSE <= g_ptConnectionData[iIndex].ptEspConnection->state))
			{
				g_ptConnectionData[iIndex].ptEspConnection = NULL;
				if (NULL != g_ptConnectionData[iIndex].pfnCgi)
				{
					/* flush cgi data */
					g_ptConnectionData[iIndex].pfnCgi(&g_ptConnectionData[iIndex]);
				}
				httpdRetireConn(&g_ptConnectionData[iIndex]);
			}
		}
	}
}
Пример #4
0
static void ICACHE_FLASH_ATTR httpdDisconCb(void *arg) {
  debugConn(arg, "httpdDisconCb");
  struct espconn* pCon = (struct espconn *)arg;
  HttpdConnData *conn = (HttpdConnData *)pCon->reverse;
  if (conn == NULL) return; // aborted connection
  httpdRetireConn(conn);
}
Пример #5
0
static void ICACHE_FLASH_ATTR httpdDisconCb(void *arg) {
	debugConn(arg, "httpdDisconCb");
	HttpdConnData *conn = httpdFindConnData(arg);
	if (conn == NULL) return;
	if (conn->cgi != NULL) conn->cgi(conn); // free cgi data
	httpdRetireConn(conn);
}
Пример #6
0
// Callback indicating a failure in the connection. "Recon" is probably intended in the sense
// of "you need to reconnect". Sigh... Note that there is no DisconCb after ReconCb
static void ICACHE_FLASH_ATTR httpdReconCb(void *arg, sint8 err) {
  debugConn(arg, "httpdReconCb");
  struct espconn* pCon = (struct espconn *)arg;
  HttpdConnData *conn = (HttpdConnData *)pCon->reverse;
  if (conn == NULL) return; // aborted connection
  DBG("%s***** reset, err=%d\n", connStr, err);
  httpdRetireConn(conn);
}
Пример #7
0
// Callback indicating a failure in the connection. "Recon" is probably intended in the sense
// of "you need to reconnect". Sigh...
static void ICACHE_FLASH_ATTR httpdReconCb(void *arg, sint8 err) {
	debugConn(arg, "httpdReconCb");
	HttpdConnData *conn = httpdFindConnData(arg);
	os_printf("%s reset, err=%d\n", connStr, err);
	if (conn == NULL) return;
	conn->conn = NULL; // don't tr to send anything, the SDK crashes...
	if (conn->cgi != NULL) conn->cgi(conn); // free cgi data
	httpdRetireConn(conn);
}
static void ICACHE_FLASH_ATTR httpdSentCb(void *arg) {
	int r;
	HttpdConnData *conn=httpdFindConnData(arg);
//	os_printf("Sent callback on conn %p\n", conn);
	if (conn==NULL) return;
	if (conn->cgi==NULL) { //Marked for destruction?
		os_printf("Conn %p is done. Closing.\n", conn->conn);
		espconn_disconnect(conn->conn);
		httpdRetireConn(conn);
		return;
	}

	r=conn->cgi(conn); //Execute cgi fn.
	if (r==HTTPD_CGI_DONE) {
		conn->cgi=NULL; //mark for destruction.
	}
}
Пример #9
0
/************************************************
*	name:			httpdSentCb
*	parameters:		pArgument - connection data
*	return value:	none
*	purpose:		callback when data on socket has been successfully sent
************************************************/
static void ICACHE_FLASH_ATTR	httpdSentCb(void *	pArgument)
{
	/* initialization */
	int 				cgiResult 									= HTTPD_CGI_FAILED;
	char 				pbSendBuffer[HTTPD_MAX_SEND_BUFFER_LENGTH]	= { 0 };
	HttpdConnection *	ptConnection 								= NULL;

	ptConnection = httpdFindConnData(pArgument);

	if (NULL == ptConnection)
	{
		goto lblCleanup;
	}

	ptConnection->ptPrivate->pbSendBuffer = pbSendBuffer;
	ptConnection->ptPrivate->cbSendBufferLength = 0;

	if (NULL == ptConnection->pfnCgi)
	{
		/* marked for destruction - no need to call xmitSendBuff */

#ifdef HTTPD_DEBUG
		os_printf("httpdSendCb: connection %p is done and closing.\n", ptConnection->ptEspConnection);
#endif

		espconn_disconnect(ptConnection->ptEspConnection);
		httpdRetireConn(ptConnection);
		goto lblCleanup;
	}

	/* Execute cgi function */
	cgiResult = ptConnection->pfnCgi(ptConnection);
	if (HTTPD_CGI_DONE == cgiResult)
	{
		/* mark for destruction */
		ptConnection->pfnCgi = NULL;
	}

	xmitSendBuff(ptConnection);

lblCleanup:
	return;
}
static void ICACHE_FLASH_ATTR httpdDisconCb(void *arg) {
	//The esp sdk passes through wrong arg here, namely the one of the *listening* socket.
	//That is why we can't use (HttpdConnData)arg->sock here.
	//Just look at all the sockets and kill the slot if needed.
	int i;
	for (i=0; i<MAX_CONN; i++) {
		if (connData[i].conn!=NULL) {
			//Why the >=ESPCONN_CLOSE and not ==? Well, seems the stack sometimes de-allocates
			//espconns under our noses, especially when connections are interrupted. The memory
			//is then used for something else, and we can use that to capture *most* of the
			//disconnect cases.
			if (connData[i].conn->state==ESPCONN_NONE || connData[i].conn->state>=ESPCONN_CLOSE) {
				connData[i].conn=NULL;
				if (connData[i].cgi!=NULL) connData[i].cgi(&connData[i]); //flush cgi data
				httpdRetireConn(&connData[i]);
			}
		}
	}
}
static void ICACHE_FLASH_ATTR httpdDisconCb(void *arg) {
#if 0
	//Stupid esp sdk passes through wrong arg here, namely the one of the *listening* socket.
	//If it ever gets fixed, be sure to update the code in this snippet; it's probably out-of-date.
	HttpdConnData *conn=httpdFindConnData(arg);
	os_printf("Disconnected, conn=%p\n", conn);
	if (conn==NULL) return;
	conn->conn=NULL;
	if (conn->cgi!=NULL) conn->cgi(conn); //flush cgi data
#endif
	//Just look at all the sockets and kill the slot if needed.
	int i;
	for (i=0; i<MAX_CONN; i++) {
		if (connData[i].conn!=NULL) {
			if (connData[i].conn->state==ESPCONN_NONE || connData[i].conn->state==ESPCONN_CLOSE) {
				connData[i].conn=NULL;
				if (connData[i].cgi!=NULL) connData[i].cgi(&connData[i]); //flush cgi data
				httpdRetireConn(&connData[i]);
			}
		}
	}
}
Пример #12
0
//Callback called when the data on a socket has been successfully
//sent.
static void ICACHE_FLASH_ATTR httpdSentCb(void *arg) {
	int r;
	HttpdConnData *conn=httpdFindConnData(arg);
	char sendBuff[MAX_SENDBUFF_LEN];
//	//INFO("Sent callback on conn %p\n", conn);
	if (conn==NULL) return;
	conn->priv->sendBuff=sendBuff;
	conn->priv->sendBuffLen=0;

	if (conn->cgi==NULL) { //Marked for destruction?
		//INFO("Conn %p is done. Closing.\n", conn->conn);
		espconn_disconnect(conn->conn);
		httpdRetireConn(conn);
		return; //No need to call xmitSendBuff.
	}

	r=conn->cgi(conn); //Execute cgi fn.
	if (r==HTTPD_CGI_DONE) {
		conn->cgi=NULL; //mark for destruction.
	}
	xmitSendBuff(conn);
}