Commit e80a6a79 authored by Mart Lubbers's avatar Mart Lubbers

Move to _module

parent dd6b7b84
Pipeline #21341 failed with stage
in 2 minutes and 44 seconds
......@@ -5,21 +5,12 @@
#include <netinet/in.h>
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));
printf("offset sockaddr_in.sin_port: %lu\n",
offsetof(struct sockaddr_in, sin_port));
printf("offset sockaddr_in.sin_addr: %lu\n",
offsetof(struct sockaddr_in, sin_addr));
printf("AF_INET :== %lu\n", AF_INET);
printf("AF_INET6 :== %lu\n", AF_INET6);
printf("AF_IPX :== %lu\n", AF_IPX);
printf("AF_APPLETALK :== %lu\n", AF_APPLETALK);
printf("AF_IRDA :== %lu\n", AF_IRDA);
printf("SOCK_STREAM :== %lu\n", SOCK_STREAM);
printf("SOCK_DGRAM :== %lu\n", SOCK_DGRAM);
return 0;
}
definition module System.Socket
from StdOverloaded import class toInt
from Data.Error import :: MaybeError, :: MaybeErrorString
from System._Pointer import :: Pointer(..)
from System._Socket import :: Socket
from System.OSError import :: MaybeOSError, :: OSError, :: OSErrorMessage, :: OSErrorCode
from System._Pointer import :: Pointer
:: *Socket a (:== Int)
:: SocketType = ST_Stream | ST_DGram
instance toInt SocketType
class SocketAddress sa where
sa_length :: !sa -> Int
......@@ -26,10 +27,5 @@ connect :: !sa !*(Socket sa) -> *(!MaybeOSError (), !*(Socket sa)) | SocketAddre
send :: !String !Int !*(Socket sa) -> *(!MaybeOSError Int, !*(Socket sa))
recv :: !Int !Int !*(Socket sa) -> *(!MaybeOSError String, !*(Socket sa))
/*
* Get access to the raw file descriptor
*/
getFd :: !*(Socket sa) -> *(!Int, !*(Socket sa))
ntohs :: !Int -> Int
htons :: !Int -> Int
implementation module System.Socket
import StdEnv
import System._Socket => qualified socket, bind, listen, accept, close, connect, send, recv, htons, ntohs
import System.OSError
instance toInt SocketType where
toInt ST_Stream = SOCK_STREAM
toInt ST_DGram = SOCK_DGRAM
socket :: !SocketType !Int !*e -> *(!MaybeOSError *(Socket sa), !*e) | SocketAddress sa
socket a b c = 'System._Socket'.socket a b c
bind :: !sa !*(Socket sa) -> *(!MaybeOSError (), !*(Socket sa)) | SocketAddress sa
bind a b = 'System._Socket'.bind a b
listen :: !Int !*(Socket sa) -> *(!MaybeOSError (), !*(Socket sa)) | SocketAddress sa
listen a b = 'System._Socket'.listen a b
accept :: !*(Socket sa) -> *(!MaybeOSError (!*(Socket sa), !sa), !*(Socket sa)) | SocketAddress sa
accept a = 'System._Socket'.accept a
close :: !*(Socket sa) !*e -> *(!MaybeOSError (), !*e) | SocketAddress sa
close a b = 'System._Socket'.close a b
connect :: !sa !*(Socket sa) -> *(!MaybeOSError (), !*(Socket sa)) | SocketAddress sa
connect a b = 'System._Socket'.connect a b
send :: !String !Int !*(Socket sa) -> *(!MaybeOSError Int, !*(Socket sa))
send a b c = 'System._Socket'.send a b c
recv :: !Int !Int !*(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
htons :: !Int -> Int
htons a = 'System._Socket'.htons a
......@@ -9,7 +9,7 @@ import Text.GenPrint
instance SocketAddress SaInet where
sa_serialize sa p w
#! p = writeInt2 p 0 2
#! 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)
......
......@@ -24,7 +24,7 @@ instance SocketAddress SaInet6 where
, sin6_scope_id = readInt4Z p 24
}
sa_length _ = 28
sa_domain _ = 10
sa_domain _ = AF_INET6
sa_null = {sin6_port=0,sin6_flowinfo=0,sin6_addr=Nothing,sin6_scope_id=0}
derive gPrint SaInet6, Maybe
......
implementation module System.Socket.Ipv4
import StdEnv
import Network.IP
import Data.Error
import System.Socket
import System._Pointer
import Text.GenPrint
instance SocketAddress SaInet where
sa_serialize sa p w
#! p = writeInt2 p 0 2
#! p = writeInt2 p 2 (htons sa.sin_port)
#! p = writeInt4 p 4 (maybe 0 toInt sa.sin_addr)
= (p, forceEvalPointer p w)
sa_deserialize p
= Ok {sin_port=ntohs (readInt2Z p 2),sin_addr=Just (fromInt (readInt4Z p 4))}
sa_length _ = 16
sa_domain _ = 2
sa_null = {sin_port=0, sin_addr=Nothing}
gPrint{|IPAddress|} a s = gPrint{|*|} (toString a) s
derive gPrint SaInet, Maybe
instance toString SaInet where toString s = printToString s
definition module System.Socket
definition module System._Socket
from Data.Error import :: MaybeError, :: MaybeErrorString
from Data.Error import :: MaybeError
from System.OSError import :: MaybeOSError, :: OSError, :: OSErrorMessage, :: OSErrorCode
from System._Pointer import :: Pointer
from System.Socket import :: SocketType, class SocketAddress
:: *Socket a (:== Int)
:: SaInet6 =
{ sin6_port :: !Int
, sin6_flowinfo :: !Int
, sin6_addr :: !String
, sin6_scope_id :: !Int
}
:: *Socket a
:: SocketType = ST_Stream | ST_DGram
AF_INET :== 2
AF_INET6 :== 10
AF_IPX :== 4
AF_APPLETALK :== 5
AF_IRDA :== 23
class SocketAddress sa where
sa_length :: !sa -> Int
sa_serialize :: !sa !Pointer !*e -> *(!Pointer, !*e)
sa_deserialize :: !Pointer -> MaybeErrorString sa
sa_domain :: !sa -> Int
sa_null :: sa
SOCK_STREAM :== 1
SOCK_DGRAM :== 2
socket :: !SocketType !Int !*e -> *(!MaybeOSError *(Socket sa), !*e) | SocketAddress sa
bind :: !sa !*(Socket sa) -> *(!MaybeOSError (), !*(Socket sa)) | SocketAddress sa
......@@ -32,10 +26,5 @@ connect :: !sa !*(Socket sa) -> *(!MaybeOSError (), !*(Socket sa)) | SocketAddre
send :: !String !Int !*(Socket sa) -> *(!MaybeOSError Int, !*(Socket sa))
recv :: !Int !Int !*(Socket sa) -> *(!MaybeOSError String, !*(Socket sa))
/*
* Get access to the raw file descriptor
*/
getFd :: !*(Socket sa) -> *(!Int, !*(Socket sa))
ntohs :: !Int -> Int
htons :: !Int -> Int
implementation module System.Socket
implementation module System._Socket
import StdEnv
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
:: *Socket a :== Int
instance toInt SocketType where
toInt ST_Stream = 1
toInt ST_DGram = 2
socket :: !SocketType !Int !*e -> *(!MaybeOSError *(Socket sa), !*e) | SocketAddress sa
socket type protocol w
#! (sockfd, w) = socket` (sa_domain msa) (toInt type) protocol w
......
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
, sin_addr :: !Maybe IPAddress
}
instance SocketAddress SaInet
instance toString SaInet
definition module System._Socket
from Data.Error import :: MaybeError
from System.OSError import :: MaybeOSError, :: OSError, :: OSErrorMessage, :: OSErrorCode
from System.Socket import :: SocketType, class SocketAddress
:: *Socket a
AF_INET :== 2
AF_INET6 :== 23
AF_IPX :== 6
AF_APPLETALK :== 16
AF_NETBIOS :== 17
AF_IRDA :== 26
AF_BTH :== 32
SOCK_STREAM :== 1
SOCK_DGRAM :== 2
SOCK_RAW :== 3
SOCK_RDM :== 4
SOCK_SEQPACKET :== 5
socket :: !SocketType !Int !*e -> *(!MaybeOSError *(Socket sa), !*e) | SocketAddress sa
bind :: !sa !*(Socket sa) -> *(!MaybeOSError (), !*(Socket sa)) | SocketAddress sa
listen :: !Int !*(Socket sa) -> *(!MaybeOSError (), !*(Socket sa)) | SocketAddress sa
accept :: !*(Socket sa) -> *(!MaybeOSError (!*(Socket sa), !sa), !*(Socket sa)) | SocketAddress sa
close :: !*(Socket sa) !*e -> *(!MaybeOSError (), !*e) | SocketAddress sa
connect :: !sa !*(Socket sa) -> *(!MaybeOSError (), !*(Socket sa)) | SocketAddress sa
send :: !String !Int !*(Socket sa) -> *(!MaybeOSError Int, !*(Socket sa))
recv :: !Int !Int !*(Socket sa) -> *(!MaybeOSError String, !*(Socket sa))
ntohs :: !Int -> Int
htons :: !Int -> Int
implementation module System.Socket
import StdEnv
import Data.Error
import StdEnv
import System.OSError
import System.Socket => qualified socket, bind, listen, accept, close, connect, send, recv, htons, ntohs
import System._Pointer
import System._WinBase
import code from library "Ws2_32"
:: *Socket a :== Int
instance toInt SocketType where
toInt ST_Stream = 1
toInt ST_DGram = 2
getLastWSAError :: !*e -> *(MaybeOSError .a, !*e)
getLastWSAError w
#! (r, w) = WSAGetLastError` w
......@@ -146,7 +144,6 @@ where
ccall WSAStartup@8 "PIp:I:A"
}
import System._WinBase
mallocSt :: !Int !*env -> *(!Pointer, !*env)
mallocSt size e
#! (heap, e) = getProcessHeap e
......
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