Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of PicoTCP by
Diff: Socket/pico_bsd_layer.cpp
- Revision:
- 11:58acd53df75c
- Parent:
- 5:445d2fc04784
- Child:
- 13:c6662adea07d
--- a/Socket/pico_bsd_layer.cpp Thu Jun 06 00:38:54 2013 +0000
+++ b/Socket/pico_bsd_layer.cpp Thu Jun 06 07:08:58 2013 +0000
@@ -389,27 +389,42 @@
int picotcp_read(int sock,void *buf, int len)
{
struct socket * _sock = findAfterId(sock);
-
+ int r, tot_len = 0;
VALIDATE_NULL(_sock);
VALIDATE_ONE(_sock->proto,PICO_PROTO_TCP);
VALIDATE_ONE(_sock->state, SOCK_CONNECTED);
if(waitForEvent(_sock,PICO_SOCK_EV_RD,1))
return -1;
-
- return pico_socket_read(_sock->sock,buf,len);
+ while(tot_len < len) {
+ r = pico_socket_read(_sock->sock, (unsigned char *)buf + tot_len, len - tot_len);
+ if (r > 0)
+ tot_len += r;
+ else break;
+ }
+ return tot_len;
}
int picotcp_write(int sock,void *buf, int len)
{
struct socket * _sock = findAfterId(sock);
+ int r, tot_len = 0;
VALIDATE_NULL(_sock);
VALIDATE_ONE(_sock->proto,PICO_PROTO_TCP);
VALIDATE_ONE(_sock->state, SOCK_CONNECTED);
if(waitForEvent(_sock,PICO_SOCK_EV_WR,1))
return -1;
- return pico_socket_write(_sock->sock,buf,len);
+
+ if(waitForEvent(_sock,PICO_SOCK_EV_WR,1))
+ return -1;
+ while(tot_len < len) {
+ r = pico_socket_write(_sock->sock, (unsigned char *)buf + tot_len, len - tot_len);
+ if (r > 0)
+ tot_len += r;
+ else break;
+ }
+ return tot_len;
}
int picotcp_setsockopt(int sock, int option, void *value)
@@ -447,7 +462,7 @@
while (PICO_TIME_MS() < now + ms) {
if (_sock->mutex->lock(1) == false) {
- Thread::wait(1);
+ //Thread::wait(1);
continue;
}
