Commit eb6d1c0e authored by Mart Lubbers's avatar Mart Lubbers

rename record members socket

parent ed057ceb
...@@ -12,7 +12,7 @@ Start w ...@@ -12,7 +12,7 @@ Start w
= case socket SocketStream w of = case socket SocketStream w of
(Error e, w) = (Error e, w) (Error e, w) = (Error e, w)
(Ok sockfd, w) (Ok sockfd, w)
#! (merr, sockfd) = connect {sin_port=8124,sin_addr=Just (fromString "127.0.0.1")} sockfd #! (merr, sockfd) = connect {ipv4_socket_port=8124,ipv4_socket_addr=Just (fromString "127.0.0.1")} sockfd
| isError merr = (liftError merr, w) | isError merr = (liftError merr, w)
#! (merr, sockfd) = recv 128 [] sockfd #! (merr, sockfd) = recv 128 [] sockfd
| isError merr = (merr, w) | isError merr = (merr, w)
......
...@@ -13,7 +13,7 @@ Start w ...@@ -13,7 +13,7 @@ Start w
= case socket SocketStream w of = case socket SocketStream w of
(Error e, w) = (Error e, w) (Error e, w) = (Error e, w)
(Ok sockfd, w) (Ok sockfd, w)
#! (merr, sockfd) = bind {sin_port=8124,sin_addr=Nothing} sockfd #! (merr, sockfd) = bind {ipv4_socket_port=8124,ipv4_socket_addr=Nothing} sockfd
| isError merr = (merr, w) | isError merr = (merr, w)
#! (merr, sockfd) = listen 3 sockfd #! (merr, sockfd) = listen 3 sockfd
| isError merr = (merr, w) | isError merr = (merr, w)
......
...@@ -6,8 +6,8 @@ from StdMaybe import :: Maybe ...@@ -6,8 +6,8 @@ from StdMaybe import :: Maybe
from System.Socket import class SocketAddress from System.Socket import class SocketAddress
:: Ipv4SocketAddress = :: Ipv4SocketAddress =
{ sin_port :: !Int { ipv4_socket_port :: !Int
, sin_addr :: !Maybe IPAddress , ipv4_socket_addr :: !Maybe IPAddress
} }
instance SocketAddress Ipv4SocketAddress instance SocketAddress Ipv4SocketAddress
instance toString Ipv4SocketAddress instance toString Ipv4SocketAddress
...@@ -10,14 +10,14 @@ import Text.GenPrint ...@@ -10,14 +10,14 @@ import Text.GenPrint
instance SocketAddress Ipv4SocketAddress where instance SocketAddress Ipv4SocketAddress where
sa_serialize sa p w sa_serialize sa p w
# p = writeInt2 p 0 (sa_domain sa) # p = writeInt2 p 0 (sa_domain sa)
# p = writeInt2 p 2 (hostToNetworkByteOrderShort sa.sin_port) # p = writeInt2 p 2 (hostToNetworkByteOrderShort sa.ipv4_socket_port)
# p = writeInt4 p 4 (maybe 0 toInt sa.sin_addr) # p = writeInt4 p 4 (maybe 0 toInt sa.ipv4_socket_addr)
= (p, w) = (p, w)
sa_deserialize p sa_deserialize p
= Ok {sin_port=networkToHostByteOrderShort (readInt2Z p 2),sin_addr=Just (fromInt (readInt4Z p 4))} = Ok {ipv4_socket_port=networkToHostByteOrderShort (readInt2Z p 2),ipv4_socket_addr=Just (fromInt (readInt4Z p 4))}
sa_length _ = 16 sa_length _ = 16
sa_domain _ = 2 sa_domain _ = 2
sa_null = {sin_port=0, sin_addr=Nothing} sa_null = {ipv4_socket_port=0, ipv4_socket_addr=Nothing}
gPrint{|IPAddress|} a s = gPrint{|*|} (toString a) s gPrint{|IPAddress|} a s = gPrint{|*|} (toString a) s
derive gPrint Ipv4SocketAddress, Maybe derive gPrint Ipv4SocketAddress, Maybe
......
...@@ -6,10 +6,10 @@ from StdMaybe import :: Maybe ...@@ -6,10 +6,10 @@ from StdMaybe import :: Maybe
from System.Socket import class SocketAddress from System.Socket import class SocketAddress
:: Ipv6SocketAddress = :: Ipv6SocketAddress =
{ sin6_port :: !Int { ipv6_socket_port :: !Int
, sin6_flowinfo :: !Int , ipv6_socket_flowinfo :: !Int
, sin6_addr :: !Maybe String , ipv6_socket_addr :: !Maybe String
, sin6_scope_id :: !Int , ipv6_socket_scope_id :: !Int
} }
instance SocketAddress Ipv6SocketAddress instance SocketAddress Ipv6SocketAddress
instance toString Ipv6SocketAddress instance toString Ipv6SocketAddress
...@@ -11,22 +11,22 @@ from System._Socket import AF_INET6 ...@@ -11,22 +11,22 @@ from System._Socket import AF_INET6
instance SocketAddress Ipv6SocketAddress where instance SocketAddress Ipv6SocketAddress where
sa_serialize sa p w sa_serialize sa p w
# p = writeInt2 p 0 (sa_domain sa) # p = writeInt2 p 0 (sa_domain sa)
# p = writeInt2 p 2 (hostToNetworkByteOrderShort sa.sin6_port) # p = writeInt2 p 2 (hostToNetworkByteOrderShort sa.ipv6_socket_port)
# p = writeInt4 p 4 (sa.sin6_flowinfo) # p = writeInt4 p 4 (sa.ipv6_socket_flowinfo)
# p = writeCharArray (p+8) (pad16 (fromMaybe "::" sa.sin6_addr)) # p = writeCharArray (p+8) (pad16 (fromMaybe "::" sa.ipv6_socket_addr))
# p = writeInt4 p 24 (sa.sin6_scope_id) # p = writeInt4 p 24 (sa.ipv6_socket_scope_id)
= (p, w) = (p, w)
where where
pad16 s = s +++ {'\0'\\_<-[0..16-1-size s]} pad16 s = s +++ {'\0'\\_<-[0..16-1-size s]}
sa_deserialize p = Ok sa_deserialize p = Ok
{ sin6_port = networkToHostByteOrderShort (readInt2Z p 2) { ipv6_socket_port = networkToHostByteOrderShort (readInt2Z p 2)
, sin6_flowinfo = readInt4Z p 4 , ipv6_socket_flowinfo = readInt4Z p 4
, sin6_addr = Just (derefCharArray (p+8) 16) , ipv6_socket_addr = Just (derefCharArray (p+8) 16)
, sin6_scope_id = readInt4Z p 24 , ipv6_socket_scope_id = readInt4Z p 24
} }
sa_length _ = 28 sa_length _ = 28
sa_domain _ = AF_INET6 sa_domain _ = AF_INET6
sa_null = {sin6_port=0,sin6_flowinfo=0,sin6_addr=Nothing,sin6_scope_id=0} sa_null = {ipv6_socket_port=0,ipv6_socket_flowinfo=0,ipv6_socket_addr=Nothing,ipv6_socket_scope_id=0}
derive gPrint Ipv6SocketAddress, Maybe derive gPrint Ipv6SocketAddress, Maybe
instance toString Ipv6SocketAddress where toString s = printToString s instance toString Ipv6SocketAddress where toString s = printToString s
...@@ -5,7 +5,7 @@ from StdOverloaded import class toString ...@@ -5,7 +5,7 @@ from StdOverloaded import class toString
from System.Socket import class SocketAddress from System.Socket import class SocketAddress
:: UnixSocketAddress = :: UnixSocketAddress =
{ sun_path :: !FilePath { unix_socket_path :: !FilePath
} }
instance SocketAddress UnixSocketAddress instance SocketAddress UnixSocketAddress
instance toString UnixSocketAddress instance toString UnixSocketAddress
...@@ -10,12 +10,12 @@ from System._Socket import AF_UNIX ...@@ -10,12 +10,12 @@ from System._Socket import AF_UNIX
instance SocketAddress UnixSocketAddress where instance SocketAddress UnixSocketAddress where
sa_serialize sa p w sa_serialize sa p w
# p = writeInt2 p 0 (sa_domain sa) # p = writeInt2 p 0 (sa_domain sa)
# p = writeCharArray (p+2) (packString sa.sun_path) # p = writeCharArray (p+2) (packString sa.unix_socket_path)
= (p, w) = (p, w)
sa_deserialize p sa_deserialize p
= Ok {sun_path=derefString (p+2)} = Ok {unix_socket_path=derefString (p+2)}
sa_length _ = 110 sa_length _ = 110
sa_domain _ = AF_UNIX sa_domain _ = AF_UNIX
sa_null = {sun_path="/"} sa_null = {unix_socket_path="/"}
instance toString UnixSocketAddress where toString s = s.sun_path instance toString UnixSocketAddress where toString s = s.unix_socket_path
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment