WPS: Clean up http_client_tx_ready()

Calculate the send() buffer length only once to make this a bit more
readable.

Signed-off-by: Jouni Malinen <j@w1.fi>
This commit is contained in:
Jouni Malinen 2015-08-29 13:34:39 +03:00
parent 24a5e528ce
commit 63fc84acd7

View file

@ -85,15 +85,16 @@ static void http_client_tx_ready(int sock, void *eloop_ctx, void *sock_ctx)
{ {
struct http_client *c = eloop_ctx; struct http_client *c = eloop_ctx;
int res; int res;
size_t send_len;
send_len = wpabuf_len(c->req) - c->req_pos;
wpa_printf(MSG_DEBUG, "HTTP: Send client request to %s:%d (%lu of %lu " wpa_printf(MSG_DEBUG, "HTTP: Send client request to %s:%d (%lu of %lu "
"bytes remaining)", "bytes remaining)",
inet_ntoa(c->dst.sin_addr), ntohs(c->dst.sin_port), inet_ntoa(c->dst.sin_addr), ntohs(c->dst.sin_port),
(unsigned long) wpabuf_len(c->req), (unsigned long) wpabuf_len(c->req),
(unsigned long) wpabuf_len(c->req) - c->req_pos); (unsigned long) send_len);
res = send(c->sd, wpabuf_head_u8(c->req) + c->req_pos, res = send(c->sd, wpabuf_head_u8(c->req) + c->req_pos, send_len, 0);
wpabuf_len(c->req) - c->req_pos, 0);
if (res < 0) { if (res < 0) {
wpa_printf(MSG_DEBUG, "HTTP: Failed to send buffer: %s", wpa_printf(MSG_DEBUG, "HTTP: Failed to send buffer: %s",
strerror(errno)); strerror(errno));
@ -102,12 +103,11 @@ static void http_client_tx_ready(int sock, void *eloop_ctx, void *sock_ctx)
return; return;
} }
if ((size_t) res < wpabuf_len(c->req) - c->req_pos) { if ((size_t) res < send_len) {
wpa_printf(MSG_DEBUG, "HTTP: Sent %d of %lu bytes; %lu bytes " wpa_printf(MSG_DEBUG, "HTTP: Sent %d of %lu bytes; %lu bytes "
"remaining", "remaining",
res, (unsigned long) wpabuf_len(c->req), res, (unsigned long) wpabuf_len(c->req),
(unsigned long) wpabuf_len(c->req) - c->req_pos - (unsigned long) send_len - res);
res);
c->req_pos += res; c->req_pos += res;
return; return;
} }