Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't Error when sendto() errors with ENETUNREACH or EHOSTUNREACH #7

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 17 additions & 5 deletions src/driver/device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -449,9 +449,17 @@ void Device::handle_send(Guard& G)
// non-blocking sendto(), so we don't unlock here
sock.sendto(peer_addr, (const char*)&msg.buf[0], msg.buf.size()*4);
cnt_sent++;
}catch(SocketBusy&){
want_to_send = true;
return;
}catch(SocketError& e){
if(e.code==SOCK_EWOULDBLOCK) {
want_to_send = true;
return;
} else if(e.code==ENETUNREACH || e.code==EHOSTUNREACH) {
IFDBG(1, "Unable to send to %s : (%d) %s", peer_name.c_str(), e.code, e.what());
// Don't throw (and latch into Error state) what is probably
// a transient error. Will timeout since packet wasn't sent
} else {
throw;
}
}
IFDBG(1, "Send seq=%08x %zu bytes", (unsigned)msg.seq, msg.buf.size()*4u);

Expand Down Expand Up @@ -952,8 +960,12 @@ void Device::run()
doProcess[i] = true;
cnt_recv++;
cnt_recv_bytes += unsigned(feedUDPHeaderSize) + bufs[i].size();
}catch(SocketBusy&){
break;
}catch(SocketError& e){
if(e.code==SOCK_EWOULDBLOCK) {
break;
} else {
throw;
}
}

if(!doProcess[i]) {
Expand Down
4 changes: 0 additions & 4 deletions src/util/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,6 @@ void Socket::sendto(const osiSockAddr& dest, const char* buf, size_t buflen) con
ssize_t ret = ::sendto(sock, buf, buflen, 0, &dest.sa, sizeof(dest));
if(ret<0) {
int code = SOCKERRNO;
if(code==SOCK_EWOULDBLOCK)
throw SocketBusy();
throw SocketError(code);
} else if(size_t(ret)!=buflen)
throw std::runtime_error("Incomplete sendto()");
Expand All @@ -119,8 +117,6 @@ size_t Socket::recvfrom(osiSockAddr& src, char* buf, size_t buflen) const
ssize_t ret = ::recvfrom(sock, buf, buflen, 0, &src.sa, &len);
if(ret<0) {
int code = SOCKERRNO;
if(code==SOCK_EWOULDBLOCK)
throw SocketBusy();
throw SocketError(code);
}
return size_t(ret);
Expand Down
6 changes: 0 additions & 6 deletions src/util/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,6 @@ struct epicsShareClass SocketError : public std::exception
const char *what() const throw();
};

struct epicsShareClass SocketBusy : public SocketError
{
SocketBusy() :SocketError(SOCK_EWOULDBLOCK) {}
virtual ~SocketBusy() throw() {}
};

// RAII handle to ensure that sockets aren't leaked
// and helper to make socket calls throw SocketError
struct Socket
Expand Down