From 2c29a1c96d78eb68fbabbc4025f22a8ecfa48180 Mon Sep 17 00:00:00 2001 From: Seonah Moon Date: Thu, 3 May 2018 19:58:56 +0900 Subject: Add new API for TCP Fast Open Change-Id: Ic459a29d1fa1100ca598726aca8f555e8c4f69e3 --- include/http.h | 67 +++++++++++++++++++++++++++------------- include/http_private.h | 2 ++ packaging/capi-network-http.spec | 2 +- src/http_transaction.c | 39 +++++++++++++++++++++++ test/http_test.c | 10 ++++++ 5 files changed, 98 insertions(+), 22 deletions(-) diff --git a/include/http.h b/include/http.h index 618904f..931d602 100644 --- a/include/http.h +++ b/include/http.h @@ -27,12 +27,6 @@ extern "C" { #endif - -#ifndef TIZEN_ERROR_HTTP -#define TIZEN_ERROR_HTTP -0x03000000 -#endif - - /** * @file http.h */ @@ -215,6 +209,8 @@ typedef enum { /** * @brief Called when the HTTP header is received. * @since_tizen 3.0 + * @remarks The @a header should be released using free(). \n + * The @a header is available until @a http_transaction is released. * @param[in] http_transaction The HTTP transaction handle * @param[in] header The header information of HTTP Transaction * @param[in] header_len The length of the HTTP Transaction header @@ -261,11 +257,11 @@ typedef void (*http_transaction_completed_cb)(http_transaction_h http_transactio /** * @brief Called when the HTTP transaction is aborted. * @details Following error codes can be delivered. \n - * #HTTP_ERROR_OPERATION_FAILED, \n - * #HTTP_ERROR_COULDNT_RESOLVE_HOST, \n - * #HTTP_ERROR_COULDNT_CONNECT, \n - * #HTTP_ERROR_OPERATION_TIMEDOUT, \n - * #HTTP_ERROR_SSL_CONNECT_ERROR. + * #HTTP_ERROR_OPERATION_FAILED, \n + * #HTTP_ERROR_COULDNT_RESOLVE_HOST, \n + * #HTTP_ERROR_COULDNT_CONNECT, \n + * #HTTP_ERROR_OPERATION_TIMEDOUT, \n + * #HTTP_ERROR_SSL_CONNECT_ERROR. * @since_tizen 3.0 * @param[in] http_transaction The HTTP transaction handle * @param[in] error The error code about aborted reason @@ -330,9 +326,9 @@ int http_deinit(void); * @brief Creates the HTTP session handle. * @since_tizen 3.0 * @remarks The @a http_session should be released using http_session_destroy(). - * Opened transactions can't be submitted after destroying session handle. + * Opened transactions can't be submitted after destroying session handle. * @param[in] mode The HTTP session mode - * @param[out] http_session The HTTP session handle + * @param[out] http_session The HTTP session handle * @return @c 0 on success, * otherwise negative error value * @retval #HTTP_ERROR_NONE Successful @@ -415,7 +411,7 @@ int http_session_get_auto_redirection(http_session_h http_session, bool *auto_re * @brief Gets the number of active transactions in the current session. * @since_tizen 3.0 * @param[in] http_session The HTTP session handle - * @param[out] active_transaction_count The number of activated transactions + * @param[out] active_transaction_count The number of activated transactions * @return @c 0 on success, * otherwise negative error value * @retval #HTTP_ERROR_NONE Successful @@ -473,7 +469,7 @@ int http_session_destroy_all_transactions(http_session_h http_session); * @since_tizen 3.0 * @privlevel public * @privilege %http://tizen.org/privilege/internet \n - * %http://tizen.org/privilege/network.get + * %http://tizen.org/privilege/network.get * @param[in] http_transaction The HTTP transaction handle * @return @c 0 on success, * otherwise negative error value @@ -489,8 +485,8 @@ int http_transaction_submit(http_transaction_h http_transaction); /** * @brief Closes the HTTP transaction handle. * @since_tizen 3.0 - * @remarks The @a transaction is released by http_transaction_destroy(). - * http_transaction should be set to NULL after using it. + * @remarks The @a http_transaction is released by http_transaction_destroy(). + * http_transaction should be set to NULL after using it. * @param[in] http_transaction The HTTP transaction handle * @return @c 0 on success, * otherwise negative error value @@ -506,8 +502,8 @@ int http_transaction_destroy(http_transaction_h http_transaction); /** * @brief Registers callback called when receives header. * @since_tizen 3.0 - * @param[in] http_transaction The HTTP transaction handle - * @param[in] header_cb The callback function to be called + * @param[in] http_transaction The HTTP transaction handle + * @param[in] header_cb The callback function to be called * @param[in] user_data The user data passed to the callback function * @return @c 0 on success, * otherwise negative error value @@ -665,7 +661,7 @@ int http_transaction_pause(http_transaction_h http_transaction, http_pause_type_ /** * @brief Cancels the transaction. * @details This function cancels the transaction.\n - * The aborted callback is invoked after using it. + * The aborted callback is invoked after using it. * @since_tizen 3.0 * @param[in] http_transaction The HTTP transaction handle * @return @c 0 on success, @@ -755,6 +751,34 @@ int http_transaction_set_server_certificate_verification(http_transaction_h http int http_transaction_get_server_certificate_verification(http_transaction_h http_transaction, bool* verify); +/** + * @brief Sets the flag to allow TCP Fast Open. + * @since_tizen 5.0 + * @param[in] http_transaction The HTTP transaction handle + * @param[in] enable The flag to enable TCP Fast Open + * @return @c 0 on success, + * otherwise negative error value + * @retval #HTTP_ERROR_NONE Successful + * @retval #HTTP_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #HTTP_ERROR_INVALID_OPERATION Invalid operation + * @retval #HTTP_ERROR_NOT_SUPPORTED Not Supported + */ +int http_transaction_set_tcp_fastopen(http_transaction_h http_transaction, bool enable); + +/** + * @brief Gets the flag to allow TCP Fast Open. + * @since_tizen 5.0 + * @param[in] http_transaction The HTTP transaction handle + * @param[out] enable The flag to enable TCP Fast Open + * @return @c 0 on success, + * otherwise negative error value + * @retval #HTTP_ERROR_NONE Successful + * @retval #HTTP_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #HTTP_ERROR_INVALID_OPERATION Invalid operation + * @retval #HTTP_ERROR_NOT_SUPPORTED Not Supported + */ +int http_transaction_get_tcp_fastopen(http_transaction_h http_transaction, bool *enable); + /** * @} */ @@ -992,7 +1016,7 @@ int http_transaction_request_get_cookie(http_transaction_h http_transaction, cha /** * @brief Writes the request message body. * @details This function writes the request message body in the internal queue. \n - * The written queue for request body is uploaded after invoking http_transaction_submit(). + * The written queue for request body is uploaded after invoking http_transaction_submit(). * @since_tizen 3.0 * @param[in] http_transaction The HTTP transaction handle * @param[in] body The message body data @@ -1019,6 +1043,7 @@ int http_transaction_request_write_body(http_transaction_h http_transaction, con * @retval #HTTP_ERROR_INVALID_PARAMETER Invalid parameter * @retval #HTTP_ERROR_INVALID_OPERATION Invalid operation * @retval #HTTP_ERROR_NOT_SUPPORTED Not Supported + * @retval #HTTP_ERROR_PERMISSION_DENIED Permission denied */ int http_transaction_request_set_upload_file(http_transaction_h http_transaction, const char *file_path); diff --git a/include/http_private.h b/include/http_private.h index aa25e34..22651fc 100644 --- a/include/http_private.h +++ b/include/http_private.h @@ -153,6 +153,8 @@ typedef struct { bool upload_event; bool verify_peer; gchar *ca_path; + bool tcp_fastopen; + gchar error[CURL_ERROR_SIZE]; bool cancel; diff --git a/packaging/capi-network-http.spec b/packaging/capi-network-http.spec index ecc64c0..d2fa659 100644 --- a/packaging/capi-network-http.spec +++ b/packaging/capi-network-http.spec @@ -1,6 +1,6 @@ Name: capi-network-http Summary: Http Framework -Version: 0.0.32 +Version: 0.0.33 Release: 0 Group: System/Network License: Apache-2.0 diff --git a/src/http_transaction.c b/src/http_transaction.c index 396a21f..41acb26 100644 --- a/src/http_transaction.c +++ b/src/http_transaction.c @@ -14,6 +14,8 @@ * limitations under the License. */ +#include + #include "http.h" #include "http_private.h" @@ -389,6 +391,9 @@ int _transaction_submit(gpointer user_data) } //LCOV_EXCL_STOP + if (transaction->tcp_fastopen) + curl_easy_setopt(transaction->easy_handle, CURLOPT_TCP_FASTOPEN, 1L); + curl_easy_setopt(transaction->easy_handle, CURLOPT_HEADERFUNCTION, __handle_header_cb); curl_easy_setopt(transaction->easy_handle, CURLOPT_HEADERDATA, transaction); @@ -529,6 +534,7 @@ API int http_session_open_transaction(http_session_h http_session, http_method_e transaction->upload_event = FALSE; transaction->verify_peer = TRUE; transaction->ca_path = g_strdup(HTTP_DEFAULT_CA_PATH); + transaction->tcp_fastopen = 0; transaction->error[0] = '\0'; transaction->cancel = 0; @@ -649,6 +655,7 @@ API int http_transaction_destroy(http_transaction_h http_transaction) transaction->timeout = 0; transaction->verify_peer = 0; + transaction->tcp_fastopen = 0; if (transaction->ca_path) { free(transaction->ca_path); @@ -1034,6 +1041,38 @@ API int http_transaction_set_server_certificate_verification(http_transaction_h return HTTP_ERROR_NONE; } +API int http_transaction_get_tcp_fastopen(http_transaction_h http_transaction, bool *enable) +{ + _retvm_if(_http_is_init() == false, HTTP_ERROR_INVALID_OPERATION, + "http isn't initialized"); + _retvm_if(http_transaction == NULL, HTTP_ERROR_INVALID_PARAMETER, + "parameter(http_transaction) is NULL\n"); + +#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 6, 0) + return HTTP_ERROR_NOT_SUPPORTED; +#else + __http_transaction_h *transaction = (__http_transaction_h *)http_transaction; + *enable = transaction->tcp_fastopen; + return HTTP_ERROR_NONE; +#endif +} + +API int http_transaction_set_tcp_fastopen(http_transaction_h http_transaction, bool enable) +{ + _retvm_if(_http_is_init() == false, HTTP_ERROR_INVALID_OPERATION, + "http isn't initialized"); + _retvm_if(http_transaction == NULL, HTTP_ERROR_INVALID_PARAMETER, + "parameter(http_transaction) is NULL\n"); + +#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 6, 0) + return HTTP_ERROR_NOT_SUPPORTED; +#else + __http_transaction_h *transaction = (__http_transaction_h *)http_transaction; + transaction->tcp_fastopen = enable; + return HTTP_ERROR_NONE; +#endif +} + //LCOV_EXCL_START API int http_transaction_set_http_auth_scheme(http_transaction_h http_transaction, http_auth_scheme_e auth_scheme) { diff --git a/test/http_test.c b/test/http_test.c index 19ded45..bb3ae27 100644 --- a/test/http_test.c +++ b/test/http_test.c @@ -226,6 +226,7 @@ int test_simple_get(void) int ret; http_transaction_h transaction = NULL; http_method_e method; + int tfo = false; printf("Input uri: "); ret = scanf("%1023s", uri); @@ -243,6 +244,15 @@ int test_simple_get(void) return 0; } + printf("TCP Fast Oepn(0: disable, 1: enable): "); + ret = scanf("%1d", &tfo); + + ret = http_transaction_set_tcp_fastopen(transaction, tfo); + if (ret != 0) { + ERR("Fail to set tfo", ret); + return 0; + } + _register_callbacks(transaction); ret = http_transaction_submit(transaction); if (ret != 0) { -- cgit v1.2.3