Skip to content

Commit 56bbb6d

Browse files
committed
Using CULong for CSocket and proper typing
1 parent ebd1cc6 commit 56bbb6d

File tree

8 files changed

+28
-24
lines changed

8 files changed

+28
-24
lines changed

Network/Socket/Buffer.hsc

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ socket2FD :: Socket -> IO FD
7171
socket2FD s = do
7272
fd <- unsafeFdSocket s
7373
-- HACK, 1 means True
74-
return $ FD{ fdFD = fd, fdIsSocket_ = 1 }
74+
-- TODO: remove fromIntegral for WinIO
75+
return $ FD{ fdFD = fromIntegral fd, fdIsSocket_ = 1 }
7576
#endif
7677

7778
-- | Send data to the socket. The socket must be connected to a remote
@@ -298,27 +299,27 @@ recvBufMsg s bufsizs clen flags = do
298299

299300
#if !defined(mingw32_HOST_OS)
300301
foreign import ccall unsafe "send"
301-
c_send :: CInt -> Ptr a -> CSize -> CInt -> IO CInt
302+
c_send :: CSocket -> Ptr a -> CSize -> CInt -> IO CInt
302303
foreign import ccall unsafe "sendmsg"
303-
c_sendmsg :: CInt -> Ptr (MsgHdr sa) -> CInt -> IO CInt -- fixme CSsize
304+
c_sendmsg :: CSocket -> Ptr (MsgHdr sa) -> CInt -> IO CInt -- fixme CSsize
304305
foreign import ccall unsafe "recvmsg"
305-
c_recvmsg :: CInt -> Ptr (MsgHdr sa) -> CInt -> IO CInt
306+
c_recvmsg :: CSocket -> Ptr (MsgHdr sa) -> CInt -> IO CInt
306307
#else
307308
foreign import CALLCONV SAFE_ON_WIN "ioctlsocket"
308-
c_ioctlsocket :: CInt -> CLong -> Ptr CULong -> IO CInt
309+
c_ioctlsocket :: CSocket -> CLong -> Ptr CULong -> IO CInt
309310
foreign import CALLCONV SAFE_ON_WIN "WSAGetLastError"
310311
c_WSAGetLastError :: IO CInt
311312
foreign import CALLCONV SAFE_ON_WIN "WSASendMsg"
312313
-- fixme Handle for SOCKET, see #426
313-
c_sendmsg :: CInt -> Ptr (MsgHdr sa) -> DWORD -> LPDWORD -> Ptr () -> Ptr () -> IO CInt
314+
c_sendmsg :: CSocket -> Ptr (MsgHdr sa) -> DWORD -> LPDWORD -> Ptr () -> Ptr () -> IO CInt
314315
foreign import CALLCONV SAFE_ON_WIN "WSARecvMsg"
315-
c_recvmsg :: CInt -> Ptr (MsgHdr sa) -> LPDWORD -> Ptr () -> Ptr () -> IO CInt
316+
c_recvmsg :: CSocket -> Ptr (MsgHdr sa) -> LPDWORD -> Ptr () -> Ptr () -> IO CInt
316317
#endif
317318

318319
foreign import ccall unsafe "recv"
319-
c_recv :: CInt -> Ptr CChar -> CSize -> CInt -> IO CInt
320+
c_recv :: CSocket -> Ptr CChar -> CSize -> CInt -> IO CInt
320321
foreign import CALLCONV SAFE_ON_WIN "sendto"
321-
c_sendto :: CInt -> Ptr a -> CSize -> CInt -> Ptr sa -> CInt -> IO CInt
322+
c_sendto :: CSocket -> Ptr a -> CSize -> CInt -> Ptr sa -> CInt -> IO CInt
322323
foreign import CALLCONV SAFE_ON_WIN "recvfrom"
323-
c_recvfrom :: CInt -> Ptr a -> CSize -> CInt -> Ptr sa -> Ptr CInt -> IO CInt
324+
c_recvfrom :: CSocket -> Ptr a -> CSize -> CInt -> Ptr sa -> Ptr CInt -> IO CInt
324325

Network/Socket/Fcntl.hs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
module Network.Socket.Fcntl where
44

5+
import Network.Socket.Types
56
import qualified System.Posix.Internals
67

78
#if !defined(mingw32_HOST_OS)
@@ -11,15 +12,16 @@ import Network.Socket.Imports
1112

1213
-- | Set the nonblocking flag on Unix.
1314
-- On Windows, nothing is done.
14-
setNonBlockIfNeeded :: CInt -> IO ()
15+
setNonBlockIfNeeded :: CSocket -> IO ()
1516
setNonBlockIfNeeded fd =
16-
System.Posix.Internals.setNonBlockingFD fd True
17+
System.Posix.Internals.setNonBlockingFD (fromIntegral fd) True
18+
-- TODO: remove fromIntegral for WinIO
1719

