Skip to content

Commit 37e43d2

Browse files
committed
Merge PR #459
2 parents ef42779 + 24c0bfc commit 37e43d2

File tree

8 files changed

+701
-468
lines changed

8 files changed

+701
-468
lines changed

Network/Socket.hs

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,9 @@ module Network.Socket
134134

135135
-- * Socket options
136136
, SocketOption(SockOpt
137-
,Debug,ReuseAddr,Type,SoError,DontRoute,Broadcast
138-
,SendBuffer,RecvBuffer,KeepAlive,OOBInline,TimeToLive
139-
,MaxSegment,NoDelay,Cork,Linger,ReusePort
137+
,Debug,ReuseAddr,SoDomain,Type,SoProtocol,SoError,DontRoute
138+
,Broadcast,SendBuffer,RecvBuffer,KeepAlive,OOBInline
139+
,TimeToLive,MaxSegment,NoDelay,Cork,Linger,ReusePort
140140
,RecvLowWater,SendLowWater,RecvTimeOut,SendTimeOut
141141
,UseLoopBack,UserTimeout,IPv6Only
142142
,RecvIPv4TTL,RecvIPv4TOS,RecvIPv4PktInfo
@@ -160,11 +160,22 @@ module Network.Socket
160160
, mkSocket
161161
, socketToHandle
162162
-- ** Types of Socket
163-
, SocketType(..)
163+
, SocketType(GeneralSocketType, UnsupportedSocketType, NoSocketType
164+
, Stream, Datagram, Raw, RDM, SeqPacket)
164165
, isSupportedSocketType
165166
, getSocketType
166167
-- ** Family
167-
, Family(..)
168+
, Family(GeneralFamily, UnsupportedFamily
169+
,AF_UNSPEC,AF_UNIX,AF_INET,AF_INET6,AF_IMPLINK,AF_PUP,AF_CHAOS
170+
,AF_NS,AF_NBS,AF_ECMA,AF_DATAKIT,AF_CCITT,AF_SNA,AF_DECnet
171+
,AF_DLI,AF_LAT,AF_HYLINK,AF_APPLETALK,AF_ROUTE,AF_NETBIOS
172+
,AF_NIT,AF_802,AF_ISO,AF_OSI,AF_NETMAN,AF_X25,AF_AX25,AF_OSINET
173+
,AF_GOSSIP,AF_IPX,Pseudo_AF_XTP,AF_CTF,AF_WAN,AF_SDL,AF_NETWARE
174+
,AF_NDD,AF_INTF,AF_COIP,AF_CNT,Pseudo_AF_RTIP,Pseudo_AF_PIP
175+
,AF_SIP,AF_ISDN,Pseudo_AF_KEY,AF_NATM,AF_ARP,Pseudo_AF_HDRCMPLT
176+
,AF_ENCAP,AF_LINK,AF_RAW,AF_RIF,AF_NETROM,AF_BRIDGE,AF_ATMPVC
177+
,AF_ROSE,AF_NETBEUI,AF_SECURITY,AF_PACKET,AF_ASH,AF_ECONET
178+
,AF_ATMSVC,AF_IRDA,AF_PPPOX,AF_WANPIPE,AF_BLUETOOTH,AF_CAN)
168179
, isSupportedFamily
169180
, packFamily
170181
, unpackFamily

Network/Socket/Imports.hs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ module Network.Socket.Imports (
77
, module Data.Maybe
88
, module Data.Monoid
99
, module Data.Ord
10-
, module Data.Typeable
1110
, module Data.Word
1211
, module Foreign.C.String
1312
, module Foreign.C.Types
@@ -24,7 +23,6 @@ import Data.List
2423
import Data.Maybe
2524
import Data.Monoid
2625
import Data.Ord
27-
import Data.Typeable
2826
import Data.Word
2927
import Foreign.C.String
3028
import Foreign.C.Types

Network/Socket/Info.hsc

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
{-# LANGUAGE CPP #-}
2-
{-# LANGUAGE DeriveDataTypeable #-}
32
{-# LANGUAGE RecordWildCards #-}
43
{-# OPTIONS_GHC -fno-warn-orphans #-}
54

@@ -63,7 +62,7 @@ data AddrInfoFlag =
6362
-- addresses are found, IPv6-mapped IPv4 addresses will be
6463
-- returned. (Only some platforms support this.)
6564
| AI_V4MAPPED
66-
deriving (Eq, Read, Show, Typeable)
65+
deriving (Eq, Read, Show)
6766

6867
aiFlagMapping :: [(AddrInfoFlag, CInt)]
6968

@@ -106,7 +105,7 @@ data AddrInfo = AddrInfo {
106105
, addrProtocol :: ProtocolNumber
107106
, addrAddress :: SockAddr
108107
, addrCanonName :: Maybe String
109-
} deriving (Eq, Show, Typeable)
108+
} deriving (Eq, Show)
110109

111110
instance Storable AddrInfo where
112111
sizeOf _ = #const sizeof(struct addrinfo)
@@ -124,18 +123,17 @@ instance Storable AddrInfo where
124123
then return Nothing
125124
else Just <$> peekCString ai_canonname_ptr
126125

127-
socktype <- unpackSocketType' "AddrInfo.peek" ai_socktype
128126
return $ AddrInfo {
129127
addrFlags = unpackBits aiFlagMapping ai_flags
130128
, addrFamily = unpackFamily ai_family
131-
, addrSocketType = socktype
129+
, addrSocketType = unpackSocketType ai_socktype
132130
, addrProtocol = ai_protocol
133131
, addrAddress = ai_addr
134132
, addrCanonName = ai_canonname
135133
}
136134

137135
poke p (AddrInfo flags family sockType protocol _ _) = do
138-
c_stype <- packSocketTypeOrThrow "AddrInfo.poke" sockType
136+
let c_stype = packSocketType sockType
139137

140138
(#poke struct addrinfo, ai_flags) p (packBits aiFlagMapping flags)
141139
(#poke struct addrinfo, ai_family) p (packFamily family)
@@ -171,7 +169,7 @@ data NameInfoFlag =
171169
-- looked up. Instead, a numeric representation of the
172170
-- service is returned.
173171
| NI_NUMERICSERV
174-
deriving (Eq, Read, Show, Typeable)
172+
deriving (Eq, Read, Show)
175173

176174
niFlagMapping :: [(NameInfoFlag, CInt)]
177175

Network/Socket/Options.hsc

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
{-# LANGUAGE CPP #-}
2-
{-# LANGUAGE DeriveDataTypeable #-}
32
{-# LANGUAGE PatternSynonyms #-}
43
{-# LANGUAGE ScopedTypeVariables #-}
54
{-# LANGUAGE ViewPatterns #-}
@@ -9,8 +8,8 @@
98

109
module Network.Socket.Options (
1110
SocketOption(SockOpt
12-
,Debug,ReuseAddr,Type,SoError,DontRoute,Broadcast
13-
,SendBuffer,RecvBuffer,KeepAlive,OOBInline,TimeToLive
11+
,Debug,ReuseAddr,SoDomain,Type,SoProtocol,SoError,DontRoute
12+
,Broadcast,SendBuffer,RecvBuffer,KeepAlive,OOBInline,TimeToLive
1413
,MaxSegment,NoDelay,Cork,Linger,ReusePort
1514
,RecvLowWater,SendLowWater,RecvTimeOut,SendTimeOut
1615
,UseLoopBack,UserTimeout,IPv6Only
@@ -53,8 +52,7 @@ isSupportedSocketOption opt = opt /= SockOpt (-1) (-1)
5352
--
5453
-- Since: 3.0.1.0
5554
getSocketType :: Socket -> IO SocketType
56-
getSocketType s = (fromMaybe NoSocketType . unpackSocketType . fromIntegral)
57-
<$> getSocketOption s Type
55+
getSocketType s = unpackSocketType <$> getSockOpt s Type
5856

5957
#ifdef SOL_SOCKET
6058
-- | SO_DEBUG
@@ -71,13 +69,31 @@ pattern ReuseAddr = SockOpt (#const SOL_SOCKET) (#const SO_REUSEADDR)
7169
#else
7270
pattern ReuseAddr = SockOpt (-1) (-1)
7371
#endif
74-
-- | SO_TYPE
72+
73+
-- | SO_DOMAIN, read-only
74+
pattern SoDomain :: SocketOption
75+
#ifdef SO_DOMAIN
76+
pattern SoDomain = SockOpt (#const SOL_SOCKET) (#const SO_DOMAIN)
77+
#else
78+
pattern SoDomain = SockOpt (-1) (-1)
79+
#endif
80+
81+
-- | SO_TYPE, read-only
7582
pattern Type :: SocketOption
7683
#ifdef SO_TYPE
7784
pattern Type = SockOpt (#const SOL_SOCKET) (#const SO_TYPE)
7885
#else
7986
pattern Type = SockOpt (-1) (-1)
8087
#endif
88+
89+
-- | SO_PROTOCOL, read-only
90+
pattern SoProtocol :: SocketOption
91+
#ifdef SO_PROTOCOL
92+
pattern SoProtocol = SockOpt (#const SOL_SOCKET) (#const SO_PROTOCOL)
93+
#else
94+
pattern SoProtocol = SockOpt (-1) (-1)
95+
#endif
96+
8197
-- | SO_ERROR
8298
pattern SoError :: SocketOption
8399
#ifdef SO_ERROR

Network/Socket/Shutdown.hs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
{-# LANGUAGE CPP #-}
2-
{-# LANGUAGE DeriveDataTypeable #-}
32

43
#include "HsNetDef.h"
54

@@ -27,7 +26,6 @@ import Network.Socket.Types
2726
data ShutdownCmd = ShutdownReceive
2827
| ShutdownSend
2928
| ShutdownBoth
30-
deriving Typeable
3129

3230
sdownCmdToInt :: ShutdownCmd -> CInt
3331
sdownCmdToInt ShutdownReceive = 0

Network/Socket/Syscall.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ socket family stype protocol = E.bracketOnError create c_close $ \fd -> do
8484
return s
8585
where
8686
create = do
87-
c_stype <- modifyFlag <$> packSocketTypeOrThrow "socket" stype
87+
let c_stype = modifyFlag $ packSocketType stype
8888
throwSocketErrorIfMinus1Retry "Network.Socket.socket" $
8989
c_socket (packFamily family) c_stype protocol
9090

0 commit comments

Comments
 (0)