diff options
author | Joey Hess <joey@kitenet.net> | 2013-05-02 22:38:45 -0400 |
---|---|---|
committer | Joey Hess <joey@kitenet.net> | 2013-05-02 22:38:45 -0400 |
commit | ed4e08d23a005d5f43151d271a35a99fccd9b978 (patch) | |
tree | 606cc3924d33f08af7a6a5d9ac3267ee115821f3 /Utility/WebApp.hs | |
parent | 64c5d51645d665e96bb3f2467692d9be88cbeefe (diff) |
work around strange endianness bug in port number on Android
Diffstat (limited to 'Utility/WebApp.hs')
-rw-r--r-- | Utility/WebApp.hs | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/Utility/WebApp.hs b/Utility/WebApp.hs index 440d56fdf..0614384a1 100644 --- a/Utility/WebApp.hs +++ b/Utility/WebApp.hs @@ -36,6 +36,9 @@ import Blaze.ByteString.Builder (Builder) import Data.Monoid import Control.Arrow ((***)) import Control.Concurrent +#ifdef __ANDROID__ +import Data.Endian +#endif localhost :: HostName localhost = "localhost" @@ -63,7 +66,16 @@ runWebApp :: Maybe HostName -> Wai.Application -> (SockAddr -> IO ()) -> IO () runWebApp h app observer = do sock <- getSocket h void $ forkIO $ runSettingsSocket webAppSettings sock app - observer =<< getSocketName sock + sockaddr <- fixSockAddr <$> getSocketName sock + observer sockaddr + +fixSockAddr :: SockAddr -> SockAddr +#ifdef __ANDROID__ +{- On Android, the port is currently incorrectly returned in network + - byte order, which is wrong on little endian systems. -} +fixSockAddr (SockAddrInet (PortNum port) addr) = SockAddrInet (PortNum $ swapEndian port) addr +#endif +fixSockAddr addr = addr webAppSettings :: Settings webAppSettings = defaultSettings |