1820
-- | Set the close_on_exec flag on Unix.
1921
-- On Windows, nothing is done.
2022
--
2123
-- Since 2.7.0.0.
22-
setCloseOnExecIfNeeded :: CInt -> IO ()
24+
setCloseOnExecIfNeeded :: CSocket -> IO ()
2325
#if defined(mingw32_HOST_OS) || defined(ghcjs_HOST_OS)
2426
setCloseOnExecIfNeeded _ = return ()
2527
#else
@@ -28,14 +30,14 @@ setCloseOnExecIfNeeded fd = System.Posix.Internals.setCloseOnExec fd
2830

2931
#if !defined(mingw32_HOST_OS)
3032
foreign import ccall unsafe "fcntl"
31-
c_fcntl_read :: CInt -> CInt -> CInt -> IO CInt
33+
c_fcntl_read :: CSocket -> CInt -> CInt -> IO CInt
3234
#endif
3335

3436
-- | Get the close_on_exec flag.
3537
-- On Windows, this function always returns 'False'.
3638
--
3739
-- Since 2.7.0.0.
38-
getCloseOnExec :: CInt -> IO Bool
40+
getCloseOnExec :: CSocket -> IO Bool
3941
#if defined(mingw32_HOST_OS) || defined(ghcjs_HOST_OS)
4042
getCloseOnExec _ = return False
4143
#else
@@ -49,7 +51,7 @@ getCloseOnExec fd = do
4951
-- On Windows, this function always returns 'False'.
5052
--
5153
-- Since 2.7.0.0.
52-
getNonBlock :: CInt -> IO Bool
54+
getNonBlock :: CSocket -> IO Bool
5355
#if defined(mingw32_HOST_OS)
5456
-- | TODO: Query socket for async flag
5557
getNonBlock _ = return False

Network/Socket/Handle.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,10 @@ import Network.Socket.Types
2121
-- sequence with appropriate handshakes specified by the protocol.
2222

2323
-- TODO: WinIO doesn't use fd, add support
24+
-- Need to remove fromIntegral.
2425
socketToHandle :: Socket -> IOMode -> IO Handle
2526
socketToHandle s mode = invalidateSocket s err $ \oldfd -> do
26-
h <- fdToHandle' oldfd (Just GHC.IO.Device.Stream) True (show s) mode True{-bin-}
27+
h <- fdToHandle' (fromIntegral oldfd) (Just GHC.IO.Device.Stream) True (show s) mode True{-bin-}
2728
hSetBuffering h NoBuffering
2829
return h
2930
where

Network/Socket/Name.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ getSocketName s =
3535
peekSocketAddress ptr
3636

3737
foreign import CALLCONV unsafe "getpeername"
38-
c_getpeername :: CInt -> Ptr sa -> Ptr CInt -> IO CInt
38+
c_getpeername :: CSocket -> Ptr sa -> Ptr CInt -> IO CInt
3939
foreign import CALLCONV unsafe "getsockname"
40-
c_getsockname :: CInt -> Ptr sa -> Ptr CInt -> IO CInt
40+
c_getsockname :: CSocket -> Ptr sa -> Ptr CInt -> IO CInt
4141

4242
-- ---------------------------------------------------------------------------
4343
-- socketPort

Network/Socket/Options.hsc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,6 @@ instance Storable SocketTimeout where
511511
----------------------------------------------------------------
512512

513513
foreign import CALLCONV unsafe "getsockopt"
514-
c_getsockopt :: CInt -> CInt -> CInt -> Ptr a -> Ptr CInt -> IO CInt
514+
c_getsockopt :: CSocket -> CInt -> CInt -> Ptr a -> Ptr CInt -> IO CInt
515515
foreign import CALLCONV unsafe "setsockopt"
516-
c_setsockopt :: CInt -> CInt -> CInt -> Ptr a -> CInt -> IO CInt
516+
c_setsockopt :: CSocket -> CInt -> CInt -> Ptr a -> CInt -> IO CInt

Network/Socket/Shutdown.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ shutdown s stype = void $ withFdSocket s $ \fd ->
3838
c_shutdown fd $ sdownCmdToInt stype
3939

4040
foreign import CALLCONV unsafe "shutdown"
41-
c_shutdown :: CInt -> CInt -> IO CInt
41+
c_shutdown :: CSocket -> CInt -> IO CInt
4242

4343
-- | Closing a socket gracefully.
4444
-- This sends TCP FIN and check if TCP FIN is received from the peer.

Network/Socket/Syscall.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ connect :: SocketAddress sa => Socket -> sa -> IO ()
139139
connect s sa = withSocketsDo $ withSocketAddress sa $ \p_sa sz ->
140140
connectLoop s p_sa (fromIntegral sz)
141141

142-
connectLoop :: SocketAddress sa => Socket -> Ptr sa -> CSocket -> IO ()
142+
connectLoop :: SocketAddress sa => Socket -> Ptr sa -> CInt -> IO ()
143143
connectLoop s p_sa sz = withFdSocket s $ \fd -> loop fd
144144
where
145145
errLoc = "Network.Socket.connect: " ++ show s

Network/Socket/Types.hsc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ import Network.Socket.ReadShow
105105
-----------------------------------------------------------------------------
106106

107107
#if defined(mingw32_HOST_OS)
108-
type CSocket = SOCKET
108+
type CSocket = CULong
109109
#else
110110
type CSocket = CInt
111111
#endif

0 commit comments

Comments
 (0)