diff options
author | joe <joe@jerkface.net> | 2017-11-04 22:21:24 -0400 |
---|---|---|
committer | joe <joe@jerkface.net> | 2017-11-04 22:21:24 -0400 |
commit | 8903c7e0b9eea11dbf229747e7f9729bfe5d2f7b (patch) | |
tree | a15d464c97bbad2a9f256f5fb52c8375b11ca9d3 /src/Network/QueryResponse.hs | |
parent | f045f7e473b534cbe4dff70420e4cc0184465e54 (diff) |
Quieter output and some bug fixes.
Diffstat (limited to 'src/Network/QueryResponse.hs')
-rw-r--r-- | src/Network/QueryResponse.hs | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/src/Network/QueryResponse.hs b/src/Network/QueryResponse.hs index b757aed7..0345dd88 100644 --- a/src/Network/QueryResponse.hs +++ b/src/Network/QueryResponse.hs | |||
@@ -503,6 +503,17 @@ ignoreEOF def e | isEOFError e = pure def | |||
503 | udpBufferSize :: Int | 503 | udpBufferSize :: Int |
504 | udpBufferSize = 65536 | 504 | udpBufferSize = 65536 |
505 | 505 | ||
506 | -- | Wrapper around 'B.sendTo' that silently ignores DoesNotExistError. | ||
507 | saferSendTo :: Socket -> ByteString -> SockAddr -> IO () | ||
508 | saferSendTo sock bs saddr = void (B.sendTo sock bs saddr) | ||
509 | `catch` \e -> | ||
510 | -- sendTo: does not exist (Network is unreachable) | ||
511 | -- Occurs when IPv6 or IPv4 network is not available. | ||
512 | -- Currently, we require -threaded to prevent a forever-hang in this case. | ||
513 | if isDoesNotExistError e | ||
514 | then return () | ||
515 | else throw e | ||
516 | |||
506 | -- | A 'udpTransport' uses a UDP socket to send and receive 'ByteString's. The | 517 | -- | A 'udpTransport' uses a UDP socket to send and receive 'ByteString's. The |
507 | -- argument is the listen-address for incoming packets. This is a useful | 518 | -- argument is the listen-address for incoming packets. This is a useful |
508 | -- low-level 'Transport' that can be transformed for higher-level protocols | 519 | -- low-level 'Transport' that can be transformed for higher-level protocols |
@@ -520,22 +531,19 @@ udpTransport bind_address = do | |||
520 | Just . Right <$!> B.recvFrom sock udpBufferSize | 531 | Just . Right <$!> B.recvFrom sock udpBufferSize |
521 | kont $! r | 532 | kont $! r |
522 | , sendMessage = case family of | 533 | , sendMessage = case family of |
523 | -- TODO: sendTo: does not exist (Network is unreachable) | ||
524 | -- Occurs when IPv6 network is not available. | ||
525 | -- Currently, we require -threaded to prevent a forever-hang in this case. | ||
526 | AF_INET6 -> \case | 534 | AF_INET6 -> \case |
527 | (SockAddrInet port addr) -> \bs -> | 535 | (SockAddrInet port addr) -> \bs -> |
528 | -- Change IPv4 to 4mapped6 address. | 536 | -- Change IPv4 to 4mapped6 address. |
529 | void $ B.sendTo sock bs $ SockAddrInet6 port 0 (0,0,0x0000ffff,fromBE32 addr) 0 | 537 | saferSendTo sock bs $ SockAddrInet6 port 0 (0,0,0x0000ffff,fromBE32 addr) 0 |
530 | addr6 -> \bs -> void $ B.sendTo sock bs addr6 | 538 | addr6 -> \bs -> saferSendTo sock bs addr6 |
531 | AF_INET -> \case | 539 | AF_INET -> \case |
532 | (SockAddrInet6 port 0 (0,0,0x0000ffff,raw4) 0) -> \bs -> do | 540 | (SockAddrInet6 port 0 (0,0,0x0000ffff,raw4) 0) -> \bs -> do |
533 | let host4 = toBE32 raw4 | 541 | let host4 = toBE32 raw4 |
534 | -- Change 4mapped6 to ordinary IPv4. | 542 | -- Change 4mapped6 to ordinary IPv4. |
535 | -- hPutStrLn stderr $ "4mapped6 -> "++show (SockAddrInet port host4) | 543 | -- hPutStrLn stderr $ "4mapped6 -> "++show (SockAddrInet port host4) |
536 | void $ B.sendTo sock bs (SockAddrInet port host4) | 544 | saferSendTo sock bs (SockAddrInet port host4) |
537 | addr@(SockAddrInet6 {}) -> \bs -> hPutStrLn stderr ("Discarding packet to "++show addr) | 545 | addr@(SockAddrInet6 {}) -> \bs -> hPutStrLn stderr ("Discarding packet to "++show addr) |
538 | addr4 -> \bs -> void $ B.sendTo sock bs addr4 | 546 | addr4 -> \bs -> saferSendTo sock bs addr4 |
539 | _ -> \addr bs -> void $ B.sendTo sock bs addr | 547 | _ -> \addr bs -> saferSendTo sock bs addr |
540 | , closeTransport = close sock | 548 | , closeTransport = close sock |
541 | } | 549 | } |