ithewei 6 年之前
父节点
当前提交
d271aabaf4
共有 3 个文件被更改,包括 15 次插入10 次删除
  1. 7 5
      base/hplatform.h
  2. 5 0
      event/nmap.cpp
  3. 3 5
      http/HttpRequest.h

+ 7 - 5
base/hplatform.h

@@ -68,14 +68,16 @@
 #endif
 // __clang__
 
-#ifndef BUILD_STATIC_LIB
-#ifdef _MSC_VER
+#ifdef BUILD_STATIC_LIB
+#define EXPORT
+#elif defined(OS_WIN)
+#ifdef DLL_EXPORTS
 #define EXPORT  __declspec(dllexport)
-#elif defined(__GNUC__)
-#define EXPORT  __attribute__((visibility("default")))
 #else
-#define EXPORT
+#define EXPORT  __declspec(dllimport)
 #endif
+#elif defined(__GNUC__)
+#define EXPORT  __attribute__((visibility("default")))
 #else
 #define EXPORT
 #endif

+ 5 - 0
event/nmap.cpp

@@ -12,6 +12,10 @@ typedef struct recvfrom_udata_s {
     int     up_cnt;
 } recvfrom_udata_t;
 
+void on_idle(hidle_t* idle) {
+    hloop_stop(idle->loop);
+}
+
 void on_timer(htimer_t* timer) {
     hloop_stop(timer->loop);
 }
@@ -105,6 +109,7 @@ int nmap_discovery(Nmap* nmap) {
     }
 
     htimer_add(&loop, on_timer, MAX_RECVFROM_TIMEOUT, 1);
+    hidle_add(&loop, on_idle, 1);
 
     hloop_run(&loop);
     uint64_t end_hrtime = hloop_now_hrtime(&loop);

+ 3 - 5
http/HttpRequest.h

@@ -160,15 +160,13 @@ append:
         }
     }
 
-    void fill_content_lenght() {
-        if (body.size() != 0) {
-            headers["Content-Length"] = std::to_string(body.size());
-        }
+    void fill_content_length() {
+        headers["Content-Length"] = std::to_string(body.size());
     }
 
     void dump_headers(std::string& str) {
         fill_content_type();
-        fill_content_lenght();
+        fill_content_length();
         for (auto& header: headers) {
             // %s: %s\r\n
             str += header.first;