W                     ! " # $ % & ' ( ) * + , - . / 0 1 2 3 4 5 6 7 8 9 : ; < = > ? @ A B C D E F G HIJKL M N O P Q R S T U V  Safe-Inferred3=KWW Safe-Inferred Safe-Inferred Safe-Inferred Safe-Inferred3=K     Safe-Inferred     Safe-Inferred     Safe-Inferred  Safe-Inferred3=K Safe-InferredUse the X# instance to combine several flags: !mconcat [msgNOSIGNAL, msgWAITALL]YY Safe-Inferred+Z[Z[ Safe-Inferred \]^_`abcdefgh \]^_`abcdefgh \]^_`abcdefgh Safe-Inferred+M Use the X# instance to combine several flags: mconcat [niNAMEREQD, niNOFQDN]Use the X# instance to combine several flags: "mconcat [aiADDRCONFIG, aiV4MAPPED]]Contains the error code that can be matched against and a readable description taken from  eia_strerr.,8Throw an exception if the hostname cannot be determined.-?Service is datagram based (UDP) rather than stream based (TCP)..QReturn only the hostname part of the fully qualified domain name for local hosts./,Return the numeric form of the host address.0/Return the numeric form of the service address.1-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. r> getAddrInfo (Just "www.haskell.org") (Just "80") aiV4MAPPED :: IO [AddrInfo SockAddrIn6 STREAM TCP] [AddrInfo {addrInfoFlags = AddrInfoFlags 8, addrAddress = "[2400:cb00:2048:0001:0000:0000:6ca2:cc3c]:80", addrCanonName = Nothing}] > getAddrInfo (Just "darcs.haskell.org") Nothing aiV4MAPPED :: IO [AddrInfo SockAddrIn6 STREAM TCP] [AddrInfo {addrInfoFlags = AddrInfoFlags 8, addrAddress = "[0000:0000:0000:0000:0000:ffff:17fd:e1ad]:0", addrCanonName = Nothing}] > getAddrInfo (Just "darcs.haskell.org") Nothing mempty :: IO [AddrInfo SockAddrIn6 STREAM TCP] *** Exception: AddrInfoException (-2) "Name or service not known"22Maps addresss to readable host- and service names.The operation throws s. R> getNameInfo (SockAddrIn 80 $ pack [23,253,242,70]) mempty ("haskell.org","http")  !"#$ijkl%&'()*+,-./012mno !"#$%&'()*+,-./012 !"#$ijkl%&'()*+,-./012mno  Safe-Inferred345pq345345345pq None6789rst678967896789rst None :;<=>?uvw:;<=>?:;<=>?:;<=>?uvwNonexyxyxy Safe-InferredF A generic socket type. Also see socket for details.The socket is just an z-wrapped file descriptor. It is exposed 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 seperate 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 [this](https:/mail.haskell.org pipermail haskell-cafes2014-September/115823.html) thread and read the library code to see how the problem is currently circumvented. @ABCDEFG|@ABCDEFG@ABCDEFG|NoneHIJKHIJKHIJKHIJK (c) Lars Petersen 2015MITinfo@lars-petersen.net experimentalNone3=KM LCreates a new socket.Whereas the underlying POSIX socket function 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 SockAddrIn DGRAM UDP) -- create a IPv6-TCP-streaming socket sock6 <- socket :: IO (Socket SockAddrIn6 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 V' the socket when it's no longer needed.This 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:  EAFNOSUPPORT#The socket domain is not supported.EMFILE$The process is out file descriptors.ENFILE#The system is out file descriptors.EPROTONOSUPPORT>The socket protocol is not supported (for this socket domain). EPROTOTYPE1The socket type is not supported by the protocol.EACCES,The process is lacking necessary privileges.ENOMEMInsufficient memory.MBind a socket to an address.Calling M on a Vd socket throws EBADF8 even if the former file descriptor has been reassigned.It is assumed that f never blocks and therefore  EINPROGRESS, EALREADY and EINTR9 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 [argued here](http:/stackoverflow.com a/14485305).The following (s are relevant and might be thrown (see man bind3 for more exceptions regarding SockAddrUn sockets):  EADDRINUSEThe address is in use. EADDRNOTAVAILThe address is not available.EBADFNot a valid file descriptor.EINVALPSocket is already bound and cannot be re-bound or the socket has been shut down.ENOBUFSInsufficient resources. EOPNOTSUPP)The socket type does not support binding.EACCES?The address is protected and the process is lacking permission.EISCONN The socket is already connected.ELOOPeMore than {SYMLOOP_MAX} symbolic links were encountered during resolution of the pathname in address. ENAMETOOLONGThe length of a pathname exceeds {PATH_MAX}, or pathname resolution of a symbolic link produced an intermediate result with a length that exceeds {PATH_MAX}.The following Ms are theoretically possible, but should not occur if the library is correct:  EAFNOSUPPORTThe address family is invalid.ENOTSOCK$The file descriptor is not a socket.EINVAL-Address length does not match address family.N/Accept connections on a connection-mode socket.Calling N on a Vd socket throws EBADF8 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: EBADF@Not a valid file descriptor (only after socket has been closed). EDESTADDRREQYThe socket is not bound and the protocol does not support listening on an unbound socket.EINVAL6The socket is already connected or has been shut down.ENOTSOCK;The file descriptor is not a socket (should be impossible). EOPNOTSUPP(The protocol does not support listening.EACCES"The process is lacking privileges.ENOBUFSInsufficient resources.OAccept a new connection.Calling O on a Vd socket throws EBADF8 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 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 V' the socket when it's no longer needed.This operation catches EAGAIN,  EWOULDBLOCK and EINTR& internally and retries automatically.This operation throws s: EBADFDNot a valid file descriptor (only after the socket has been closed). ECONNABORTEDA connection has been aborted.EINVAL&The socket is not accepting/listening.EMFILE$The process is out file descriptors.ENFILE#The system is out file descriptors.ENOBUFSNo buffer space available.ENOMEMOut of memory.ENOSOCK5Not a valid socket descriptor (should be impossible). EOPNOTSUPP7The socket type does not support accepting connections.EPROTOGeneric protocol error.PConnects to an remote address.Calling P on a Vd socket throws EBADF8 even if the former file descriptor has been reassigned.This function returns as soon as a connection has either been established or refused. A failed connection attempt does not throw an exception if EINTR or  EINPROGRESS were caught internally. The operation just unblocks and returns in this case. The approach is to just try to read or write the socket and eventually fail there instead. Also see [these considerations](http:/cr.yp.to,docs/connect.html) for an explanation. EINTR and  EINPROGRESS, are handled internally and won't be thrown.The following js are relevant and might be thrown if the OS was able to decide the connection request synchronously:  EADDRNOTAVAILThe address is not available.EBADFThe file descriptor is invalid. ECONNREFUSED7The target was not listening or refused the connection.EISCONN The socket is already connected. ENETUNREACHThe network is unreachable. ETIMEDOUT:The connect timed out before a connection was established.The following Ms are theoretically possible, but should not occur if the library is correct:  EAFNOTSUPPORT)Address family does not match the socket.ENOTSOCKThe descriptor is not a socket. EPROTOTYPE+The address type does not match the socket.Q%Send a message on a connected socket.Calling Q on a Vd socket throws EBADF8 even if the former file descriptor has been reassigned./The operation returns the number of bytes sent.EAGAIN,  EWOULDBLOCK and EINTR, and handled internally and won't be thrown. The flag  MSG_NOSIGNAL/ is set to supress signals which are pointless.The following #s are relevant and might be thrown: EBADFThe file descriptor is invalid. ECONNRESET(The peer forcibly closed the connection. EDESTADDREQ1Remote address has not been set, but is required.EMSGSIZEPThe message is too large to be sent all at once, but the protocol requires this.ENOTCONNThe socket is not connected.EPIPEKThe socket is shut down for writing or the socket is not connected anymore.EACCESS#The process is lacking permissions.EIO5An I/O error occured while writing to the filesystem.ENETDOWN$The local network interface is down. ENETUNREACHNo route to network.ENOBUFS.Insufficient resources to fulfill the request.The following Ms are theoretically possible, but should not occur if the library is correct:  EOPNOTSUPP&The specified flags are not supported.ENOTSOCK*The descriptor does not refer to a socket.RLike Q-, but continues until all data has been sent. }sendAll sock data flags = do sent <- send sock data flags when (sent < length data) $ sendAll sock (drop sent data) flagsS?Send a message on a socket with a specific destination address.Calling S on a Vd socket throws EBADF8 even if the former file descriptor has been reassigned./The operation returns the number of bytes sent.EAGAIN,  EWOULDBLOCK and EINTR, and handled internally and won't be thrown. The flag  MSG_NOSIGNAL/ is set to supress signals which are pointless.The following #s are relevant and might be thrown: EBADFThe file descriptor is invalid. ECONNRESET(The peer forcibly closed the connection. EDESTADDREQ1Remote address has not been set, but is required.EMSGSIZEPThe message is too large to be sent all at once, but the protocol requires this.ENOTCONNThe socket is not connected.EPIPEKThe socket is shut down for writing or the socket is not connected anymore.EACCESS#The process is lacking permissions. EDESTADDRREQ$The destination address is required. EHOSTUNREACH'The destination host cannot be reached.EIOAn I/O error occured.EISCONN The socket is already connected.ENETDOWNThe local network is down. ENETUNREACHNo route to the network.ENUBUFS.Insufficient resources to fulfill the request.ENOMEM+Insufficient memory to fulfill the request.ELOOPAF_UNIX only. ENAMETOOLONGAF_UNIX only.The following Ms are theoretically possible, but should not occur if the library is correct:  EAFNOTSUPP"The address family does not match. EOPNOTSUPP&The specified flags are not supported.ENOTSOCK*The descriptor does not refer to a socket.EINVALThe address len does not match.T(Receive a message on a connected socket.Calling T on a Vd socket throws EBADF8 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 .EAGAIN,  EWOULDBLOCK and EINTR, and handled internally and won't be thrown.The following #s are relevant and might be thrown: EBADFThe file descriptor is invalid. ECONNRESET(The peer forcibly closed the connection.ENOTCONNThe socket is not connected. ETIMEDOUTThe connection timed out.EIO5An I/O error occured while writing to the filesystem.ENOBUFS.Insufficient resources to fulfill the request.ENONMEM+Insufficient memory to fulfill the request.The following Ms are theoretically possible, but should not occur if the library is correct:  EOPNOTSUPP&The specified flags are not supported.ENOTSOCK*The descriptor does not refer to a socket.UFReceive a message on a socket and additionally yield the peer address.Calling U on a Vd socket throws EBADF8 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 .EAGAIN,  EWOULDBLOCK and EINTR, and handled internally and won't be thrown.The following #s are relevant and might be thrown: EBADFThe file descriptor is invalid. ECONNRESET(The peer forcibly closed the connection.ENOTCONNThe socket is not connected. ETIMEDOUTThe connection timed out.EIO5An I/O error occured while writing to the filesystem.ENOBUFS.Insufficient resources to fulfill the request.ENONMEM+Insufficient memory to fulfill the request.The following Ms are theoretically possible, but should not occur if the library is correct:  EOPNOTSUPP&The specified flags are not supported.ENOTSOCK*The descriptor does not refer to a socket.VCloses 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 V on this socket will fail with EBADF( after the socket has been closed (V replaces the  in the z with -13 to reliably avoid use-after-free situations).The following #s are relevant and might be thrown: EIO5An I/O error occured while writing to the filesystem.The following Ms are theoretically possible, but should not occur if the library is correct: EBADFThe file descriptor is invalid. LMNOPQRSTUVM  !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGLMNOPQRSTUVM !"#$12LMNOPQRSTUVFG6789:;<=>?345 DEBC@A%&'()*+,-./0 LMNOPQRSTUV} !"#$%&'()* + ,--./012233445566789:;<=>?@ABCDEFG H H I J J K L M M N O P QRRSTUVWWXYZ[ \ ] ^ _ ` a b c d e fghijklmnopqrstuvwxyz{|}~ hhsocket-0.2.0.0System.Socket.ProtocolSystem.Socket.Protocol.UDPSystem.Socket.Protocol.TCPSystem.Socket.Protocol.SCTPSystem.Socket.TypeSystem.Socket.Type.STREAMSystem.Socket.Type.DGRAMSystem.Socket.Type.SEQPACKETSystem.Socket.Address System.Socket System.Socket.Address.SockAddrUn System.Socket.Address.SockAddrIn!System.Socket.Address.SockAddrIn6System.Socket.UnsafeSystem.Socket.Internal.MsgFlags System.Socket.Internal.ExceptionSystem.Socket.Internal.FFISystem.Socket.Internal.AddrInfoSystem.Socket.Internal.EventSystem.Socket.Internal.SocketGHC.ConcthreadWaitReadData.ByteString ByteStringSystem.Posix.TypesFdProtocolprotocolNumberUDP $fProtocolUDPTCP $fProtocolTCPSCTP$fProtocolSCTPType typeNumberSTREAM $fTypeSTREAMDGRAM $fTypeDGRAM SEQPACKET$fTypeSEQPACKETAddressaddressFamilyNumberMsgFlagsmsgEOR msgNOSIGNALmsgOOB msgWAITALLSocketException NameInfoFlags AddrInfoFlagsAddrInfoExceptionAddrInfo addrInfoFlags addrAddress addrCanonName aiADDRCONFIGaiALL aiCANONNAME aiNUMERICHOST aiNUMERICSERV aiPASSIVE aiV4MAPPED niNAMEREQDniDGRAMniNOFQDN niNUMERICHOST niNUMERICSERV getAddrInfo getNameInfo SockAddrUnsunPath SockAddrInsinPortsinAddr SockAddrIn6sin6Port sin6Flowinfosin6Addr sin6ScopeId SO_ACCEPTCONN SetSockOpt setSockOpt GetSockOpt getSockOptSocket unsafeSend unsafeSendTo unsafeRecvunsafeRecvFromsocketbindlistenacceptconnectsendsendAllsendTorecvrecvFromclose $fProtocol()base Data.MonoidMonoid$fMonoidMsgFlags$fShowSocketException$fExceptionSocketExceptionc_memsetc_setnonblocking c_getsockopt c_recvfromc_recvc_sendtoc_sendc_listenc_accept c_connectc_bindc_closec_socket c_gaistrerror c_getnameinfoc_freeaddrinfo c_getaddrinfo$fMonoidNameInfoFlags$fMonoidAddrInfoFlags$fExceptionAddrInfoException$fStorableSockAddrUn$fAddressSockAddrUn$fStorableSockAddrIn$fShowSockAddrIn$fAddressSockAddrIn$fStorableSockAddrIn6$fShowSockAddrIn6$fAddressSockAddrIn6threadWaitWrite'threadWaitRead'GHC.MVarMVarControl.Concurrent.MVarwithMVar$fGetSockOptSO_ACCEPTCONN