Commit 087e01b9 authored by Mart Lubbers's avatar Mart Lubbers

move example

parent 0f27dcba
Pipeline #21280 failed with stage
in 2 minutes and 48 seconds
......@@ -2,3 +2,6 @@ Clean System Files
_Tests
_Tests.*
*.o
*-sapl
*-www
*-data
......@@ -6,6 +6,7 @@ import Data.Maybe
import Network.IP
import System.Socket
import System.Socket.Ipv4
import System.Socket.Ipv6
Start :: *World -> (MaybeOSError String, *World)
Start w
......
This diff is collapsed.
This diff is collapsed.
......@@ -6,10 +6,13 @@
int main(void)
{
printf("AF_INET: %lu\n", AF_INET);
printf("AF_INET6: %lu\n", AF_INET6);
printf("SOCK_STREAM: %lu\n", SOCK_STREAM);
printf("SOCK_DGRAM: %lu\n", SOCK_DGRAM);
printf("INADDR_ANY: %lu\n", INADDR_ANY);
printf("IPPROTO_IP: %lu\n", IPPROTO_IP);
printf("sizeof(sockaddr_in): %lu\n", sizeof (struct sockaddr_in));
printf("sizeof(sockaddr_in6): %lu\n", sizeof (struct sockaddr_in6));
printf("offset sockaddr_in.sin_family: %lu\n",
offsetof(struct sockaddr_in, sin_family));
......
......@@ -5,12 +5,6 @@ from System.OSError import :: MaybeOSError, :: OSError, :: OSErrorMessage, :: OS
from System._Pointer import :: Pointer
:: *Socket a (:== Int)
:: SaInet6 =
{ sin6_port :: !Int
, sin6_flowinfo :: !Int
, sin6_addr :: !String
, sin6_scope_id :: !Int
}
:: SocketType = ST_Stream | ST_DGram
......
......@@ -31,15 +31,14 @@ where
bind :: !sa !*(Socket sa) -> *(!MaybeOSError (), !*(Socket sa)) | SocketAddress sa
bind addr sockfd
#! p = malloc (sa_length addr)
#! (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
| r == -1 = getLastOSError sockfd
#! r = free p
| r == -1 = getLastOSError sockfd
#! sockfd = freeSt p sockfd
= (Ok (), sockfd)
where
bind` :: !Int !Pointer !Int !*e -> *(!Int, !*e)
......@@ -61,18 +60,16 @@ where
accept :: !*(Socket sa) -> *(!MaybeOSError (!*(Socket sa), !sa), !*(Socket sa)) | SocketAddress sa
accept sockfd
# (fd, sockfd) = getFd sockfd
# p1 = malloc 64
# p2 = malloc 8
# (p1, sockfd) = mallocSt 64 sockfd
# (p2, sockfd) = mallocSt 8 sockfd
# p2 = writeInt p2 0 64
= case accept` fd p1 p2 sockfd of
(-1, sockfd) = getLastOSError sockfd
(sock, sockfd)
#! (merr, p1) = readP sa_deserialize p1
| isError merr = (Error (0, fromError merr), sockfd)
#! r = free p1
| r == -1 = getLastOSError sockfd
#! r = free p2
| r == -1 = getLastOSError sockfd
#! sockfd = freeSt p1 sockfd
#! sockfd = freeSt p2 sockfd
= (Ok (sock, fromOk merr), sockfd)
where
accept` :: !Int !Pointer !Int !*e -> *(!*Int, !*e)
......
definition module System.Socket.Ipv4
from StdOverloaded import class toString
//from Data.Error import :: MaybeError, :: MaybeErrorString
from Network.IP import :: IPAddress
from StdMaybe import :: Maybe
from System.Socket import class SocketAddress
//from System.OSError import :: MaybeOSError, :: OSError, :: OSErrorMessage, :: OSErrorCode
//from System._Pointer import :: Pointer
:: SaInet =
{ sin_port :: !Int
......
definition module System.Socket.Ipv6
from StdOverloaded import class toString
from Network.IP import :: IPAddress
from StdMaybe import :: Maybe
from System.Socket import class SocketAddress
:: SaInet6 =
{ sin6_port :: !Int
, sin6_flowinfo :: !Int
, sin6_addr :: !Maybe String
, sin6_scope_id :: !Int
}
instance SocketAddress SaInet6
instance toString SaInet6
implementation module System.Socket.Ipv6
import StdEnv
import Data.Error
import Data.Maybe
import System.Socket
import System._Pointer
import Text.GenPrint
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)
where
pad16 s = s +++ {'\0'\\_<-[0..16-1-size s]}
sa_deserialize p = Ok
{ sin6_port = ntohs (readInt2Z p 2)
, sin6_flowinfo = readInt4Z p 4
, sin6_addr = Just (derefCharArray (p+8) 16)
, sin6_scope_id = readInt4Z p 24
}
sa_length _ = 28
sa_domain _ = 10
sa_null = {sin6_port=0,sin6_flowinfo=0,sin6_addr=Nothing,sin6_scope_id=0}
derive gPrint SaInet6, Maybe
instance toString SaInet6 where toString s = printToString s
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