summaryrefslogtreecommitdiff
path: root/Utility
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2013-05-02 16:48:14 -0400
committerGravatar Joey Hess <joey@kitenet.net>2013-05-02 16:48:14 -0400
commit9ad8b871af82fb165ae21a996397ee00cd9ea7a8 (patch)
tree02968f4f6271dcd0bef6eaf6c206efe95d7a867e /Utility
parentfbf3662c81fb7041491c8f7c36e078192dffd137 (diff)
work around getAddrInfo segfault on Android
For an unknown reason, getAddrInfo currently is segfaulting. Note that in February, I had used warpDebug, which uses getAddrInfo, and it worked. Don't know if my toolchain has changed and broke it, or it's due to having a different Android device now. Anyway, work around it by hardcoding the address to use.
Diffstat (limited to 'Utility')
-rw-r--r--Utility/WebApp.hs24
1 files changed, 20 insertions, 4 deletions
diff --git a/Utility/WebApp.hs b/Utility/WebApp.hs
index 1306b14c3..440d56fdf 100644
--- a/Utility/WebApp.hs
+++ b/Utility/WebApp.hs
@@ -72,7 +72,7 @@ webAppSettings = defaultSettings
}
{- Binds to a local socket, or if specified, to a socket on the specified
- - hostname or address. Selets any free port, unless the hostname ends with
+ - hostname or address. Selects any free port, unless the hostname ends with
- ":port"
-
- Prefers to bind to the ipv4 address rather than the ipv6 address
@@ -80,6 +80,18 @@ webAppSettings = defaultSettings
-}
getSocket :: Maybe HostName -> IO Socket
getSocket h = do
+#ifdef __ANDROID__
+ -- getAddrInfo currently segfaults on Android.
+ -- The HostName is ignored by this code.
+ when (isJust h) $
+ error "getSocket with HostName not supported on Android"
+ addr <- inet_addr "127.0.0.1"
+ sock <- socket AF_INET Stream defaultProtocol
+ preparesocket sock
+ bindSocket sock (SockAddrInet aNY_PORT addr)
+ use sock
+ where
+#else
addrs <- getAddrInfo (Just hints) (Just hostname) port
case (partition (\a -> addrFamily a == AF_INET) addrs) of
(v4addr:_, _) -> go v4addr
@@ -94,12 +106,16 @@ getSocket h = do
go' :: Int -> AddrInfo -> IO Socket
go' 0 _ = error "unable to bind to local socket"
go' n addr = do
- r <- tryIO $ bracketOnError (open addr) sClose (use addr)
+ r <- tryIO $ bracketOnError (open addr) sClose (useaddr addr)
either (const $ go' (pred n) addr) return r
open addr = socket (addrFamily addr) (addrSocketType addr) (addrProtocol addr)
- use addr sock = do
- setSocketOption sock ReuseAddr 1
+ useaddr addr sock = do
+ preparesocket sock
bindSocket sock (addrAddress addr)
+ use sock
+#endif
+ preparesocket sock = setSocketOption sock ReuseAddr 1
+ use sock = do
listen sock maxListenQueue
return sock