ithewei 3 years ago
parent
commit
c03ec9fd28
4 changed files with 12 additions and 11 deletions
  1. 2 2
      README-CN.md
  2. 1 0
      docs/API.md
  3. 8 9
      event/kcp/hkcp.c
  4. 1 0
      http/client/requests.h

+ 2 - 2
README-CN.md

@@ -345,7 +345,7 @@ int main(int argc, char** argv) {
         printf("onopen: GET %s\n", url.c_str());
     };
     ws.onmessage = [](const WebSocketChannelPtr& channel, const std::string& msg) {
-        printf("onmessage: %s\n", msg.c_str());
+        printf("onmessage: %.*s\n", (int)msg.size(), msg.data());
     };
     ws.onclose = [](const WebSocketChannelPtr& channel) {
         printf("onclose\n");
@@ -372,7 +372,7 @@ int main(int argc, char** argv) {
         printf("onopen\n");
     };
     ws.onmessage = [](const std::string& msg) {
-        printf("onmessage: %s\n", msg.c_str());
+        printf("onmessage: %.*s\n", (int)msg.size(), msg.data());
     };
     ws.onclose = []() {
         printf("onclose\n");

+ 1 - 0
docs/API.md

@@ -635,6 +635,7 @@
 - mqtt_client_publish
 - mqtt_client_subscribe
 - mqtt_client_unsubscribe
+- class MqttClient
 
 ## other
 - class HThreadPool

+ 8 - 9
event/kcp/hkcp.c

@@ -82,24 +82,23 @@ static void hio_write_kcp_event_cb(hevent_t* ev) {
 
     hio_write_kcp(io, buf->base, buf->len);
 
-    HV_FREE(buf->base);
     HV_FREE(buf);
 }
 
-static int hio_write_kcp_async(hio_t* io, const void* buf, size_t len) {
-    hbuf_t* newbuf = NULL;
-    HV_ALLOC_SIZEOF(newbuf);
-    newbuf->len = len;
-    HV_ALLOC(newbuf->base, len);
-    memcpy(newbuf->base, buf, len);
+static int hio_write_kcp_async(hio_t* io, const void* data, size_t len) {
+    hbuf_t* buf = NULL;
+    HV_ALLOC(buf, sizeof(hbuf_t) + len);
+    buf->base = (char*)buf + sizeof(hbuf_t);
+    buf->len = len;
+    memcpy(buf->base, data, len);
 
     hevent_t ev;
     memset(&ev, 0, sizeof(ev));
     ev.cb = hio_write_kcp_event_cb;
     ev.userdata = io;
-    ev.privdata = newbuf;
+    ev.privdata = buf;
     hloop_post_event(io->loop, &ev);
-    return 0;
+    return len;
 }
 
 int hio_write_kcp(hio_t* io, const void* buf, size_t len) {

+ 1 - 0
http/client/requests.h

@@ -74,6 +74,7 @@ HV_INLINE Response uploadFormFile(const char* url, const char* name, const char*
     Request req(new HttpRequest);
     req->method = method;
     req->url = url;
+    req->timeout = 600; // 10min
     req->content_type = MULTIPART_FORM_DATA;
     req->SetFormFile(name, filepath);
     for (auto& param : params) {