diff options
Diffstat (limited to 'testsuite/tests/lib/socket')
19 files changed, 344 insertions, 0 deletions
diff --git a/testsuite/tests/lib/socket/Makefile b/testsuite/tests/lib/socket/Makefile new file mode 100644 index 0000000000..9101fbd40a --- /dev/null +++ b/testsuite/tests/lib/socket/Makefile @@ -0,0 +1,3 @@ +TOP=../../.. +include $(TOP)/mk/boilerplate.mk +include $(TOP)/mk/test.mk diff --git a/testsuite/tests/lib/socket/socket001.hs b/testsuite/tests/lib/socket/socket001.hs new file mode 100644 index 0000000000..0af7afa0d7 --- /dev/null +++ b/testsuite/tests/lib/socket/socket001.hs @@ -0,0 +1,58 @@ +{- server + +The purpose of this test driver is to test TCP Stream sockets. +All values have been hard coded since the BSD library is not used to +query the databases for the values. In therory this code is thus not +portable but net007/Main.hs provides a portable version using the BSD +module. + +This creates a stream socket bound to port 5000 and waits for incoming +messages it then reads all available data before closing the +connection to that peer. + +No form of error checking is provided other than that already provided +by module SocketPrim. + + +TESTS: + socket + bindSocket + listen + accept + readSocket + sClose + +-} + + +module Main where + +import SocketPrim + +main = do + s <- socket AF_INET Stream 6 + bindSocket s (SockAddrInet (fromIntegral 5000) iNADDR_ANY) + listen s 5 + + let + loop = + accept s >>= \ (s',peerAddr) -> + putStr "*** Start of Transfer ***\n" >> + h <- socketToHandle s' + let + read_all = + b <- hEOF h + c <- hGetChar h + putChar c + + if nbytes /= 0 then + putStr str >> + read_all + else + putStr "\n*** End of Transfer ***\n" >> + sClose s' + in + read_all + + loop + diff --git a/testsuite/tests/lib/socket/socket001.stdout b/testsuite/tests/lib/socket/socket001.stdout new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/testsuite/tests/lib/socket/socket001.stdout diff --git a/testsuite/tests/lib/socket/socket002.hs b/testsuite/tests/lib/socket/socket002.hs new file mode 100644 index 0000000000..1e7b19da0b --- /dev/null +++ b/testsuite/tests/lib/socket/socket002.hs @@ -0,0 +1,45 @@ +{- client + +Client side to net001/Main.hs. + +Note that the machine IP numbers have been hard coded into this +program so it is unlikely that you will be able to run this test if +you are not at dcs.gla.ac.uk :-( + +The reason for this is to aviod using the BSD module at this stage of +testing. + + +TESTS: + socket + connect + writeSocket + shutdown + inet_addr +-} + + +module Main where + +import SocketPrim + + +starbuck = "130.209.240.81" -- SunOS 4.1.3 1 sun4c +marcus = "130.209.247.2" -- SunOS 4.1.3 6 sun4m +avon = "130.209.247.4" -- OSF1 V2.0 240 alpha +karkar = "130.209.247.3" -- OSF1 V2.0 240 alpha +nauru = "130.209.247.5" -- Linux 2.0.30 (RH-4.2) x86 +easter = "130.209.247.6" -- Linux 2.0.30 (RH-4.2) x86 + +message = "Hello World" + + +main = + socket AF_INET Stream 6 >>= \ s -> + inet_addr easter >>= \ ia -> + connect s (SockAddrInet (mkPortNumber 5000) ia) >> + + writeSocket s message >> + shutdown s ShutdownBoth >> + sClose s + diff --git a/testsuite/tests/lib/socket/socket002.stdout b/testsuite/tests/lib/socket/socket002.stdout new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/testsuite/tests/lib/socket/socket002.stdout diff --git a/testsuite/tests/lib/socket/socket003.hs b/testsuite/tests/lib/socket/socket003.hs new file mode 100644 index 0000000000..ea88a34dde --- /dev/null +++ b/testsuite/tests/lib/socket/socket003.hs @@ -0,0 +1,43 @@ +{- server + +As for net001 but gets the system to allocate the next free port +number. It also prints out the IP number of the peer. + +TESTS: + getSocketName + inet_ntoa + +-} + +module Main where + +import SocketPrim + + +main = + socket AF_INET Stream 6 >>= \ s -> + bindSocket s (SockAddrInet aNY_PORT iNADDR_ANY) >> + getSocketName s >>= \ (SockAddrInet port _) -> + putStr ("Allocated Port Number: " ++ show port ++ "\n") >> + listen s 5 >> + + + let + loop = + accept s >>= \ (s',(SockAddrInet _ haddr)) -> + inet_ntoa haddr >>= \ na -> + putStr ("*** Start of Transfer from: " ++ na ++ "***\n") >> + let + read_all = + readSocket s' 4 >>= \ (str, nbytes) -> + if nbytes /= 0 then + putStr str >> + read_all + else + putStr "\n*** End of Transfer ***\n" >> + sClose s' + in + read_all + in + loop + diff --git a/testsuite/tests/lib/socket/socket003.stdout b/testsuite/tests/lib/socket/socket003.stdout new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/testsuite/tests/lib/socket/socket003.stdout diff --git a/testsuite/tests/lib/socket/socket004.hs b/testsuite/tests/lib/socket/socket004.hs new file mode 100644 index 0000000000..d7fbdc91bc --- /dev/null +++ b/testsuite/tests/lib/socket/socket004.hs @@ -0,0 +1,38 @@ +{- client + +As for net002 but reads port number and message as arguments. +It also prints out the IP number of the peer machine. + + + +TESTS: + getPeerName +-} + + +module Main(main) where + +import SocketPrim +import System + + +starbuck = "130.209.240.81" +marcus = "130.209.247.2" + +nauru = "130.209.247.5" -- Linux 2.0.30 (RH-4.2) x86 +easter = "130.209.247.6" -- Linux 2.0.30 (RH-4.2) x86 + + +main = + getArgs >>= \ [port, message] -> + socket AF_INET Stream 6 >>= \ s -> + inet_addr easter >>= \ i_addr -> + connect s (SockAddrInet (mkPortNumber (read port)) i_addr) >> + + getPeerName s >>= \ (SockAddrInet p haddr) -> + inet_ntoa haddr >>= \ a -> + putStr ("Connected to : " ++ a ++ "\n") >> + writeSocket s message >> + shutdown s ShutdownBoth >> + sClose s + diff --git a/testsuite/tests/lib/socket/socket004.stdout b/testsuite/tests/lib/socket/socket004.stdout new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/testsuite/tests/lib/socket/socket004.stdout diff --git a/testsuite/tests/lib/socket/socket005.hs b/testsuite/tests/lib/socket/socket005.hs new file mode 100644 index 0000000000..ec504aa480 --- /dev/null +++ b/testsuite/tests/lib/socket/socket005.hs @@ -0,0 +1,37 @@ +{- server + +Server as net001 but for Unix Domain Datagram sockets. + +TESTS: + socket + bindSocket + readSocket + +-} + + +module Main where + +import SocketPrim + + +main = + socket AF_UNIX Datagram 0 >>= \ s -> + bindSocket s (SockAddrUnix "sock") >> + + let + loop = + putStr "*** Start of Transfer ***\n" >> + let + read_all = + readSocket s 1024 >>= \ (str, nbytes) -> + if nbytes /= 0 then + putStr str >> + read_all + else + putStr "\n*** End of Transfer ***\n" + in + read_all + in + loop + diff --git a/testsuite/tests/lib/socket/socket005.stdout b/testsuite/tests/lib/socket/socket005.stdout new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/testsuite/tests/lib/socket/socket005.stdout diff --git a/testsuite/tests/lib/socket/socket006.hs b/testsuite/tests/lib/socket/socket006.hs new file mode 100644 index 0000000000..e2ad13ae49 --- /dev/null +++ b/testsuite/tests/lib/socket/socket006.hs @@ -0,0 +1,27 @@ +{- client + +Client side of net005 + +TESTS: + socket + connect + writeSocket + shutdown + sClose +-} + + +module Main where + +import SocketPrim + +message = "Hello World" + + +main = + socket AF_UNIX Datagram 0 >>= \ s -> + connect s (SockAddrUnix "sock") >> + + writeSocket s message >> + shutdown s ShutdownBoth >> + sClose s diff --git a/testsuite/tests/lib/socket/socket006.stdout b/testsuite/tests/lib/socket/socket006.stdout new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/testsuite/tests/lib/socket/socket006.stdout diff --git a/testsuite/tests/lib/socket/socket007.hs b/testsuite/tests/lib/socket/socket007.hs new file mode 100644 index 0000000000..fbc9ff04e0 --- /dev/null +++ b/testsuite/tests/lib/socket/socket007.hs @@ -0,0 +1,44 @@ +{- server + +As net003 but uses the BSD module for portability. Also prints the +common name of the host rather than its IP number. + +TESTS: + getProtocolNumber + getSocketName + getHostByAddr + +-} + +module Main where + +import BSD +import SocketPrim + +main = + getProtocolNumber "tcp" >>= \ proto -> + socket AF_INET Stream proto >>= \ s -> + bindSocket s (SockAddrInet aNY_PORT iNADDR_ANY) >> + getSocketName s >>= \ (SockAddrInet port _) -> + putStr ("Allocated Port Number: " ++ show port ++ "\n") >> + listen s 5 >> + + + let + loop = + accept s >>= \ (s',(SockAddrInet _ haddr)) -> + getHostByAddr AF_INET haddr >>= \ (HostEntry hname _ _ _) -> + putStr ("*** Start of Transfer from: " ++ hname ++ "***\n") >> + let + read_all = + readSocket s' 4 >>= \ (str, nbytes) -> + if nbytes /= 0 then + putStr str >> + read_all + else + putStr "\n*** End of Transfer ***\n" >> + sClose s' + in + read_all + in + loop diff --git a/testsuite/tests/lib/socket/socket007.stdout b/testsuite/tests/lib/socket/socket007.stdout new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/testsuite/tests/lib/socket/socket007.stdout diff --git a/testsuite/tests/lib/socket/socket008.hs b/testsuite/tests/lib/socket/socket008.hs new file mode 100644 index 0000000000..896763409e --- /dev/null +++ b/testsuite/tests/lib/socket/socket008.hs @@ -0,0 +1,21 @@ +module Main where + +import SocketPrim +import BSD +import System + +main = + getArgs >>= \ [host, port, message] -> + getProtocolNumber "tcp" >>= \ proto -> + socket AF_INET Stream proto >>= \ s -> + getHostByName host >>= \ (HostEntry _ _ _ haddrs) -> + connect s (SockAddrInet (mkPortNumber (read port)) + (head haddrs)) >> + + getPeerName s >>= \ (SockAddrInet _ haddr) -> + getHostByAddr AF_INET haddr >>= \ (HostEntry hname _ _ _) -> + putStr ("Connected to : " ++ hname ++ "\n") >> + writeSocket s message >> + shutdown s ShutdownBoth >> + sClose s + diff --git a/testsuite/tests/lib/socket/socket008.stdout b/testsuite/tests/lib/socket/socket008.stdout new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/testsuite/tests/lib/socket/socket008.stdout diff --git a/testsuite/tests/lib/socket/socket009.hs b/testsuite/tests/lib/socket/socket009.hs new file mode 100644 index 0000000000..c34334e691 --- /dev/null +++ b/testsuite/tests/lib/socket/socket009.hs @@ -0,0 +1,28 @@ +-- Sigbjorn and I don't understand what this test is meant to do +-- It simply hangs on stdin! + +import IO -- 1.3 + +import System(getArgs) + +main = getArgs >>= \ [user,host] -> + let username = (user ++ "@" ++ host) in + openFile username ReadWriteMode >>= \ cd -> + hSetBuffering stdin NoBuffering >> + hSetBuffering stdout NoBuffering >> + hSetBuffering cd NoBuffering >> + hPutStr cd speakString >> + speak cd + +speakString = "Someone wants to speak with you\n" + +speak cd = + (hReady cd >>= \ ready -> + if ready then (hGetChar cd >>= putChar) + else return () >> + + hReady stdin >>= \ ready -> + if ready then (getChar >>= hPutChar cd) + else return ()) >> + + speak cd diff --git a/testsuite/tests/lib/socket/socket009.stdout b/testsuite/tests/lib/socket/socket009.stdout new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/testsuite/tests/lib/socket/socket009.stdout |