⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 httpd.lst

📁 STC51系列的源码
💻 LST
📖 第 1 页 / 共 2 页
字号:
 174   3              }
 175   2          
 176   2            
 177   2              if(hs->state != HTTP_FUNC) 
C51 COMPILER V8.02   HTTPD                                                                 10/28/2008 15:31:40 PAGE 4   

 178   2              {   /* Check if the client (remote end) has acknowledged any data that
 179   3                      we've previously sent. If so, we move the file pointer further
 180   3                      into the file and send back more data. If we are out of data to
 181   3                      send, we close the connection. */
 182   3                  if(uip_acked()) 
 183   3                  {
 184   4                          if(hs->count >= uip_conn->len) 
 185   4                          {
 186   5                              hs->count -= uip_conn->len;
 187   5                              hs->dataptr += uip_conn->len;
 188   5                          } 
 189   4                          else 
 190   4                          {
 191   5                              hs->count = 0;
 192   5                          }
 193   4                
 194   4                          if(hs->count == 0) 
 195   4                          {
 196   5                              if(hs->script != NULL) 
 197   5                              {   next_scriptline();
 198   6                                  next_scriptstate();
 199   6                              } 
 200   5                              else 
 201   5                              {   uip_close();
 202   6                              }
 203   5                          }
 204   4                  }         
 205   3              } 
 206   2              else 
 207   2              {
 208   3                  /* Call the CGI function. */
 209   3                  switch(hs->script[2] - ISO_a)
 210   3                  {
 211   4                  case 0x0:
 212   4                       status=print_stats(uip_acked());
 213   4                       break;
 214   4                  case 0x1:
 215   4                       status=file_stats(uip_acked());
 216   4                       break;
 217   4                  case 0x2:
 218   4                       status=tcp_stats(uip_acked());
 219   4                       break;
 220   4                  default:
 221   4                       break;
 222   4                  }
 223   3                  if(status)
 224   3                  {   PRINT("send file 4.\r\n ");
 225   4                      next_scriptline();
 226   4                          next_scriptstate();
 227   4                  }
 228   3      
 229   3                  //if((*cgitab[hs->script[2] - ISO_a])(uip_acked())) 
 230   3                  //{
 231   3                      //    /* If the function returns non-zero, we jump to the next line
 232   3                  //    in the script. */
 233   3                      //    next_scriptline();
 234   3                      //    next_scriptstate();
 235   3                  //}
 236   3              }
 237   2          
 238   2              if(hs->state != HTTP_FUNC && !uip_poll()) 
 239   2              {
C51 COMPILER V8.02   HTTPD                                                                 10/28/2008 15:31:40 PAGE 5   

 240   3                  /* Send a piece of data, but not more than the MSS of the
 241   3                      connection. */
 242   3                  uip_send(hs->dataptr, hs->count);
 243   3              }
 244   2          
 245   2              /* Finally, return to uIP. Our outgoing packet will soon be on its
 246   2               way... */
 247   2              return;
 248   2          
 249   2          default:
 250   2              /* Should never happen. */
 251   2              uip_abort();
 252   2              break;
 253   2          }  
 254   1      }
 255          /*-----------------------------------------------------------------------------------*/
 256          /* next_scriptline():
 257           *
 258           * Reads the script until it finds a newline. */
 259          static void
 260          next_scriptline(void)
 261          {
 262   1        /* Loop until we find a newline character. */
 263   1        do {
 264   2          ++(hs->script);
 265   2        } while(hs->script[0] != ISO_nl);
 266   1      
 267   1        /* Eat up the newline as well. */
 268   1        ++(hs->script);
 269   1      }
 270          /*-----------------------------------------------------------------------------------*/
 271          /* next_sciptstate:
 272           *
 273           * Reads one line of script and decides what to do next.
 274           */
 275          static void next_scriptstate(void)
 276          {
 277   1        struct fs_file   fsfile;
 278   1        u8_t   i;
 279   1      
 280   1       again:
 281   1        switch(hs->script[0]) {
 282   2        case ISO_t:
 283   2          /* Send a text string. */
 284   2          hs->state = HTTP_TEXT;
 285   2          hs->dataptr = &hs->script[2];
 286   2      
 287   2          /* Calculate length of string. */
 288   2          for(i = 0; hs->dataptr[i] != ISO_nl; ++i);
 289   2          hs->count = i;    
 290   2          break;
 291   2        case ISO_c:
 292   2          /* Call a function. */
 293   2          hs->state = HTTP_FUNC;
 294   2          hs->dataptr = NULL;
 295   2          hs->count = 0;
 296   2          //(*cgitab[hs->script[2] - ISO_a])(0);
 297   2          /* Call the CGI function. */
 298   2          switch(hs->script[2] - ISO_a)
 299   2          {
 300   3          case 0x0:
 301   3               print_stats(uip_acked());
C51 COMPILER V8.02   HTTPD                                                                 10/28/2008 15:31:40 PAGE 6   

 302   3               break;
 303   3          case 0x1:
 304   3               file_stats(uip_acked());
 305   3               break;
 306   3          case 0x2:
 307   3               tcp_stats(uip_acked());
 308   3               break;
 309   3          default:
 310   3               break;
 311   3          }
 312   2          break;
 313   2        case ISO_i:   
 314   2          /* Include a file. */
 315   2          hs->state = HTTP_FILE;
 316   2          if(!fs_open(&hs->script[2], &fsfile)) {
 317   3            uip_abort();
 318   3          }
 319   2          hs->dataptr = fsfile.dat;
 320   2          hs->count = fsfile.len;
 321   2          break;
 322   2        case ISO_hash:
 323   2          /* Comment line. */
 324   2          next_scriptline();
 325   2          goto again;
 326   2          break;
 327   2        case ISO_period:
 328   2          /* End of script. */
 329   2          hs->state = HTTP_END;
 330   2          uip_close();
 331   2          break;
 332   2        default:
 333   2          uip_abort();
 334   2          break;
 335   2        }
 336   1      }
 337          /*-----------------------------------------------------------------------------------*/
 338          /** @} */
 339          /** @} */


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =   1408    ----
   CONSTANT SIZE    =     60    ----
   XDATA SIZE       =      3      11
   PDATA SIZE       =   ----    ----
   DATA SIZE        =   ----    ----
   IDATA SIZE       =   ----    ----
   BIT SIZE         =   ----    ----
END OF MODULE INFORMATION.


C51 COMPILATION COMPLETE.  0 WARNING(S),  0 ERROR(S)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -