hewei.it 4 năm trước cách đây
mục cha
commit
3a6228a912
3 tập tin đã thay đổi với 11 bổ sung10 xóa
  1. 1 1
      evpp/EventLoop.h
  2. 9 8
      examples/httpd/handler.h
  3. 1 1
      protocol/dns.h

+ 1 - 1
evpp/EventLoop.h

@@ -119,7 +119,7 @@ public:
     }
 
     long tid() {
-        if (loop_ == NULL) hv_gettid();
+        if (loop_ == NULL) return hv_gettid();
         return hloop_tid(loop_);
     }
 

+ 9 - 8
examples/httpd/handler.h

@@ -2,6 +2,7 @@
 #define HV_HTTPD_HANDLER_H
 
 #include "HttpMessage.h"
+#include "htime.h"
 
 class Handler {
 public:
@@ -38,17 +39,17 @@ public:
     }
 
     static int sleep(HttpRequest* req, HttpResponse* resp) {
-        time_t start_time = time(NULL);
+        unsigned long long start_ms = gettimeofday_ms();
         std::string strTime = req->GetParam("t");
         if (!strTime.empty()) {
-            int sec = atoi(strTime.c_str());
-            if (sec > 0) {
-                hv_delay(sec*1000);
+            int ms = atoi(strTime.c_str());
+            if (ms > 0) {
+                hv_delay(ms);
             }
         }
-        time_t end_time = time(NULL);
-        resp->Set("start_time", start_time);
-        resp->Set("end_time", end_time);
+        unsigned long long end_ms = gettimeofday_ms();
+        resp->Set("start_ms", start_ms);
+        resp->Set("end_ms", end_ms);
         response_status(resp, 0, "OK");
         return 200;
     }
@@ -95,7 +96,7 @@ public:
         resp->form = req->form;
         resp->form["int"] = 123;
         resp->form["float"] = 3.14;
-        resp->form["float"] = "hello";
+        resp->form["string"] = "hello";
         // resp->form["file"] = FormData(NULL, "test.jpg");
         // resp->UploadFormFile("file", "test.jpg");
         return 200;

+ 1 - 1
protocol/dns.h

@@ -95,7 +95,7 @@ HV_EXPORT int dns_unpack(char* buf, int len, dns_t* dns);
 HV_EXPORT void dns_free(dns_t* dns);
 
 // dns_pack -> sendto -> recvfrom -> dns_unpack
-HV_EXPORT int dns_query(dns_t* query, dns_t* response, const char* nameserver DEFAULT("127.0.1,1"));
+HV_EXPORT int dns_query(dns_t* query, dns_t* response, const char* nameserver DEFAULT("127.0.1.1"));
 
 // domain -> dns_t query; -> dns_query -> dns_t response; -> addrs
 HV_EXPORT int nslookup(const char* domain, uint32_t* addrs, int naddr, const char* nameserver DEFAULT("127.0.1.1"));