Explorar el Código

完善mangoose的bug

liyuezong hace 2 años
padre
commit
d031dc8a6a
Se han modificado 4 ficheros con 15 adiciones y 26 borrados
  1. 8 16
      pro/mongoose/mongoose.c
  2. 0 10
      pro/mongoose/mongoose.h
  3. 3 0
      pro/src/common.h
  4. 4 0
      pro/src/websocket_handle.c

+ 8 - 16
pro/mongoose/mongoose.c

@@ -2270,7 +2270,10 @@ void mg_http_reply(struct mg_connection *c, int code, const char *headers,
                    const char *fmt, ...) {
   va_list ap;
   size_t len;
-  
+  if (c==NULL)
+  {
+    return;
+  }
 // mg_printf(c, "HTTP/1.1 %d %s\r\n%sContent-Length:            \r\n\r\n", code,
  //           mg_http_status_code_str(code), headers == NULL ? "" : headers);
 mg_printf(c, "HTTP/1.1 %d %s\r\n"
@@ -2282,15 +2285,12 @@ mg_printf(c, "HTTP/1.1 %d %s\r\n"
   "X-Frame-0ptions:: SAMEORIGIN\n"
   "X-Xss-Protection: 1: mode=block\n"
   "Accept-Ranges: bytes\n"
-  "Vary: Accept-Encoding\n"
-  "Access-Control-Allow-Origin: *\n"
-  "Access-Control-Allow-Methods: *\n"
-  "Access-Control-Allow-Headers: *\n\n"
-  "%s\n", code, mg_http_status_code_str(code),strlen(fmt), fmt == NULL ? "" : fmt);
+  "Vary: Accept-Encoding\n\n"
+  "%s\n", code, mg_http_status_code_str(code),strlen(fmt == NULL ? "" : fmt), fmt == NULL ? "" : fmt);
 
   len = c->send.len;
-  va_start(ap, fmt);
-  mg_vxprintf(mg_pfn_iobuf, &c->send, fmt, &ap);
+  va_start(ap, fmt == NULL ? "" : fmt);
+  mg_vxprintf(mg_pfn_iobuf, &c->send, fmt == NULL ? "" : fmt, &ap);
   va_end(ap);
   /*if (c->send.len > 16) {
     size_t n = mg_snprintf((char *) &c->send.buf[len - 15], 11, "%-10lu",
@@ -4461,14 +4461,6 @@ void mg_mgr_free(struct mg_mgr *mgr) {
 }
 
 bool mg_mgr_init(struct mg_mgr *mgr) {
-      // 初始化互斥锁  
-
-  #if MG_ARCH == MG_ARCH_UNIX
-  if (pthread_mutex_init(&WSlock, NULL) != 0) {  
-        return false;  
-  }  
-  #endif
-
   memset(mgr, 0, sizeof(*mgr));
 #if MG_ENABLE_EPOLL
   if ((mgr->epoll_fd = epoll_create1(EPOLL_CLOEXEC)) < 0)

+ 0 - 10
pro/mongoose/mongoose.h

@@ -2932,16 +2932,6 @@ struct mg_tcpip_driver_tm4c_data {
 
 
 
-#if MG_ARCH == MG_ARCH_UNIX
-
-#include "pthread.h"
-pthread_mutex_t WSlock; 
-
-#endif
-
-
-
-
 #endif  // MONGOOSE_H
 
 

+ 3 - 0
pro/src/common.h

@@ -826,4 +826,7 @@ int days_in_month(int year, int month);
 // 函数:增加一天到日期  
 void add_day_to_date(char *date_str, int *year, int *month, int *day);
 
+pthread_mutex_t WSlock; 
+pthread_mutex_t Httplock; 
+
 #endif

+ 4 - 0
pro/src/websocket_handle.c

@@ -117,6 +117,10 @@ void* websocket_thread(void* arg)
 
 int websocket_init(void) 
 {
+        // ³õʼ»¯»¥³âËø  
+  if (pthread_mutex_init(&WSlock, NULL) != 0) {  
+        return -1;  
+  }  
     ws_handle_t *wh=&wsHandle;
     
     memset(wh, 0, sizeof(ws_handle_t));