Verified Commit 26135abb authored by Camil Staps's avatar Camil Staps 🚀

Cleanup socket modules

parent b4f94cf4
Pipeline #21439 failed with stage
in 3 minutes and 39 seconds
......@@ -10,4 +10,3 @@ _Tests.*
* Time Profile.pcl
*.exe
a.out
......@@ -9,10 +9,10 @@ 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 = writeInt4 p 4 (maybe 0 toInt sa.sin_addr)
= (p, forceEvalPointer p w)
# p = writeInt2 p 0 (sa_domain sa)
# p = writeInt2 p 2 (htons 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))}
sa_length _ = 16
......
......@@ -10,12 +10,12 @@ 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 = writeInt4 p 4 (sa.sin6_flowinfo)
#! p = writeCharArray (p+8) (pad16 (fromMaybe "::" sa.sin6_addr))
#! p = writeInt4 p 24 (sa.sin6_scope_id)
= (p, forceEvalPointer p w)
# p = writeInt2 p 0 (sa_domain sa)
# p = writeInt2 p 2 (htons 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)
= (p, w)
where
pad16 s = s +++ {'\0'\\_<-[0..16-1-size s]}
sa_deserialize p = Ok
......
......@@ -9,9 +9,9 @@ from System._Socket import AF_UNIX
instance SocketAddress SaUnix where
sa_serialize sa p w
#! p = writeInt2 p 0 (sa_domain sa)
#! p = writeCharArray (p+2) (packString sa.sun_path)
= (p, forceEvalPointer p w)
# p = writeInt2 p 0 (sa_domain sa)
# p = writeCharArray (p+2) (packString sa.sun_path)
= (p, w)
sa_deserialize p
= Ok {sun_path=derefString (p+2)}
sa_length _ = 110
......
......@@ -11,8 +11,8 @@ import System.Socket => qualified socket, bind, listen, accept, close, connect,
socket :: !SocketType !Int !*e -> *(!MaybeOSError *(Socket sa), !*e) | SocketAddress sa
socket type protocol w
#! (sockfd, w) = socket` (sa_domain msa) (toInt type) protocol w
#! (fd, sockfd) = getFd sockfd
# (sockfd, w) = socket` (sa_domain msa) (toInt type) protocol w
# (fd, sockfd) = getFd sockfd
| fd == -1 = getLastOSError w
= (Ok (coerce sockfd msa), w)
where
......@@ -28,14 +28,14 @@ where
bind :: !sa !*(Socket sa) -> *(!MaybeOSError (), !*(Socket sa)) | SocketAddress sa
bind addr sockfd
#! (p, sockfd) = mallocSt (sa_length addr) sockfd
# (p, sockfd) = mallocSt (sa_length addr) sockfd
| p == 0 = getLastOSError sockfd
#! (p, sockfd) = sa_serialize addr p sockfd
#! len = sa_length addr
#! (fd, sockfd) = getFd sockfd
#! (r, sockfd) = bind` fd p len sockfd
# (p, sockfd) = sa_serialize addr p sockfd
# len = sa_length addr
# (fd, sockfd) = getFd sockfd
# (r, sockfd) = bind` fd p len sockfd
| r == -1 = getLastOSError sockfd
#! sockfd = freeSt p sockfd
# sockfd = freeSt p sockfd
= (Ok (), sockfd)
where
bind` :: !Int !Pointer !Int !*e -> *(!Int, !*e)
......@@ -76,12 +76,12 @@ where
connect :: !sa !*(Socket sa) -> *(!MaybeOSError (), !*(Socket sa)) | SocketAddress sa
connect addr sockfd
#! (p, sockfd) = mallocSt (sa_length addr) sockfd
# (p, sockfd) = mallocSt (sa_length addr) sockfd
| p == 0 = getLastOSError sockfd
#! (p, sockfd) = sa_serialize addr p sockfd
#! (fd, sockfd) = getFd sockfd
#! (r, sockfd) = connect` fd p (sa_length addr) sockfd
#! sockfd = freeSt p sockfd
# (p, sockfd) = sa_serialize addr p sockfd
# (fd, sockfd) = getFd sockfd
# (r, sockfd) = connect` fd p (sa_length addr) sockfd
# sockfd = freeSt p sockfd
| r == -1 = getLastOSError sockfd
= (Ok (), sockfd)
where
......@@ -92,8 +92,8 @@ where
send :: !String !Int !*(Socket sa) -> *(!MaybeOSError Int, !*(Socket sa))
send data flags sockfd
#! (fd, sockfd) = getFd sockfd
#! (r, sockfd) = send` fd (packString data) (size data) flags sockfd
# (fd, sockfd) = getFd sockfd
# (r, sockfd) = send` fd (packString data) (size data) flags sockfd
| r == -1 = getLastOSError sockfd
= (Ok r, sockfd)
where
......@@ -104,12 +104,12 @@ where
recv :: !Int !Int !*(Socket sa) -> *(!MaybeOSError String, !*(Socket sa))
recv length flags sockfd
#! (p, sockfd) = mallocSt length sockfd
#! (fd, sockfd) = getFd sockfd
#! (r, sockfd) = recv` fd p length flags sockfd
# (p, sockfd) = mallocSt length sockfd
# (fd, sockfd) = getFd sockfd
# (r, sockfd) = recv` fd p length flags sockfd
| r == -1 = getLastOSError sockfd
#! (s, p) = readP derefString p
#! sockfd = freeSt p sockfd
# (s, p) = readP derefString p
# sockfd = freeSt p sockfd
= (Ok s, sockfd)
where
......
......@@ -117,7 +117,7 @@ where
WSAGetLastError` _ = code {
ccall WSAGetLastError@0 "P:I:A"
}
import StdDebug
socket :: !SocketType !Int !*e -> *(!MaybeOSError *(Socket sa), !*e) | SocketAddress sa
socket type protocol w
#! (p, w) = mallocSt 2048 w
......
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