import Weak ( addForeignFinalizer )
import PrelIOBase -- IOError, Handle representation
import PrelHandle
-import PrelConc ( threadWaitRead )
+import PrelConc ( threadWaitRead, threadWaitWrite )
import Foreign
import Addr ( nullAddr )
status <- _ccall_ connectSocket s addr' sz (isDomainSocket::Int)
case (status::Int) of
-1 -> constructErrorAndFail "connect"
+ -6 -> do threadWaitWrite s >> writeIORef socketStatus Connected
+ -- ToDo: check for error with getsockopt
_ -> writeIORef socketStatus Connected
\end{code}
| UseLoopBack {- SO_USELOOPBACK -} -- not used, I believe.
#endif
+socketOptLevel :: SocketOption -> Int
+socketOptLevel so =
+ case so of
+#ifndef _WIN32
+ MaxSegment -> ``IPPROTO_TCP''
+#endif
+ NoDelay -> ``IPPROTO_TCP''
+ _ -> ``SOL_SOCKET''
+
packSocketOption :: SocketOption -> Int
packSocketOption so =
case so of
-> Int -- Option Value
-> IO ()
setSocketOption (MkSocket s _ _ _ _) so v = do
- rc <- _ccall_ setSocketOption__ s (packSocketOption so) v
+ rc <- _ccall_ setSocketOption__ s
+ (packSocketOption so)
+ (socketOptLevel so)
+ v
if rc /= (0::Int)
then constructErrorAndFail "setSocketOption"
else return ()
-> SocketOption -- Option Name
-> IO Int -- Option Value
getSocketOption (MkSocket s _ _ _ _) so = do
- rc <- _ccall_ getSocketOption__ s (packSocketOption so)
+ rc <- _ccall_ getSocketOption__ s
+ (packSocketOption so)
+ (socketOptLevel so)
if rc == -1 -- let's just hope that value isn't taken..
then constructErrorAndFail "getSocketOption"
else return rc