mirror of
https://github.com/lwip-tcpip/lwip.git
synced 2024-08-25 23:52:51 +00:00
make lwip_write() use lwip_send() and avoid code duplication.return copylen
in lwip_recvfrom since it has already been chosen as the minimum of len and buflen.
This commit is contained in:
parent
1dd7e81df7
commit
428293a69b
@ -272,16 +272,7 @@ lwip_recvfrom(int s, void *mem, int len, unsigned int flags,
|
|||||||
*fromlen = sizeof(struct sockaddr_in);
|
*fromlen = sizeof(struct sockaddr_in);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* if the length of the received data is larger than
|
|
||||||
len, this data is discarded and we return len.
|
|
||||||
otherwise we return the actual length of the received
|
|
||||||
data */
|
|
||||||
if(len > copylen) {
|
|
||||||
return copylen;
|
return copylen;
|
||||||
} else {
|
|
||||||
return len;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
/*-----------------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------------*/
|
||||||
int
|
int
|
||||||
@ -411,31 +402,6 @@ lwip_socket(int domain, int type, int protocol)
|
|||||||
int
|
int
|
||||||
lwip_write(int s, void *data, int size)
|
lwip_write(int s, void *data, int size)
|
||||||
{
|
{
|
||||||
struct lwip_socket *sock;
|
|
||||||
err_t err;
|
|
||||||
|
|
||||||
DEBUGF(SOCKETS_DEBUG, ("write: socket %d, size %d\n", s, size));
|
|
||||||
|
|
||||||
sock = get_socket(s);
|
|
||||||
if(sock == NULL) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
switch(netconn_type(sock->conn)) {
|
|
||||||
case NETCONN_UDP:
|
|
||||||
return lwip_send(s, data, size, 0);
|
return lwip_send(s, data, size, 0);
|
||||||
|
|
||||||
case NETCONN_TCP:
|
|
||||||
err = netconn_write(sock->conn, data, size, NETCONN_COPY);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
err = ERR_ARG;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if(err != ERR_OK) {
|
|
||||||
/* errno = ... */
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
return size;
|
|
||||||
}
|
}
|
||||||
/*-----------------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------------*/
|
||||||
|
Loading…
Reference in New Issue
Block a user