[Net] Explicitly handle buffer errors in send/recv
This commit is contained in:
parent
ac5d7dc821
commit
c783dd4a52
2 changed files with 19 additions and 0 deletions
|
@ -195,6 +195,9 @@ NetSocketPosix::NetError NetSocketPosix::_get_socket_error() const {
|
|||
return ERR_NET_IN_PROGRESS;
|
||||
if (err == WSAEWOULDBLOCK)
|
||||
return ERR_NET_WOULD_BLOCK;
|
||||
if (err == WSAEMSGSIZE || err == WSAENOBUFS) {
|
||||
return ERR_NET_BUFFER_TOO_SMALL;
|
||||
}
|
||||
print_verbose("Socket error: " + itos(err));
|
||||
return ERR_NET_OTHER;
|
||||
#else
|
||||
|
@ -207,6 +210,9 @@ NetSocketPosix::NetError NetSocketPosix::_get_socket_error() const {
|
|||
if (errno == EAGAIN || errno == EWOULDBLOCK) {
|
||||
return ERR_NET_WOULD_BLOCK;
|
||||
}
|
||||
if (errno == ENOBUFS) {
|
||||
return ERR_NET_BUFFER_TOO_SMALL;
|
||||
}
|
||||
print_verbose("Socket error: " + itos(errno));
|
||||
return ERR_NET_OTHER;
|
||||
#endif
|
||||
|
@ -535,6 +541,9 @@ Error NetSocketPosix::recv(uint8_t *p_buffer, int p_len, int &r_read) {
|
|||
if (err == ERR_NET_WOULD_BLOCK) {
|
||||
return ERR_BUSY;
|
||||
}
|
||||
if (err == ERR_NET_BUFFER_TOO_SMALL) {
|
||||
return ERR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
return FAILED;
|
||||
}
|
||||
|
@ -556,6 +565,9 @@ Error NetSocketPosix::recvfrom(uint8_t *p_buffer, int p_len, int &r_read, IP_Add
|
|||
if (err == ERR_NET_WOULD_BLOCK) {
|
||||
return ERR_BUSY;
|
||||
}
|
||||
if (err == ERR_NET_BUFFER_TOO_SMALL) {
|
||||
return ERR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
return FAILED;
|
||||
}
|
||||
|
@ -592,6 +604,9 @@ Error NetSocketPosix::send(const uint8_t *p_buffer, int p_len, int &r_sent) {
|
|||
if (err == ERR_NET_WOULD_BLOCK) {
|
||||
return ERR_BUSY;
|
||||
}
|
||||
if (err == ERR_NET_BUFFER_TOO_SMALL) {
|
||||
return ERR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
return FAILED;
|
||||
}
|
||||
|
@ -611,6 +626,9 @@ Error NetSocketPosix::sendto(const uint8_t *p_buffer, int p_len, int &r_sent, IP
|
|||
if (err == ERR_NET_WOULD_BLOCK) {
|
||||
return ERR_BUSY;
|
||||
}
|
||||
if (err == ERR_NET_BUFFER_TOO_SMALL) {
|
||||
return ERR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
return FAILED;
|
||||
}
|
||||
|
|
|
@ -54,6 +54,7 @@ private:
|
|||
ERR_NET_WOULD_BLOCK,
|
||||
ERR_NET_IS_CONNECTED,
|
||||
ERR_NET_IN_PROGRESS,
|
||||
ERR_NET_BUFFER_TOO_SMALL,
|
||||
ERR_NET_OTHER
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue