1
0
ithewei 5 жил өмнө
parent
commit
249ccbdc12
4 өөрчлөгдсөн 34 нэмэгдсэн , 7 устгасан
  1. 28 6
      README.md
  2. 1 1
      base/hthread.h
  3. 1 0
      configure
  4. 4 0
      hconfig.h

+ 28 - 6
README.md

@@ -32,29 +32,51 @@ but simpler apis and richer protocols.
 
 ## Getting Started
 
-### http server
-see examples/httpd.cpp
+### HTTP
+#### http server
+see examples/httpd/httpd.cpp
 ```c++
 #include "HttpServer.h"
 
-int http_api_hello(HttpRequest* req, HttpResponse* res) {
-    res->body = "hello";
+int http_api_echo(HttpRequest* req, HttpResponse* res) {
+    res->body = req->body;
     return 0;
 }
 
 int main() {
     HttpService service;
     service.base_url = "/v1/api";
-    service.AddApi("/hello", HTTP_GET, http_api_hello);
+    service.AddApi("/echo", HTTP_POST, http_api_echo);
 
     http_server_t server;
     server.port = 8080;
-    server.worker_processes = 4;
     server.service = &service;
     http_server_run(&server);
     return 0;
 }
 ```
+#### http client
+see examples/curl.cpp
+```c++
+#include "http_client.h"
+
+int main(int argc, char* argv[]) {
+    HttpRequest req;
+    req.method = HTTP_POST;
+    req.url = "http://localhost:8080/v1/api/echo";
+    req.body = "hello,world!";
+    HttpResponse res;
+    int ret = http_client_send(&req, &res);
+    printf("%s\n", req.Dump(true,true).c_str());
+    if (ret != 0) {
+        printf("* Failed:%s:%d\n", http_client_strerror(ret), ret);
+    }
+    else {
+        printf("%s\n", res.Dump(true,true).c_str());
+    }
+    return ret;
+}
+```
 
 ```shell
 git clone https://github.com/ithewei/libhv.git

+ 1 - 1
base/hthread.h

@@ -6,8 +6,8 @@
 
 #ifdef OS_WIN
 #define gettid  GetCurrentThreadId
+#elif HAVE_GETTID
 #elif defined(OS_ANDROID)
-#define gettid  gettid
 #elif defined(OS_LINUX)
 #include <sys/syscall.h>
 static inline int gettid() {

+ 1 - 0
configure

@@ -118,6 +118,7 @@ header=fcntl.h && check_header
 header=pthread.h && check_header
 
 # Checks for functions
+function=gettid && header=unistd.h && check_funtion
 function=strlcpy && header=string.h && check_funtion
 function=strlcat && header=string.h && check_funtion
 function=clock_gettime && header=time.h && check_funtion

+ 4 - 0
hconfig.h

@@ -29,6 +29,10 @@
 #define HAVE_PTHREAD_H 1
 #endif
 
+#ifndef HAVE_GETTID
+#define HAVE_GETTID 0
+#endif
+
 #ifndef HAVE_STRLCPY
 #define HAVE_STRLCPY 0
 #endif