Commit 5fa27a9b authored by Mart Lubbers's avatar Mart Lubbers Committed by Mart Lubbers

rename htons, ntohs

parent d1c9a8f6
Pipeline #21496 failed with stage
in 3 minutes and 15 seconds
......@@ -9,7 +9,7 @@ import System.Socket.Ipv4
Start :: *World -> (MaybeOSError String, *World)
Start w
= case socket ST_Stream w of
= case socket SocketStream w of
(Error e, w) = (Error e, w)
(Ok sockfd, w)
#! (merr, sockfd) = connect {sin_port=8124,sin_addr=Just (fromString "127.0.0.1")} sockfd
......
......@@ -10,7 +10,7 @@ import System.Socket.Ipv4
Start :: *World -> (MaybeOSError (), *World)
Start w
= case socket ST_Stream w of
= case socket SocketStream w of
(Error e, w) = (Error e, w)
(Ok sockfd, w)
#! (merr, sockfd) = bind {sin_port=8124,sin_addr=Nothing} sockfd
......
......@@ -97,5 +97,22 @@ send :: !String ![SendFlag] !*(Socket sa) -> *(!MaybeOSError Int, !*Socket sa)
*/
recv :: !Int ![RecvFlag] !*(Socket sa) -> *(!MaybeOSError String, !*Socket sa)
ntohs :: !Int -> Int
htons :: !Int -> Int
/*
* Convert a short in network order to a short in host order
*/
networkToHostByteOrderShort :: !Int -> Int
/*
* Convert a short in network order to a short in host order
*/
hostToNetworkByteOrderShort :: !Int -> Int
/*
* Convert a long in network order to a long in host order
*/
networkToHostByteOrderLong :: !Int -> Int
/*
* Convert a long in network order to a long in host order
*/
hostToNetworkByteOrderLong :: !Int -> Int
implementation module System.Socket
import StdEnv
import System._Socket => qualified socket, bind, listen, accept, close, connect, send, recv, htons, ntohs
import System._Socket => qualified socket, bind, listen, accept, close, connect, send, recv, hostToNetworkByteOrderLong, hostToNetworkByteOrderShort, networkToHostByteOrderShort, networkToHostByteOrderLong
import System.OSError
instance toInt SocketType where
......@@ -41,8 +41,14 @@ send a b c = 'System._Socket'.send a b c
recv :: !Int ![RecvFlag] !*(Socket sa) -> *(!MaybeOSError String, !*Socket sa)
recv a b c = 'System._Socket'.recv a b c
ntohs :: !Int -> Int
ntohs a = 'System._Socket'.ntohs a
networkToHostByteOrderShort :: !Int -> Int
networkToHostByteOrderShort a = 'System._Socket'.networkToHostByteOrderShort a
htons :: !Int -> Int
htons a = 'System._Socket'.htons a
hostToNetworkByteOrderShort :: !Int -> Int
hostToNetworkByteOrderShort a = 'System._Socket'.hostToNetworkByteOrderShort a
networkToHostByteOrderLong :: !Int -> Int
networkToHostByteOrderLong a = 'System._Socket'.networkToHostByteOrderShort a
hostToNetworkByteOrderLong :: !Int -> Int
hostToNetworkByteOrderLong a = 'System._Socket'.hostToNetworkByteOrderLong a
......@@ -10,11 +10,11 @@ import Text.GenPrint
instance SocketAddress SaInet where
sa_serialize sa p w
# p = writeInt2 p 0 (sa_domain sa)
# p = writeInt2 p 2 (htons sa.sin_port)
# p = writeInt2 p 2 (hostToNetworkByteOrderShort sa.sin_port)
# p = writeInt4 p 4 (maybe 0 toInt sa.sin_addr)
= (p, w)
sa_deserialize p
= Ok {sin_port=ntohs (readInt2Z p 2),sin_addr=Just (fromInt (readInt4Z p 4))}
= Ok {sin_port=networkToHostByteOrderShort (readInt2Z p 2),sin_addr=Just (fromInt (readInt4Z p 4))}
sa_length _ = 16
sa_domain _ = 2
sa_null = {sin_port=0, sin_addr=Nothing}
......
......@@ -11,7 +11,7 @@ from System._Socket import AF_INET6
instance SocketAddress SaInet6 where
sa_serialize sa p w
# p = writeInt2 p 0 (sa_domain sa)
# p = writeInt2 p 2 (htons sa.sin6_port)
# p = writeInt2 p 2 (hostToNetworkByteOrderShort sa.sin6_port)
# p = writeInt4 p 4 (sa.sin6_flowinfo)
# p = writeCharArray (p+8) (pad16 (fromMaybe "::" sa.sin6_addr))
# p = writeInt4 p 24 (sa.sin6_scope_id)
......@@ -19,7 +19,7 @@ instance SocketAddress SaInet6 where
where
pad16 s = s +++ {'\0'\\_<-[0..16-1-size s]}
sa_deserialize p = Ok
{ sin6_port = ntohs (readInt2Z p 2)
{ sin6_port = networkToHostByteOrderShort (readInt2Z p 2)
, sin6_flowinfo = readInt4Z p 4
, sin6_addr = Just (derefCharArray (p+8) 16)
, sin6_scope_id = readInt4Z p 24
......
......@@ -32,5 +32,7 @@ connect :: !sa !*(Socket sa) -> *(!MaybeOSError (), !*Socket sa) | SocketAddress
send :: !String ![SendFlag] !*(Socket sa) -> *(!MaybeOSError Int, !*Socket sa)
recv :: !Int ![RecvFlag] !*(Socket sa) -> *(!MaybeOSError String, !*Socket sa)
ntohs :: !Int -> Int
htons :: !Int -> Int
networkToHostByteOrderShort :: !Int -> Int
hostToNetworkByteOrderShort :: !Int -> Int
networkToHostByteOrderLong :: !Int -> Int
hostToNetworkByteOrderLong :: !Int -> Int
......@@ -5,7 +5,7 @@ import Data.Error
import System.OSError
import System._Pointer
import System._Posix
import System.Socket => qualified socket, bind, listen, accept, close, connect, send, recv, htons, ntohs
import System.Socket => qualified socket, bind, listen, accept, close, connect, send, recv, networkToHostByteOrderLong, networkToHostByteOrderShort, hostToNetworkByteOrderLong, hostToNetworkByteOrderShort
:: *Socket a :== Int
......@@ -137,14 +137,24 @@ where
ccall close "I:I"
}
htons :: !Int -> Int
htons x = code {
networkToHostByteOrderShort :: !Int -> Int
networkToHostByteOrderShort a = code {
ccall ntohs "I:I"
}
hostToNetworkByteOrderShort :: !Int -> Int
hostToNetworkByteOrderShort a = code {
ccall htons "I:I"
}
ntohs :: !Int -> Int
ntohs x = code {
ccall ntohs "I:I"
networkToHostByteOrderLong :: !Int -> Int
networkToHostByteOrderLong a = code {
ccall ntohl "I:I"
}
hostToNetworkByteOrderLong :: !Int -> Int
hostToNetworkByteOrderLong a = code {
ccall htonl "I:I"
}
getFd :: !*(Socket sa) -> *(!Int, !*(Socket sa))
......
......@@ -36,5 +36,7 @@ connect :: !sa !*(Socket sa) -> *(!MaybeOSError (), !*Socket sa) | SocketAddress
send :: !String ![SendFlag] !*(Socket sa) -> *(!MaybeOSError Int, !*Socket sa)
recv :: !Int ![RecvFlag] !*(Socket sa) -> *(!MaybeOSError String, !*Socket sa)
ntohs :: !Int -> Int
htons :: !Int -> Int
networkToHostByteOrderShort :: !Int -> Int
hostToNetworkByteOrderShort :: !Int -> Int
networkToHostByteOrderLong :: !Int -> Int
hostToNetworkByteOrderLong :: !Int -> Int
......@@ -3,7 +3,7 @@ implementation module System._Socket
import Data.Error
import StdEnv
import System.OSError
import System.Socket => qualified socket, bind, listen, accept, close, connect, send, recv, htons, ntohs
import System.Socket => qualified socket, bind, listen, accept, close, connect, send, recv, networkToHostByteOrderLong, networkToHostByteOrderShort, hostToNetworkByteOrderLong, hostToNetworkByteOrderShort
import System._Pointer
import System._WinBase
......@@ -283,6 +283,26 @@ ntohs x = code {
ccall ntohs@4 "PI:I"
}
networkToHostByteOrderShort :: !Int -> Int
networkToHostByteOrderShort a = code {
ccall ntohs@4 "PI:I"
}
hostToNetworkByteOrderShort :: !Int -> Int
hostToNetworkByteOrderShort a = code {
ccall htons@4 "PI:I"
}
networkToHostByteOrderLong :: !Int -> Int
networkToHostByteOrderLong a = code {
ccall ntohl@4 "PI:I"
}
hostToNetworkByteOrderLong :: !Int -> Int
hostToNetworkByteOrderLong a = code {
ccall htonl@4 "PI:I"
}
getFd :: !*(Socket sa) -> *(!Int, !*Socket sa)
getFd s = code {
push_b 0
......
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