2
0
Эх сурвалжийг харах

Solved automatic block size calculation. (Fix #12)

silvioprog 6 жил өмнө
parent
commit
abaa9e0fe9

+ 2 - 3
include/sagui.h

@@ -925,7 +925,6 @@ SG_EXTERN int sg_httpres_sendfile(struct sg_httpres *res, uint64_t size, uint64_
  * Sends a stream to the client.
  * Sends a stream to the client.
  * \param[in] res Response handle.
  * \param[in] res Response handle.
  * \param[in] size Size of the stream.
  * \param[in] size Size of the stream.
- * \param[in] block_size Preferred block size for stream loading.
  * \param[in] read_cb Callback to read data from stream handle.
  * \param[in] read_cb Callback to read data from stream handle.
  * \param[in] handle Stream handle.
  * \param[in] handle Stream handle.
  * \param[in] free_cb Callback to free the stream handle.
  * \param[in] free_cb Callback to free the stream handle.
@@ -936,8 +935,8 @@ SG_EXTERN int sg_httpres_sendfile(struct sg_httpres *res, uint64_t size, uint64_
  * \retval ENOMEM Out of memory.
  * \retval ENOMEM Out of memory.
  * \note Use `size = 0` if the stream size is unknown.
  * \note Use `size = 0` if the stream size is unknown.
  */
  */
-SG_EXTERN int sg_httpres_sendstream(struct sg_httpres *res, uint64_t size, size_t block_size, sg_read_cb read_cb,
-                                    void *handle, sg_free_cb free_cb, unsigned int status);
+SG_EXTERN int sg_httpres_sendstream(struct sg_httpres *res, uint64_t size, sg_read_cb read_cb, void *handle,
+                                    sg_free_cb free_cb, unsigned int status);
 
 
 #ifdef SG_HTTP_COMPRESSION
 #ifdef SG_HTTP_COMPRESSION
 
 

+ 5 - 5
src/sg_httpres.c

@@ -203,10 +203,10 @@ error:
     return errnum;
     return errnum;
 }
 }
 
 
-int sg_httpres_sendstream(struct sg_httpres *res, uint64_t size, size_t block_size, sg_read_cb read_cb, void *handle,
-                          sg_free_cb free_cb, unsigned int status) {
+int sg_httpres_sendstream(struct sg_httpres *res, uint64_t size, sg_read_cb read_cb, void *handle, sg_free_cb free_cb,
+                          unsigned int status) {
     int errnum;
     int errnum;
-    if (!res || (block_size < 1) || !read_cb || (status < 100) || (status > 599)) {
+    if (!res || !read_cb || (status < 100) || (status > 599)) {
         errnum = EINVAL;
         errnum = EINVAL;
         goto error;
         goto error;
     }
     }
@@ -214,8 +214,8 @@ int sg_httpres_sendstream(struct sg_httpres *res, uint64_t size, size_t block_si
         errnum = EALREADY;
         errnum = EALREADY;
         goto error;
         goto error;
     }
     }
-    res->handle = MHD_create_response_from_callback((size > 0 ? size : MHD_SIZE_UNKNOWN), block_size,
-                                                    read_cb, handle, free_cb);
+    res->handle = MHD_create_response_from_callback((size > 0 ? size : MHD_SIZE_UNKNOWN), SG__BLOCK_SIZE, read_cb,
+                                                    handle, free_cb);
     if (!res->handle)
     if (!res->handle)
         return ENOMEM;
         return ENOMEM;
     res->status = status;
     res->status = status;

+ 8 - 11
test/test_httpres.c

@@ -332,31 +332,28 @@ static void test_httpres_sendfile(struct sg_httpres *res) {
 
 
 static void test_httpres_sendstream(struct sg_httpres *res) {
 static void test_httpres_sendstream(struct sg_httpres *res) {
     char *str;
     char *str;
-    size_t size = sizeof(int), block_size = sizeof(int);
+    size_t size = sizeof(int);
     int buf = 1;
     int buf = 1;
-    ASSERT(sg_httpres_sendstream(NULL, size, block_size, dummy_read_cb, &buf, dummy_free_cb, 200) == EINVAL);
-    ASSERT(buf == 0);
-    buf = 1;
-    ASSERT(sg_httpres_sendstream(res, size, 0, dummy_read_cb, &buf, dummy_free_cb, 200) == EINVAL);
+    ASSERT(sg_httpres_sendstream(NULL, size, dummy_read_cb, &buf, dummy_free_cb, 200) == EINVAL);
     ASSERT(buf == 0);
     ASSERT(buf == 0);
     buf = 1;
     buf = 1;
-    ASSERT(sg_httpres_sendstream(res, size, block_size, NULL, &buf, dummy_free_cb, 200) == EINVAL);
+    ASSERT(sg_httpres_sendstream(res, size, NULL, &buf, dummy_free_cb, 200) == EINVAL);
     ASSERT(buf == 0);
     ASSERT(buf == 0);
     buf = 1;
     buf = 1;
-    ASSERT(sg_httpres_sendstream(res, size, block_size, dummy_read_cb, &buf, dummy_free_cb, 99) == EINVAL);
+    ASSERT(sg_httpres_sendstream(res, size, dummy_read_cb, &buf, dummy_free_cb, 99) == EINVAL);
     ASSERT(buf == 0);
     ASSERT(buf == 0);
     buf = 1;
     buf = 1;
-    ASSERT(sg_httpres_sendstream(res, size, block_size, dummy_read_cb, &buf, dummy_free_cb, 600) == EINVAL);
+    ASSERT(sg_httpres_sendstream(res, size, dummy_read_cb, &buf, dummy_free_cb, 600) == EINVAL);
     ASSERT(buf == 0);
     ASSERT(buf == 0);
 
 
     size = sizeof(str);
     size = sizeof(str);
     str = sg_alloc(size);
     str = sg_alloc(size);
-    ASSERT(sg_httpres_sendstream(res, 0, block_size, dummy_read_cb, str, dummy_free_cb, 200) == 0);
+    ASSERT(sg_httpres_sendstream(res, 0, dummy_read_cb, str, dummy_free_cb, 200) == 0);
     sg_free(res->handle);
     sg_free(res->handle);
     res->handle = NULL;
     res->handle = NULL;
-    ASSERT(sg_httpres_sendstream(res, size, block_size, dummy_read_cb, str, dummy_free_cb, 201) == 0);
+    ASSERT(sg_httpres_sendstream(res, size, dummy_read_cb, str, dummy_free_cb, 201) == 0);
     ASSERT(res->status == 201);
     ASSERT(res->status == 201);
-    ASSERT(sg_httpres_sendstream(res, size, block_size, dummy_read_cb, str, dummy_free_cb, 200) == EALREADY);
+    ASSERT(sg_httpres_sendstream(res, size, dummy_read_cb, str, dummy_free_cb, 200) == EALREADY);
     sg_free(res->handle);
     sg_free(res->handle);
     res->handle = NULL;
     res->handle = NULL;
     sg_free(str);
     sg_free(str);

+ 1 - 2
test/test_httpsrv_curl.c

@@ -231,8 +231,7 @@ static void srv_req_cb(__SG_UNUSED void *cls, struct sg_httpreq *req, struct sg_
         ASSERT(access(filename1, F_OK) == 0);
         ASSERT(access(filename1, F_OK) == 0);
         tmp_file = fopen(filename1, "r");
         tmp_file = fopen(filename1, "r");
         ASSERT(tmp_file);
         ASSERT(tmp_file);
-        sg_httpres_sendstream(res, len, 256,
-                              sg_httpres_sendstream_read_cb, tmp_file, sg_httpres_sendstream_free_cb, 200);
+        sg_httpres_sendstream(res, len, sg_httpres_sendstream_read_cb, tmp_file, sg_httpres_sendstream_free_cb, 200);
         return;
         return;
     }
     }