Skip to content
This repository was archived by the owner on Jun 8, 2021. It is now read-only.

Commit ed2f45c

Browse files
DeepikaBartek Szatkowski
Deepika
authored and
Bartek Szatkowski
committed
Made sure entire buffer is transmitted
1 parent 963aa41 commit ed2f45c

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

main.cpp

+15-8
Original file line numberDiff line numberDiff line change
@@ -96,19 +96,26 @@ void http_demo(NetworkInterface *net)
9696

9797
// Send a simple http request
9898
char sbuffer[] = "GET / HTTP/1.1\r\nHost: www.arm.com\r\n\r\n";
99-
response = socket.send(sbuffer, sizeof sbuffer);
100-
if(response < 0) {
101-
printf("Error sending data: %d\r\n", response);
102-
socket.close();
103-
return;
104-
} else {
105-
printf("sent %d [%.*s]\r\n", response, strstr(sbuffer, "\r\n")-sbuffer, sbuffer);
99+
nsapi_size_t size = sizeof sbuffer;
100+
response = 0;
101+
while(size)
102+
{
103+
response = socket.send(sbuffer+response, size);
104+
if (response < 0) {
105+
printf("Error sending data: %d\r\n", response);
106+
socket.close();
107+
return;
108+
} else {
109+
size -= response;
110+
// Check if entire message was sent or not
111+
printf("sent %d [%.*s]\r\n", response, strstr(sbuffer, "\r\n")-sbuffer, sbuffer);
112+
}
106113
}
107114

108115
// Recieve a simple http response and print out the response line
109116
char rbuffer[64];
110117
response = socket.recv(rbuffer, sizeof rbuffer);
111-
if(response < 0) {
118+
if (response < 0) {
112119
printf("Error receiving data: %d\r\n", response);
113120
} else {
114121
printf("recv %d [%.*s]\r\n", response, strstr(rbuffer, "\r\n")-rbuffer, rbuffer);

0 commit comments

Comments
 (0)