Socket: Ignore ECONNREFUSED on write to datagram socket
[senf.git] / Socket / ReadWritePolicy.cc
index 8d55091..4b43625 100644 (file)
@@ -91,6 +91,12 @@ prefix_ unsigned senf::WriteablePolicy::do_write(FileHandle handle, char const *
             case EINTR:
                 break;
             case EAGAIN:
+            case ECONNREFUSED:
+                // Writing to a UDP socket seems return this error code if a corresponding ICMP
+                // error code has been received before (at least on linux). This is inconsistent
+                // since I cannot rely on getting ECONNREFUSED. I therefore ignore this error. TCP
+                // sockets will return this error on connect() and not on write(). Therefore we can
+                // unconditionally ignore this error here.
                 rv = 0;
                 break;
             default:
@@ -102,7 +108,7 @@ prefix_ unsigned senf::WriteablePolicy::do_write(FileHandle handle, char const *
 
 prefix_ unsigned senf::WriteablePolicy::do_writeto(FileHandle handle,
                                                           char const * buffer, unsigned size,
-                                                          struct sockaddr * addr, socklen_t len)
+                                                          struct sockaddr const * addr, socklen_t len)
 {
     int rv = -1;
     do {
@@ -132,4 +138,6 @@ prefix_ unsigned senf::WriteablePolicy::do_writeto(FileHandle handle,
 // c-file-style: "senf"
 // indent-tabs-mode: nil
 // ispell-local-dictionary: "american"
+// compile-command: "scons -u test"
+// comment-column: 40
 // End: