{-# LANGUAGE CPP #-}
#include "HsNetDef.h"
moduleNetwork.Socket.Name(getPeerName ,getSocketName ,socketPort ,socketPortSafe )whereimportForeign.Marshal.Utils(with)importNetwork.Socket.Imports importNetwork.Socket.Internal importNetwork.Socket.Types -- | Getting peer's socket address.getPeerName ::SocketAddress sa =>Socket ->IOsa getPeerName :: forall sa. SocketAddress sa => Socket -> IO sa
getPeerName Socket
s =(Ptr sa -> Int -> IO sa) -> IO sa
forall sa a. SocketAddress sa => (Ptr sa -> Int -> IO a) -> IO a
withNewSocketAddress ((Ptr sa -> Int -> IO sa) -> IO sa)
-> (Ptr sa -> Int -> IO sa) -> IO sa
forall a b. (a -> b) -> a -> b
$\Ptr sa
ptr Int
sz ->CInt -> (Ptr CInt -> IO sa) -> IO sa
forall a b. Storable a => a -> (Ptr a -> IO b) -> IO b
with(Int -> CInt
forall a b. (Integral a, Num b) => a -> b
fromIntegralInt
sz )((Ptr CInt -> IO sa) -> IO sa) -> (Ptr CInt -> IO sa) -> IO sa
forall a b. (a -> b) -> a -> b
$\Ptr CInt
int_star ->Socket -> (CInt -> IO sa) -> IO sa
forall r. Socket -> (CInt -> IO r) -> IO r
withFdSocket Socket
s ((CInt -> IO sa) -> IO sa) -> (CInt -> IO sa) -> IO sa
forall a b. (a -> b) -> a -> b
$\CInt
fd ->doString -> IO CInt -> IO ()
forall a. (Eq a, Num a) => String -> IO a -> IO ()
throwSocketErrorIfMinus1Retry_ String
"Network.Socket.getPeerName"(IO CInt -> IO ()) -> IO CInt -> IO ()
forall a b. (a -> b) -> a -> b
$CInt -> Ptr sa -> Ptr CInt -> IO CInt
forall sa. CInt -> Ptr sa -> Ptr CInt -> IO CInt
c_getpeername CInt
fd Ptr sa
ptr Ptr CInt
int_star CInt
_sz <-Ptr CInt -> IO CInt
forall a. Storable a => Ptr a -> IO a
peekPtr CInt
int_star Ptr sa -> IO sa
forall sa. SocketAddress sa => Ptr sa -> IO sa
peekSocketAddress Ptr sa
ptr -- | Getting my socket address.getSocketName ::SocketAddress sa =>Socket ->IOsa getSocketName :: forall sa. SocketAddress sa => Socket -> IO sa
getSocketName Socket
s =(Ptr sa -> Int -> IO sa) -> IO sa
forall sa a. SocketAddress sa => (Ptr sa -> Int -> IO a) -> IO a
withNewSocketAddress ((Ptr sa -> Int -> IO sa) -> IO sa)
-> (Ptr sa -> Int -> IO sa) -> IO sa
forall a b. (a -> b) -> a -> b
$\Ptr sa
ptr Int
sz ->CInt -> (Ptr CInt -> IO sa) -> IO sa
forall a b. Storable a => a -> (Ptr a -> IO b) -> IO b
with(Int -> CInt
forall a b. (Integral a, Num b) => a -> b
fromIntegralInt
sz )((Ptr CInt -> IO sa) -> IO sa) -> (Ptr CInt -> IO sa) -> IO sa
forall a b. (a -> b) -> a -> b
$\Ptr CInt
int_star ->Socket -> (CInt -> IO sa) -> IO sa
forall r. Socket -> (CInt -> IO r) -> IO r
withFdSocket Socket
s ((CInt -> IO sa) -> IO sa) -> (CInt -> IO sa) -> IO sa
forall a b. (a -> b) -> a -> b
$\CInt
fd ->doString -> IO CInt -> IO ()
forall a. (Eq a, Num a) => String -> IO a -> IO ()
throwSocketErrorIfMinus1Retry_ String
"Network.Socket.getSocketName"(IO CInt -> IO ()) -> IO CInt -> IO ()
forall a b. (a -> b) -> a -> b
$CInt -> Ptr sa -> Ptr CInt -> IO CInt
forall sa. CInt -> Ptr sa -> Ptr CInt -> IO CInt
c_getsockname CInt
fd Ptr sa
ptr Ptr CInt
int_star Ptr sa -> IO sa
forall sa. SocketAddress sa => Ptr sa -> IO sa
peekSocketAddress Ptr sa
ptr foreignimportCALLCONVunsafe"getpeername"c_getpeername ::CInt->Ptrsa ->PtrCInt->IOCIntforeignimportCALLCONVunsafe"getsockname"c_getsockname ::CInt->Ptrsa ->PtrCInt->IOCInt-- ----------------------------------------------------------------------------- socketPort---- The port number the given socket is currently connected to can be-- determined by calling $port,ドル is generally only useful when bind-- was given $aNY\_PORT$.-- | Getting the port of socket.-- `IOError` is thrown if a port is not available.socketPort ::Socket -- Connected & Bound Socket->IOPortNumber -- Port Number of SocketsocketPort :: Socket -> IO PortNumber
socketPort Socket
s =doSockAddr
sa <-Socket -> IO SockAddr
forall sa. SocketAddress sa => Socket -> IO sa
getSocketName Socket
s caseSockAddr
sa ofSockAddrInet PortNumber
port HostAddress
_->PortNumber -> IO PortNumber
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
returnPortNumber
port SockAddrInet6 PortNumber
port HostAddress
_HostAddress6
_HostAddress
_->PortNumber -> IO PortNumber
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
returnPortNumber
port SockAddr
_->IOError -> IO PortNumber
forall a. IOError -> IO a
ioError(IOError -> IO PortNumber) -> IOError -> IO PortNumber
forall a b. (a -> b) -> a -> b
$String -> IOError
userErrorString
"Network.Socket.socketPort: AF_UNIX not supported."-- ----------------------------------------------------------------------------- socketPortSafe-- | Getting the port of socket.socketPortSafe ::Socket -- Connected & Bound Socket->IO(MaybePortNumber )-- Port Number of SocketsocketPortSafe :: Socket -> IO (Maybe PortNumber)
socketPortSafe Socket
s =doSockAddr
sa <-Socket -> IO SockAddr
forall sa. SocketAddress sa => Socket -> IO sa
getSocketName Socket
s Maybe PortNumber -> IO (Maybe PortNumber)
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return(Maybe PortNumber -> IO (Maybe PortNumber))
-> Maybe PortNumber -> IO (Maybe PortNumber)
forall a b. (a -> b) -> a -> b
$caseSockAddr
sa ofSockAddrInet PortNumber
port HostAddress
_->PortNumber -> Maybe PortNumber
forall a. a -> Maybe a
JustPortNumber
port SockAddrInet6 PortNumber
port HostAddress
_HostAddress6
_HostAddress
_->PortNumber -> Maybe PortNumber
forall a. a -> Maybe a
JustPortNumber
port SockAddr
_->Maybe PortNumber
forall a. Maybe a
Nothing

AltStyle によって変換されたページ (->オリジナル) /