Skip to content

Commit

Permalink
Support abstract unix sockets
Browse files Browse the repository at this point in the history
  • Loading branch information
kolmodin committed Mar 26, 2008
1 parent ec041a2 commit 8cd9250
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions Network/Socket.hsc
Expand Up @@ -201,7 +201,7 @@ import Foreign.C.Error
import Foreign.C.String ( CString, withCString, peekCString, peekCStringLen, castCharToCChar )
import Foreign.C.Types ( CInt, CUInt, CChar, CSize )
import Foreign.Marshal.Alloc ( alloca, allocaBytes )
import Foreign.Marshal.Array ( peekArray, pokeArray0 )
import Foreign.Marshal.Array ( peekArray, pokeArray, pokeArray0 )
import Foreign.Marshal.Utils ( maybeWith, with )

import System.IO
Expand Down Expand Up @@ -506,7 +506,8 @@ pokeSockAddr p (SockAddrUnix path) = do
#endif
(#poke struct sockaddr_un, sun_family) p ((#const AF_UNIX) :: CSaFamily)
let pathC = map castCharToCChar path
pokeArray0 0 ((#ptr struct sockaddr_un, sun_path) p) pathC
poker = case path of ('\0':_) -> pokeArray; _ -> pokeArray0 0
poker ((#ptr struct sockaddr_un, sun_path) p) pathC
#endif
pokeSockAddr p (SockAddrInet (PortNum port) addr) = do
#if defined(darwin_TARGET_OS)
Expand Down Expand Up @@ -572,7 +573,10 @@ sizeOfSockAddr_Family AF_INET = #const sizeof(struct sockaddr_in)

-- size of struct sockaddr by SockAddr
#if defined(DOMAIN_SOCKET_SUPPORT)
sizeOfSockAddr (SockAddrUnix _) = #const sizeof(struct sockaddr_un)
sizeOfSockAddr (SockAddrUnix path) =
case path of
'\0':_ -> (#const sizeof(sa_family_t)) + length path
_ -> #const sizeof(struct sockaddr_un)
#endif
sizeOfSockAddr (SockAddrInet _ _) = #const sizeof(struct sockaddr_in)
#if defined(IPV6_SOCKET_SUPPORT)
Expand Down

0 comments on commit 8cd9250

Please sign in to comment.