'T      !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnop q r s t u v w x y z { | } ~    (c) Lars Petersen 2015MITinfo@lars-petersen.net experimentalNoneIUse the # instance to combine several flags: !mconcat [msgNoSignal, msgWaitAll]Use the ) instance to check whether a flag is set: .if flags .&. msgEndOfRecord /= mempty then ... MSG_EOR  MSG_NOSIGNALSuppresses the generation of PIPEA signals when writing to a socket that is no longer connected.FAlthough this flag is POSIX, it is not available on all platforms. Try msgNoSignal /= memptyin order to check whether this flag is defined on a certain platform. It is safe to just use this constant even if it might not have effect on a certain target platform. The platform independence of this flag is therefore fulfilled to some extent.9Some more explanation on the platform specific behaviour:Linux defines and supports  MSG_NOSIGNALL and properly suppresses the generation of broken pipe-related signals.AWindows does not define it, but does not generate signals either.&OSX does not define it, but generates PIPEs signals. The GHC runtime ignores them if you don't hook them explicitly. The non-portable socket option  SO_NOSIGPIPE8 may be used disable signals on a per-socket basis. MSG_OOB  MSG_WAITALL  (c) Lars Petersen 2015MITinfo@lars-petersen.net experimentalNone0I'  !"#$%&'()%  !"#$%&'()&  !"#$%&'() None+2Blocks until a socket should be tried for reading. safeSocketWaitRead = do wait <- withMVar msock $ \sock-> do -- Register while holding a lock on the socket descriptor. unsafeSocketWaitRead sock 0 -- Do the waiting without keeping the socket descriptor locked. wait*+Socket descriptor\How many times has it been tried unsuccessfully so far? (currently only relevant on Windows)GThe outer action registers the waiting, the inner does the actual wait.*+*+(c) Lars Petersen 2015MITinfo@lars-petersen.net experimentalNoneDR,  SO_REUSEADDR. SO_ERROR9The 9 type is a  Ohttps://wiki.haskell.org/GHC/Type_families#Detailed_definition_of_data_families data family. This allows to provide different data constructors depending on the socket family wihtout knowing all of them in advance or the need to patch this core library. SocketAddressInet inetLoopback 8080 :: SocketAddress Inet SocketAddressInet6 inet6Loopback 8080 0 0 :: SocketAddress Inet6:A generic socket type. Use  to create a new socket.The socket is just an !-wrapped file descriptor. The  constructor is exported trough the unsafe module in order to make this library easily extensible, but it is usually not necessary nor advised to work directly on the file descriptor. If you do, the following rules must be obeyed:Make sure not to deadlock. Use  or similar. The lock must not~ be held during a blocking call. This would make it impossible to send and receive simultaneously or to close the socket. The lock must be held when calling operations that use the file descriptor. Otherwise the socket might get closed or even reused by another thread/capability which might result in reading from or writing totally different connection. This is a security nightmare!The socket is non-blocking and all the code relies on that assumption. You need to use GHC's eventing mechanism primitives to block until something happens. The former rules forbid to use _ as it does not separate between registering the file descriptor (for which the lock must: be held) and the actual waiting (for which you must not hold the lock). Also see  Jhttps://mail.haskell.org/pipermail/haskell-cafe/2014-September/115823.htmlthisX thread and read the library code to see how the problem is currently circumvented.,-./0123456789:;<=,-./0123456789:;<= ,-./0123456789:;<=(c) Lars Petersen 2015MITinfo@lars-petersen.net experimentalNone>?>>?>?(c) Lars Petersen 2015MITinfo@lars-petersen.net experimentalNone@A@@A@A(c) Lars Petersen 2015MITinfo@lars-petersen.net experimentalNoneBCBBCBC(c) Lars Petersen 2015MITinfo@lars-petersen.net experimentalNoneDEDDEDE(c) Lars Petersen 2015MITinfo@lars-petersen.net experimentalNoneFGFFGFG(c) Lars Petersen 2015MITinfo@lars-petersen.net experimentalNoneHIJKL *+:;<=HIJKL :;HIJK=<+*LHIJKL(c) Lars Petersen 2015MITinfo@lars-petersen.net experimentalNone9;DIRM  IPV6_V6ONLYRITo avoid errors with endianess it was decided to keep this type abstract.Hint: Use the  instance if you really need to access. It exposes it exactly as found within an IP packet (big endian if you insist on interpreting it as a number).Another hint: Use 0 for parsing and suppress nameserver lookups: > getAddressInfo (Just "::1") Nothing aiNumericHost :: IO [AddressInfo SocketAddressInet6 Stream TCP] [AddressInfo { addressInfoFlags = AddressInfoFlags 4, socketAddress = SocketAddressInet6 {inet6Address = Inet6Address 0000:0000:0000:0000:0000:0000:0000:0001, inet6Port = Inet6Port 0, inet6FlowInfo = Inet6FlowInfo 0, inet6ScopeId = Inet6ScopeId 0}, canonicalName = Nothing }]SThe  "https://en.wikipedia.org/wiki/IPv4Internet Protocol version 4.T ::U ::1An  "https://en.wikipedia.org/wiki/IPv6IPv6 socket address.ZThe socket address contains a port number that may be used by transport protocols like  ;https://en.wikipedia.org/wiki/Transmission_Control_ProtocolTCP. )SocketAddressInet6 inet6Loopback 8080 0 0)MNOPQRSTUVWXYZ[\]9MNOPQRSTU SRQPO9TUMNMNOPQRSTUVWXYZ[\] (c) Lars Petersen 2015MITinfo@lars-petersen.net experimentalNone9;DIR qITo avoid errors with endianess it was decided to keep this type abstract.Hint: Use the  instance if you really need to access. It exposes it exactly as found within an IP packet (big endian if you insist on interpreting it as a number).Another hint: Use 0 for parsing and suppress nameserver lookups:  > getAddressInfo (Just "127.0.0.1") Nothing aiNumericHost :: IO [AddressInfo Inet Stream TCP] [AddressInfo {addressInfoFlags = AddressInfoFlags 4, socketAddress = SocketAddressInet {inetAddress = InetAddress 127.0.0.1, inetPort = InetPort 0}, canonicalName = Nothing}]rThe  "https://en.wikipedia.org/wiki/IPv4Internet Protocol version 4.s 0.0.0.0t 255.255.255.255u 255.255.255.255v  127.0.0.1w  224.0.0.0x  224.0.0.1y  224.0.0.255An  "https://en.wikipedia.org/wiki/IPv4IPv4 socket address.ZThe socket address contains a port number that may be used by transport protocols like  ;https://en.wikipedia.org/wiki/Transmission_Control_ProtocolTCP. #SocketAddressInet inetLoopback 8080pqrstuvwxyz{|}~9pqrstuvwxy rqp9xstvyuwpqrstuvwxyz{|}~(c) Lars Petersen 2015MITinfo@lars-petersen.net experimentalNone /0:DIRT3Maps addresses to readable host- and service names.The operation throws s. |> getNameInfo (SocketAddressInet inetLoopback 80) mempty NameInfo {hostName = "localhost.localdomain", serviceName = "http"}A # consists of host and service name.-Maps names to addresses (i.e. by DNS lookup).The operation throws s.Contrary to the underlying  getaddrinfo operation this wrapper is typesafe and thus only returns records that match the address, type and protocol encoded in the type. This is the price we have to pay for typesafe sockets and extensibility.If you need different types of records, you need to start several queries. If you want to connect to both IPv4 and IPV6 addresses use  and use IPv6-sockets. getAddressInfo (Just "www.haskell.org") (Just "https") mempty :: IO [AddressInfo Inet Stream TCP] > [AddressInfo {addressInfoFlags = AddressInfoFlags 0, socketAddress = SocketAddressInet {inetAddress = InetAddress 162.242.239.16, inetPort = InetPort 443}, canonicalName = Nothing}] > getAddressInfo (Just "www.haskell.org") (Just "80") aiV4Mapped :: IO [AddressInfo Inet6 Stream TCP] [AddressInfo { addressInfoFlags = AddressInfoFlags 8, socketAddress = SocketAddressInet6 {inet6Address = Inet6Address 2400:cb00:2048:0001:0000:0000:6ca2:cc3c, inet6Port = Inet6Port 80, inet6FlowInfo = Inet6FlowInfo 0, inet6ScopeId = Inet6ScopeId 0}, canonicalName = Nothing }] &> getAddressInfo (Just "darcs.haskell.org") Nothing aiV4Mapped :: IO [AddressInfo Inet6 Stream TCP] [AddressInfo { addressInfoFlags = AddressInfoFlags 8, socketAddress = SocketAddressInet6 {inet6Address = Inet6Address 0000:0000:0000:0000:0000:ffff:17fd:e1ad, inet6Port = Inet6Port 0, inet6FlowInfo = Inet6FlowInfo 0, inet6ScopeId = Inet6ScopeId 0}, canonicalName = Nothing }] > getAddressInfo (Just "darcs.haskell.org") Nothing mempty :: IO [AddressInfo Inet6 Stream TCP] *** Exception: AddressInfoException "Name or service not known"Use the # instance to combine several flags: 6mconcat [niNameRequired, niNoFullyQualifiedDomainName]Use the # instance to combine several flags: %mconcat [aiAddressConfig, aiV4Mapped]9Contains the error code that can be matched against. Use 5 to get a human readable explanation of the error.A wrapper around  gai_strerror. ;AddressInfoException "Temporary failure in name resolution" -AddressInfoException "Bad value for ai_flags" AAddressInfoException "Non-recoverable failure in name resolution" .AddressInfoException "ai_family not supported" 0AddressInfoException "Memory allocation failure" ,AddressInfoException "No such host is known" =AddressInfoException "Servname not supported for ai_socktype" 0AddressInfoException "ai_socktype not supported" #AddressInfoException "System error" AI_ADDRCONFIG:AI_ALL: Return both IPv4 (as mapped ) and IPv6 addresses when D is set independent of whether IPv6 addresses exist for this name. AI_CANONNAME:AI_NUMERICHOST:AI_NUMERICSERV: AI_PASSIVE: AI_V4MAPPEDL: Return mapped IPv4 addresses if no IPv6 addresses could be found or if  flag is set. NI_NAMEREQD:: Throw an exception if the hostname cannot be determined.NI_DGRAM": Service is datagram based (i.e. !) rather than stream based (i.e. ). NI_NOFQDNS: Return only the hostname part of the fully qualified domain name for local hosts.NI_NUMERICHOST.: Return the numeric form of the host address.NI_NUMERICSERV1: Return the numeric form of the service address.3('(c) Lars Petersen 2015MITinfo@lars-petersen.net experimentalNone:DRT Creates a new socket.Whereas the underlying POSIX socket operation takes 3 parameters, this library encodes this information in the type variables. This rules out several kinds of errors and escpecially simplifies the handling of addresses (by using associated type families). Examples: -- create a IPv4-UDP-datagram socket sock <- socket :: IO (Socket Inet Datagram UDP) -- create a IPv6-TCP-streaming socket sock6 <- socket :: IO (Socket Inet6 Stream TCP)1This operation sets up a finalizer that automatically closes the socket when the garbage collection decides to collect it. This is just a fail-safe. You might still run out of file descriptors as there's no guarantee about when the finalizer is run. You're advised to manually @ the socket when it's no longer needed. If possible, use o to reliably close the socket descriptor on exception or regular termination of your computation: result <- bracket (socket :: IO (Socket Inet6 Stream TCP)) close $ \sock-> do somethingWith sock -- your computation here return somethingelseThis operation configures the socket non-blocking to work seamlessly with the runtime system's event notification mechanism.dThis operation can safely deal with asynchronous exceptions without leaking file descriptors.This operation throws s. Consult your man& page for details and specific errnos.Connects to a remote address.This operation returns as soon as a connection has been established (as if the socket were blocking). The connection attempt has either failed or succeeded after this operation threw an exception or returned.4The socket is locked throughout the whole operation.The operation throws  s. Calling  on a d socket throws  = even if the former file descriptor has been reassigned.Bind a socket to an address.Calling  on a d socket throws  8 even if the former file descriptor has been reassigned.It is assumed that  never blocks and therefore ), ( and % don't occur. This assumption is supported by the fact that the Linux manpage doesn't mention any of these errors, the Posix manpage doesn't mention the last one and even MacOS' implementation will never fail with any of these when the socket is configured non-blocking as  #http://stackoverflow.com/a/14485305 argued here.This operation throws s. Consult your man$ page for details and specific errnos.QStarts listening and queueing connection requests on a connection-mode socket.Calling  on a d socket throws  = even if the former file descriptor has been reassigned.The second parameter is called backlogq and sets a limit on how many unaccepted connections the socket implementation shall queue. A value of 0+ leaves the decision to the implementation.This operation throws s. Consult your man$ page for details and specific errnos.Accept a new connection.Calling  on a d socket throws  = even if the former file descriptor has been reassigned.AThis operation configures the new socket non-blocking (TODO: use accept4 if available).@This operation sets up a finalizer for the new socket that automatically closes the new socket when the garbage collection decides to collect it. This is just a fail-safe. You might still run out of file descriptors as there's no guarantee about when the finalizer is run. You're advised to manually ' the socket when it's no longer needed.This operation throws s. Consult your man$ page for details and specific errnos.This operation catches  ,   and + internally and retries automatically.%Send a message on a connected socket.Calling  on a d socket throws  = even if the former file descriptor has been reassigned.3The operation returns the number of bytes sent. On Datagram and SequentialPacket3 sockets certain assurances on atomicity exist and   or  J are returned until the whole message would fit into the send buffer.This operation throws  s. Consult  man 3p send for details and specific errnos. ,   and  and handled internally and won't be thrown. For performance reasons the operation first tries a write on the socket and then waits when it got   or  .Like ., but allows to specify a destination address.(Receive a message on a connected socket.Calling  on a d socket throws  8 even if the former file descriptor has been reassigned.rThe operation takes a buffer size in bytes a first parameter which limits the maximum length of the returned .This operation throws  s. Consult man 3p receive for details and specific errnos. ,   and  and handled internally and won't be thrown. For performance reasons the operation first tries a read on the socket and then waits when it got   or  .Like +, but additionally yields the peer address.Closes a socket.This operation is idempotent and thus can be performed more than once without throwing an exception. If it throws an exception it is presumably a not recoverable situation and the process should exit.This operation does not block.This operation wakes up all threads that are currently blocking on this socket. All other threads are guaranteed not to block on operations on this socket in the future. Threads that perform operations other than  on this socket will fail with  ( after the socket has been closed ( replaces the  in the  with -13 to reliably avoid use-after-free situations)."This operation potentially throws s (only EIO is documented). E is catched internally and retried automatically, so won't be thrown. i  !"#$%&'(),-./0123456789:i:9785634012./,-  !"#$%&'() (c) Lars Petersen 2015MITinfo@lars-petersen.net experimentalNoneLike , but operates on lazy Hs and continues until all data has been sent or an exception occured.Like , but operates on lazy s and continues until either an empty part has been received (peer closed the connection) or given buffer limit has been exceeded or an exception occured.The  parameter is a soft limit on how many bytes to receive. Collection is stopped if the limit has been exceeded. The result might be up to one internal buffer size longer than the given limit. If the returned us length is lower or eqal than the limit, the data has not been truncated and the transmission is complete.   ! " # # $ % & ' ( ) * + , - . / 0 1 2 3 4 5 6 7 8 9 : ; < = > ? @ A B C D E F G HIIJJKLMNOPQRSTUVWXYZ[\]^_`abcddefghijklmnopqrstuvwxyz{|}~    m t u       efgh           %socket-0.6.1.0-Jqx8G6Vxk6S4SjRXESQeS8 System.SocketSystem.Socket.UnsafeSystem.Socket.Family.Inet6System.Socket.Protocol.TCPSystem.Socket.Protocol.UDPSystem.Socket.Type.DatagramSystem.Socket.Type.Raw#System.Socket.Type.SequentialPacketSystem.Socket.Family.InetSystem.Socket.Type.StreamSystem.Socket.Internal.Message System.Socket.Internal.ExceptionSystem.Socket.Internal.PlatformSystem.Socket.Internal.SocketsocketSocketGHC.ConcthreadWaitReadgetAddressInfo"System.Socket.Internal.AddressInfoUDPTCPData.ByteString ByteStringSystem.Posix.TypesFdControl.Concurrent.MVarMVarData.ByteString.Lazy MessageFlagsmsgEndOfRecord msgNoSignal msgOutOfBand msgWaitAllSocketExceptioneOk eInterruptedeBadFileDescriptoreInvalidePipe eWouldBlockeAgain eNotSocketeDestinationAddressRequired eMessageSize eProtocolTypeeNoProtocolOptioneProtocolNotSupportedeSocketTypeNotSupportedeOperationNotSupportedeProtocolFamilyNotSupportedeAddressFamilyNotSupported eAddressInUseeAddressNotAvailable eNetworkDowneNetworkUnreachable eNetworkReseteConnectionAbortedeConnectionReseteNoBufferSpace eIsConnected eNotConnected eShutdowneTooManyReferences eTimedOuteConnectionRefused eHostDowneHostUnreachableeAlready eInProgressunsafeSocketWaitWriteunsafeSocketWaitRead ReuseAddressError SocketOptiongetSocketOptionsetSocketOptionProtocolprotocolNumberType typeNumberFamily familyNumber SocketAddressunsafeSetSocketOptionunsafeGetSocketOption $fProtocolTCP $fProtocolUDPDatagram$fTypeDatagramRaw $fTypeRawSequentialPacket$fTypeSequentialPacket unsafeSend unsafeSendTo unsafeReceiveunsafeReceiveFromtryWaitRetryLoopV6Only Inet6ScopeId Inet6FlowInfo Inet6Port Inet6AddressInet6inet6Any inet6Loopback$fSocketOptionV6Only$fStorableSocketAddress$fStorableInet6ScopeId$fStorableInet6FlowInfo$fStorableInet6Port$fStorableInet6Address$fShowInet6Address $fFamilyInet6$fEqSocketAddress$fShowSocketAddress$fEqInet6Address $fEqInet6Port$fOrdInet6Port$fShowInet6Port$fNumInet6Port$fEqInet6FlowInfo$fOrdInet6FlowInfo$fShowInet6FlowInfo$fNumInet6FlowInfo$fEqInet6ScopeId$fOrdInet6ScopeId$fShowInet6ScopeId$fNumInet6ScopeId $fEqV6Only $fOrdV6Only $fShowV6OnlyInetPort InetAddressInetinetAny inetBroadcastinetNone inetLoopbackinetUnspecificGroupinetAllHostsGroupinetMaxLocalGroup$fStorableInetAddress$fStorableInetPort$fShowInetAddress $fFamilyInet$fEqInetAddress $fEqInetPort $fOrdInetPort$fShowInetPort $fNumInetPort HasNameInfo getNameInfoNameInfohostName serviceNameHasAddressInfo NameInfoFlagsAddressInfoFlagsAddressInfoException AddressInfoaddressInfoFlags socketAddress canonicalNameeaiAgain eaiBadFlagseaiFail eaiFamily eaiMemory eaiNoName eaiService eaiSocketType eaiSystemaiAddressConfigaiAllaiCanonicalName aiNumericHostaiNumericService aiPassive aiV4MappedniNameRequired niDatagramniNoFullyQualifiedDomainName niNumericHostniNumericServiceconnectbindlistenacceptsendsendToreceive receiveFromcloseStreamsendAll receiveAll $fTypeStreambaseGHC.BaseMonoid Data.BitsBitsMessage$fShowMessageFlags$fMonoidMessageFlags$fShowSocketException$fExceptionSocketExceptionCSSizec_gai_strerror c_getnameinfoc_freeaddrinfo c_getaddrinfoc_memset c_setsockopt c_getsockopt c_recvfromc_recvc_sendtoc_sendc_listenc_accept c_connectc_bindc_closec_socketunsafeSocketWaitConnectedGHC.MVarwithMVar$fSocketOptionReuseAddress$fSocketOptionErrorForeign.StorableStorableD:R:SocketAddressInet60SocketAddressInet6 inet6Address inet6Port inet6FlowInfo inet6ScopeIdw64_0w64_1w64_2w64_3w64_4w64_5w64_6w64_7w32_0w32_1w32_2w32_3w16_0w16_1D:R:SocketAddressInet0SocketAddressInet inetAddressinetPortGHC.Showshow gaiStrerrorgetAddressInfo' getNameInfo'$fHasNameInfoInet6$fHasNameInfoInet$fHasAddressInfoInet6$fHasAddressInfoInet$fMonoidNameInfoFlags$fMonoidAddressInfoFlags$fExceptionAddressInfoException$fShowAddressInfoExceptionControl.Exception.BasebracketGHC.IntInt64