コード例 #1
0
ファイル: webconfig.c プロジェクト: landylai/wi
/****************************************************************
Function    :   GAgent_DoTcpWebConfig
Description :   creat web config server.
return      :   NULL
Add by Alex.lin     --2015-04-25.
****************************************************************/
void GAgent_DoTcpWebConfig( pgcontext pgc )
{
    uint16 GAgentStatus=0,i=0;
    int32 newfd;
    struct sockaddr_t addr;
    int32 addrLen= sizeof(addr);
    GAgentStatus = pgc->rtinfo.GAgentStatus;

    if( (GAgentStatus&WIFI_MODE_AP)!= WIFI_MODE_AP )
    {
        if( pgc->ls.tcpWebConfigFd>0 )
        {
            close( pgc->ls.tcpWebConfigFd );
            pgc->ls.tcpWebConfigFd = INVALID_SOCKET;
        }
        return ;
    }

    if( pgc->ls.tcpWebConfigFd <= 0 )
    {
        GAgent_Printf( GAGENT_DEBUG,"Creat Tcp Web Server." );
        pgc->ls.tcpWebConfigFd = GAgent_CreateWebConfigServer( 80 );   
    }

    if(FD_ISSET(pgc->ls.tcpWebConfigFd, &(pgc->rtinfo.readfd)))
    {
        /* if nonblock, can be done in accept progress */
        newfd = Socket_accept(pgc->ls.tcpWebConfigFd, &addr, &addrLen);
        if(newfd > 0)
        {
            Lan_AddTcpNewClient(pgc, newfd, &addr);
        }
    }

    for(i = 0;i < LAN_TCPCLIENT_MAX; i++)
    {
        int32 fd=0;
        fd = pgc->ls.tcpClient[i].fd;
        if(fd <= 0)
            continue;
        if(FD_ISSET(fd, &(pgc->rtinfo.readfd)))
        {
            Lan_setClientTimeOut(pgc, i);
            handleWebConfig( pgc,fd);
            close(fd);
            fd = INVALID_SOCKET;
            pgc->ls.tcpClient[i].fd=INVALID_SOCKET;
        }
    }
}
コード例 #2
0
ファイル: webconfig.c プロジェクト: joeysun/Gizwits-GAgent
/****************************************************************
Function    :   GAgent_DoTcpWebConfig
Description :   creat web config server.
return      :   NULL
Add by Alex.lin     --2015-04-25.
****************************************************************/
void GAgent_DoTcpWebConfig( pgcontext pgc )
{
    uint16 GAgentStatus=0;
    int32 newfd = 0;
    struct sockaddr_t addr;
    int32 addrLen= sizeof(addr);
    GAgentStatus = pgc->rtinfo.GAgentStatus;

    if( (GAgentStatus&WIFI_MODE_AP)!= WIFI_MODE_AP )
    {
        if( pgc->ls.tcpWebConfigFd>0 )
        {
            close( pgc->ls.tcpWebConfigFd );
            pgc->ls.tcpWebConfigFd = INVALID_SOCKET;
        }
        return ;
    }
    if( (GAgentStatus&WIFI_MODE_ONBOARDING)!= WIFI_MODE_ONBOARDING )
        return ;
    
    if( pgc->ls.tcpWebConfigFd <= 0 )
    {
        GAgent_Printf( GAGENT_DEBUG,"Creat Tcp Web Server." );
        pgc->ls.tcpWebConfigFd = GAgent_CreateWebConfigServer( 80 );
    }
    if( pgc->ls.tcpWebConfigFd<0 )
        return ;
    if( !FD_ISSET(pgc->ls.tcpWebConfigFd, &(pgc->rtinfo.readfd)) )
        return ;
        
    newfd = Socket_accept(pgc->ls.tcpWebConfigFd, &addr, (socklen_t *)&addrLen);
    if(newfd < 0)
        return ;
    handleWebConfig( pgc,newfd);
    close(newfd);
    newfd = INVALID_SOCKET;
}