示例#1
0
文件: httpd.c 项目: cskarai/esp-link
//Callback called when the data on a socket has been successfully sent.
static void ICACHE_FLASH_ATTR httpdSentCb(void *arg) {
  debugConn(arg, "httpdSentCb");
  struct espconn* pCon = (struct espconn *)arg;
  HttpdConnData *conn = (HttpdConnData *)pCon->reverse;
  if (conn == NULL) return; // aborted connection

  char sendBuff[MAX_SENDBUFF_LEN];
  httpdSetOutputBuffer(conn, sendBuff, sizeof(sendBuff));

  if (conn->cgi == NULL) { //Marked for destruction?
    //os_printf("Closing 0x%p/0x%p->0x%p\n", arg, conn->conn, conn);
    espconn_disconnect(conn->conn); // we will get a disconnect callback
    return; //No need to call httpdFlush.
  }

  int 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) {
    DBG("%sERROR! Bad CGI code %d\n", connStr, r);
    conn->cgi = NULL; //mark for destruction.
  }
  httpdFlush(conn);
}
示例#2
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);
}
示例#3
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);
}