1
0
ithewei 4 жил өмнө
parent
commit
c0d18400b2
4 өөрчлөгдсөн 16 нэмэгдсэн , 26 устгасан
  1. 2 7
      README-CN.md
  2. 2 7
      README.md
  3. 6 6
      base/hdef.h
  4. 6 6
      base/hsocket.c

+ 2 - 7
README-CN.md

@@ -216,16 +216,11 @@ int main() {
 
 #### HTTP压测
 ```shell
-# webbench (linux only)
-make webbench
-bin/webbench -c 2 -t 10 http://127.0.0.1:8080/
-bin/webbench -k -c 2 -t 10 http://127.0.0.1:8080/
+# sudo apt install wrk
+wrk -c 100 -t 4 -d 10s http://127.0.0.1:8080/
 
 # sudo apt install apache2-utils
 ab -c 100 -n 100000 http://127.0.0.1:8080/
-
-# sudo apt install wrk
-wrk -c 100 -t 4 -d 10s http://127.0.0.1:8080/
 ```
 
 **libhv(port:8080) vs nginx(port:80)**

+ 2 - 7
README.md

@@ -214,16 +214,11 @@ int main() {
 
 #### http benchmark
 ```shell
-# webbench (linux only)
-make webbench
-bin/webbench -c 2 -t 10 http://127.0.0.1:8080/
-bin/webbench -k -c 2 -t 10 http://127.0.0.1:8080/
+# sudo apt install wrk
+wrk -c 100 -t 4 -d 10s http://127.0.0.1:8080/
 
 # sudo apt install apache2-utils
 ab -c 100 -n 100000 http://127.0.0.1:8080/
-
-# sudo apt install wrk
-wrk -c 100 -t 4 -d 10s http://127.0.0.1:8080/
 ```
 
 **libhv(port:8080) vs nginx(port:80)**

+ 6 - 6
base/hdef.h

@@ -103,13 +103,13 @@ ASCII:
 #endif
 
 // LD, LU, LLD, LLU for explicit conversion of integer
-#ifndef LD
-#define LD(v)   ((long)(v))
-#endif
+// #ifndef LD
+// #define LD(v)   ((long)(v))
+// #endif
 
-#ifndef LU
-#define LU(v)   ((unsigned long)(v))
-#endif
+// #ifndef LU
+// #define LU(v)   ((unsigned long)(v))
+// #endif
 
 #ifndef LLD
 #define LLD(v)  ((long long)(v))

+ 6 - 6
base/hsocket.c

@@ -75,10 +75,10 @@ const char* sockaddr_ip(sockaddr_u* addr, char *ip, int len) {
 uint16_t sockaddr_port(sockaddr_u* addr) {
     uint16_t port = 0;
     if (addr->sa.sa_family == AF_INET) {
-        port = htons(addr->sin.sin_port);
+        port = ntohs(addr->sin.sin_port);
     }
     else if (addr->sa.sa_family == AF_INET6) {
-        port = htons(addr->sin6.sin6_port);
+        port = ntohs(addr->sin6.sin6_port);
     }
     return port;
 }
@@ -94,10 +94,10 @@ int sockaddr_set_ip(sockaddr_u* addr, const char* host) {
 
 void sockaddr_set_port(sockaddr_u* addr, int port) {
     if (addr->sa.sa_family == AF_INET) {
-        addr->sin.sin_port = ntohs(port);
+        addr->sin.sin_port = htons(port);
     }
     else if (addr->sa.sa_family == AF_INET6) {
-        addr->sin6.sin6_port = ntohs(port);
+        addr->sin6.sin6_port = htons(port);
     }
 }
 
@@ -129,12 +129,12 @@ const char* sockaddr_str(sockaddr_u* addr, char* buf, int len) {
     uint16_t port = 0;
     if (addr->sa.sa_family == AF_INET) {
         inet_ntop(AF_INET, &addr->sin.sin_addr, ip, len);
-        port = htons(addr->sin.sin_port);
+        port = ntohs(addr->sin.sin_port);
         snprintf(buf, len, "%s:%d", ip, port);
     }
     else if (addr->sa.sa_family == AF_INET6) {
         inet_ntop(AF_INET6, &addr->sin6.sin6_addr, ip, len);
-        port = htons(addr->sin6.sin6_port);
+        port = ntohs(addr->sin6.sin6_port);
         snprintf(buf, len, "[%s]:%d", ip, port);
     }
 #ifdef ENABLE_UDS