Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions inc/webclient.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ struct webclient_session
struct webclient_header *header; /* webclient response header information */
int socket;
int resp_status;
struct timeval timeout;

char *host; /* server host */
char *req_url; /* HTTP request address*/
Expand Down
19 changes: 7 additions & 12 deletions src/webclient.c
Original file line number Diff line number Diff line change
Expand Up @@ -388,8 +388,7 @@ static int webclient_connect(struct webclient_session *session, const char *URI)
RT_ASSERT(session);
RT_ASSERT(URI);

timeout.tv_sec = WEBCLIENT_DEFAULT_TIMEO;
timeout.tv_usec = 0;
timeout = session->timeout;

if (strncmp(URI, "https://", 8) == 0)
{
Expand Down Expand Up @@ -882,6 +881,8 @@ struct webclient_session *webclient_session_create(size_t header_sz)
/* initialize the socket of session */
session->socket = -1;
session->content_length = -1;
session->timeout.tv_sec = WEBCLIENT_DEFAULT_TIMEO;
session->timeout.tv_usec = 0;

session->header = (struct webclient_header *) web_calloc(1, sizeof(struct webclient_header));
if (session->header == RT_NULL)
Expand Down Expand Up @@ -1220,19 +1221,13 @@ int webclient_post(struct webclient_session *session, const char *URI, const voi
*/
int webclient_set_timeout(struct webclient_session *session, int millisecond)
{
struct timeval timeout;
int second = rt_tick_from_millisecond(millisecond) / 1000;
int second = millisecond / 1000;
int microsecond = (millisecond % 1000) * 1000;

RT_ASSERT(session);

timeout.tv_sec = second;
timeout.tv_usec = 0;

/* set recv timeout option */
setsockopt(session->socket, SOL_SOCKET, SO_RCVTIMEO,
(void *) &timeout, sizeof(timeout));
setsockopt(session->socket, SOL_SOCKET, SO_SNDTIMEO,
(void *) &timeout, sizeof(timeout));
session->timeout.tv_sec = second;
session->timeout.tv_usec = microsecond;

return 0;
}
Expand Down