Commit a7ad8c2f authored by John van Groningen's avatar John van Groningen

fix end of line characters

parent 82bb4b22
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
definition module TCPDef
// ********************************************************************************
// Clean Standard TCP library, version 1.2.2
//
// StdTCPDef provides basic definitions for using TCP.
// Author: Martin Wierich
// Modified: 7 September 2001 for Clean 2.0 (Peter Achten)
// ********************************************************************************
from StdMaybe import :: Maybe
from StdOverloaded import class ==, class toString
from TCPChannelClass import :: DuplexChannel
from tcp import :: IPAddress, :: TCP_Listener_, :: TCP_RChannel_, :: TCP_SChannel_
:: *TCP_SChannel :== TCP_SChannel_ ByteSeq
:: *TCP_RChannel :== TCP_RChannel_ ByteSeq
:: *TCP_Listener :== TCP_Listener_ *(IPAddress, TCP_DuplexChannel)
:: Port :== Int
:: *TCP_DuplexChannel :== DuplexChannel *TCP_SChannel_ *TCP_RChannel_ ByteSeq
:: ByteSeq
// A sequence of bytes
instance toString ByteSeq
instance == ByteSeq
toByteSeq :: !x -> ByteSeq | toString x
byteSeqSize :: !ByteSeq -> Int
// byteSeqSize returns the size in bytes
instance toString IPAddress
// returns ip address in dotted decimal form
// ********************************************************************************
// for multiplexing
// ********************************************************************************
:: *TCP_RChannels = TCP_RChannels *[TCP_RChannel]
:: *TCP_SChannels = TCP_SChannels *[TCP_SChannel]
:: *TCP_Listeners = TCP_Listeners *[TCP_Listener]
:: *PrimitiveRChannel
= TCP_RCHANNEL TCP_RChannel
| TCP_LISTENER TCP_Listener
:: SelectResult
= SR_Available
| SR_EOM
| SR_Sendable
| SR_Disconnected
definition module TCPDef
// ********************************************************************************
// Clean Standard TCP library, version 1.2.2
//
// StdTCPDef provides basic definitions for using TCP.
// Author: Martin Wierich
// Modified: 7 September 2001 for Clean 2.0 (Peter Achten)
// ********************************************************************************
from StdMaybe import :: Maybe
from StdOverloaded import class ==, class toString
from TCPChannelClass import :: DuplexChannel
from tcp import :: IPAddress, :: TCP_Listener_, :: TCP_RChannel_, :: TCP_SChannel_
:: *TCP_SChannel :== TCP_SChannel_ ByteSeq
:: *TCP_RChannel :== TCP_RChannel_ ByteSeq
:: *TCP_Listener :== TCP_Listener_ *(IPAddress, TCP_DuplexChannel)
:: Port :== Int
:: *TCP_DuplexChannel :== DuplexChannel *TCP_SChannel_ *TCP_RChannel_ ByteSeq
:: ByteSeq
// A sequence of bytes
instance toString ByteSeq
instance == ByteSeq
toByteSeq :: !x -> ByteSeq | toString x
byteSeqSize :: !ByteSeq -> Int
// byteSeqSize returns the size in bytes
instance toString IPAddress
// returns ip address in dotted decimal form
// ********************************************************************************
// for multiplexing
// ********************************************************************************
:: *TCP_RChannels = TCP_RChannels *[TCP_RChannel]
:: *TCP_SChannels = TCP_SChannels *[TCP_SChannel]
:: *TCP_Listeners = TCP_Listeners *[TCP_Listener]
:: *PrimitiveRChannel
= TCP_RCHANNEL TCP_RChannel
| TCP_LISTENER TCP_Listener
:: SelectResult
= SR_Available
| SR_EOM
| SR_Sendable
| SR_Disconnected
implementation module TCPDef
import StdEnv,StdMaybe
import TCPChannelClass
import tcp
:: *TCP_SChannel :== TCP_SChannel_ ByteSeq
:: *TCP_RChannel :== TCP_RChannel_ ByteSeq
:: *TCP_Listener :== TCP_Listener_ *(IPAddress, TCP_DuplexChannel)
:: Port :== Int
:: *TCP_DuplexChannel :== DuplexChannel *TCP_SChannel_ *TCP_RChannel_ ByteSeq
:: ByteSeq
= { data :: !{#Char}
}
instance toString ByteSeq
where
toString {data }
= data
instance == ByteSeq
where
(==) bs1 bs2 = (toString bs1) == (toString bs2)
toByteSeq :: !x -> ByteSeq | toString x
toByteSeq x
= { data=toString x }
byteSeqSize :: !ByteSeq -> Int
byteSeqSize {data}
= size data
instance toString IPAddress
where
toString inetHost
= toDottedDecimal (unpack_ipaddr inetHost)
//////////////////////////////// for multiplexing //////////////////////////////////
:: *TCP_RChannels = TCP_RChannels *[TCP_RChannel]
:: *TCP_SChannels = TCP_SChannels *[TCP_SChannel]
:: *TCP_Listeners = TCP_Listeners *[TCP_Listener]
:: *PrimitiveRChannel
= TCP_RCHANNEL TCP_RChannel
| TCP_LISTENER TCP_Listener
:: SelectResult
= SR_Available
| SR_EOM
| SR_Sendable
| SR_Disconnected
implementation module TCPDef
import StdEnv,StdMaybe
import TCPChannelClass
import tcp
:: *TCP_SChannel :== TCP_SChannel_ ByteSeq
:: *TCP_RChannel :== TCP_RChannel_ ByteSeq
:: *TCP_Listener :== TCP_Listener_ *(IPAddress, TCP_DuplexChannel)
:: Port :== Int
:: *TCP_DuplexChannel :== DuplexChannel *TCP_SChannel_ *TCP_RChannel_ ByteSeq
:: ByteSeq
= { data :: !{#Char}
}
instance toString ByteSeq
where
toString {data }
= data
instance == ByteSeq
where
(==) bs1 bs2 = (toString bs1) == (toString bs2)
toByteSeq :: !x -> ByteSeq | toString x
toByteSeq x
= { data=toString x }
byteSeqSize :: !ByteSeq -> Int
byteSeqSize {data}
= size data
instance toString IPAddress
where
toString inetHost
= toDottedDecimal (unpack_ipaddr inetHost)
//////////////////////////////// for multiplexing //////////////////////////////////
:: *TCP_RChannels = TCP_RChannels *[TCP_RChannel]
:: *TCP_SChannels = TCP_SChannels *[TCP_SChannel]
:: *TCP_Listeners = TCP_Listeners *[TCP_Listener]
:: *PrimitiveRChannel
= TCP_RCHANNEL TCP_RChannel
| TCP_LISTENER TCP_Listener
:: SelectResult
= SR_Available
| SR_EOM
| SR_Sendable
| SR_Disconnected
definition module TCPEvent
// ********************************************************************************
// Clean Standard TCP library, version 1.2.2
//
// StdEventTCP provides functions for using event driven TCP
// Author: Martin Wierich
// Modified: 15 October 2001 for Clean 2.0 (Peter Achten)
// ********************************************************************************
import TCPChannelClass, TCPDef
from tcp_bytestreams import :: TCP_SCharStream_
class accSChannel ch :: (TCP_SChannel -> (x, TCP_SChannel)) *(ch .a)
-> (x, *(ch .a))
/* This overloaded function supports the openSendNotifier function. It applies an
access function on the underlying TCP_SChannel
*/
instance accSChannel TCP_SChannel_
instance accSChannel TCP_SCharStream_
definition module TCPEvent
// ********************************************************************************
// Clean Standard TCP library, version 1.2.2
//
// StdEventTCP provides functions for using event driven TCP
// Author: Martin Wierich
// Modified: 15 October 2001 for Clean 2.0 (Peter Achten)
// ********************************************************************************
import TCPChannelClass, TCPDef
from tcp_bytestreams import :: TCP_SCharStream_
class accSChannel ch :: (TCP_SChannel -> (x, TCP_SChannel)) *(ch .a)
-> (x, *(ch .a))
/* This overloaded function supports the openSendNotifier function. It applies an
access function on the underlying TCP_SChannel
*/
instance accSChannel TCP_SChannel_
instance accSChannel TCP_SCharStream_
implementation module TCPEvent
import StdEnv
import TCPChannelClass, TCPDef, TCPChannels
class accSChannel ch :: (TCP_SChannel -> (x, TCP_SChannel)) *(ch .a) -> (x, *(ch .a))
instance accSChannel TCP_SChannel_ where
accSChannel f tcpSChanPolymorph
#! (x, tcpSChanByteSeq) = f (Cast tcpSChanPolymorph)
= (x, Cast tcpSChanByteSeq)
instance accSChannel TCP_SCharStream_ where
accSChannel f sChannel=:{sbs_schan}
#! (x, sbs_schan) = f sbs_schan
= (x, { sChannel & sbs_schan=sbs_schan })
Cast :: !.a -> .b
Cast a
= code
{
pop_a 0
}
implementation module TCPEvent
import StdEnv
import TCPChannelClass, TCPDef, TCPChannels
class accSChannel ch :: (TCP_SChannel -> (x, TCP_SChannel)) *(ch .a) -> (x, *(ch .a))
instance accSChannel TCP_SChannel_ where
accSChannel f tcpSChanPolymorph
#! (x, tcpSChanByteSeq) = f (Cast tcpSChanPolymorph)
= (x, Cast tcpSChanByteSeq)
instance accSChannel TCP_SCharStream_ where
accSChannel f sChannel=:{sbs_schan}
#! (x, sbs_schan) = f sbs_schan
= (x, { sChannel & sbs_schan=sbs_schan })
Cast :: !.a -> .b
Cast a
= code
{
pop_a 0
}
definition module TCPIP
import TCPChannelClass,
TCPChannels,
TCPEvent,
TCPStringChannels,
TCPDef
definition module TCPIP
import TCPChannelClass,
TCPChannels,
TCPEvent,
TCPStringChannels,
TCPDef
implementation module TCPIP
implementation module TCPIP
definition module TCPStringChannels
// ********************************************************************************
// Clean Standard TCP library, version 1.2.2
//
// StdStringChannels provides channel instances to send and receive Strings.
// These channels use their own protocol above TCP.
// Author: Martin Wierich
// Modified: 7 September 2001 for Clean 2.0 (Peter Achten)
// ********************************************************************************
import StdString
import TCPDef, TCPChannelClass, TCPEvent
from TCPChannels import class getNrOfChannels, class SelectReceive, class SelectSend
/* If a string via a StringChannel is sent, then first the length of the string is
sent, and then the string itself, e.g. sending the string "abc" will result in
"3 abc\xD"
*/
// ********************************************************************************
// StringChannels to receive
// ********************************************************************************
from TCPStringChannelsInternal import ::StringRChannel_
:: *StringRChannel :== StringRChannel_ String
:: *StringRChannels = StringRChannels *[StringRChannel]
toStringRChannel :: TCP_RChannel -> StringRChannel
instance Receive StringRChannel_
instance closeRChannel StringRChannel_
instance MaxSize StringRChannel_
// ********************************************************************************
// StringChannels to send
// ********************************************************************************
:: *StringSChannel_ a
:: *StringSChannel :== StringSChannel_ String
:: *StringSChannels = StringSChannels *[StringSChannel]
toStringSChannel :: TCP_SChannel -> StringSChannel
instance Send StringSChannel_
// For openSendNotifier, closeSendNotifier
instance accSChannel StringSChannel_
// For selectChannel
instance SelectSend StringSChannels
instance SelectReceive StringRChannels
instance getNrOfChannels StringRChannels
definition module TCPStringChannels
// ********************************************************************************
// Clean Standard TCP library, version 1.2.2
//
// StdStringChannels provides channel instances to send and receive Strings.
// These channels use their own protocol above TCP.
// Author: Martin Wierich
// Modified: 7 September 2001 for Clean 2.0 (Peter Achten)
// ********************************************************************************
import StdString
import TCPDef, TCPChannelClass, TCPEvent
from TCPChannels import class getNrOfChannels, class SelectReceive, class SelectSend
/* If a string via a StringChannel is sent, then first the length of the string is
sent, and then the string itself, e.g. sending the string "abc" will result in
"3 abc\xD"
*/
// ********************************************************************************
// StringChannels to receive
// ********************************************************************************
from TCPStringChannelsInternal import ::StringRChannel_
:: *StringRChannel :== StringRChannel_ String
:: *StringRChannels = StringRChannels *[StringRChannel]
toStringRChannel :: TCP_RChannel -> StringRChannel
instance Receive StringRChannel_
instance closeRChannel StringRChannel_
instance MaxSize StringRChannel_
// ********************************************************************************
// StringChannels to send
// ********************************************************************************
:: *StringSChannel_ a
:: *StringSChannel :== StringSChannel_ String
:: *StringSChannels = StringSChannels *[StringSChannel]
toStringSChannel :: TCP_SChannel -> StringSChannel
instance Send StringSChannel_
// For openSendNotifier, closeSendNotifier
instance accSChannel StringSChannel_
// For selectChannel
instance SelectSend StringSChannels
instance SelectReceive StringRChannels
instance getNrOfChannels StringRChannels
This diff is collapsed.
definition module TCPStringChannelsInternal
from TCPDef import ::TCP_RChannel,::TCP_RChannel_,::ByteSeq
// a StringChannel has three states:
:: *ReadPhase = ReadingLength !Int // the channel is currently reading the length of the next
// string. The integer is the length that has been read
// up until now.
| ReadingString !*{#Char} !Int !Int // the channel is currently receiving the next string
// For (ReadingString toFill filled s) it holds:
// s==size toFill=="the size that the next receivable string will have"
// filled characters already have been received and written into toFill
| EndOfMessages // the underlying tcp channel is eom or a string that is too big is received
:: *StringRChannel_ a
= { tcp_rchan :: !TCP_RChannel
, readPhase :: !ReadPhase
, receivedStrings :: ![String]
, maxSize :: !Int
}
addString :: !(!String, !Int) !ReadPhase !Int -> (![String], !ReadPhase)
definition module TCPStringChannelsInternal
from TCPDef import ::TCP_RChannel,::TCP_RChannel_,::ByteSeq
// a StringChannel has three states:
:: *ReadPhase = ReadingLength !Int // the channel is currently reading the length of the next
// string. The integer is the length that has been read
// up until now.
| ReadingString !*{#Char} !Int !Int // the channel is currently receiving the next string
// For (ReadingString toFill filled s) it holds:
// s==size toFill=="the size that the next receivable string will have"
// filled characters already have been received and written into toFill
| EndOfMessages // the underlying tcp channel is eom or a string that is too big is received
:: *StringRChannel_ a
= { tcp_rchan :: !TCP_RChannel
, readPhase :: !ReadPhase
, receivedStrings :: ![String]
, maxSize :: !Int
}
addString :: !(!String, !Int) !ReadPhase !Int -> (![String], !ReadPhase)
implementation module TCPStringChannelsInternal
import StdEnv
import TCPChannelClass, TCPDef, TCPChannels, TCPEvent
//from tcp import ::Tick,class ChannelEnv (channel_env_get_current_tick)
addString :: !(!String, !Int) !ReadPhase !Int -> (![String], !ReadPhase)
/* addString (s,i) rp maxSize
performs a state transition on the ReadPhase which reflects the receiving of (s % (i,(size s)-1))
*/
addString _ readPhase=:EndOfMessages _
= ([], readPhase)
addString (string, stringBegin) readPhase=:(ReadingLength l) maxSize
| stringBegin>=size string
= ([], readPhase)
#! chList = [ string.[i] \\ i<-[stringBegin..(size string)-1] ]
digits = takeWhile isDigit chList
newL = seq (map transition digits) l
// converts character list into an integer
| newL>maxSize && maxSize>0
= ([], EndOfMessages)
| length digits < size string - stringBegin
// the whole number has been read
= addString (string, stringBegin+(length digits)+1) (ReadingString (createArray newL ' ') newL newL) maxSize
// there are still some digits unread
= ([], ReadingLength newL)
where
transition digit int
= 10*int + (digitToInt digit)
addString (string, stringBegin) readPhase=:(ReadingString wholeString stillToReceive total) maxSize
| stringBegin>=size string
= ([], readPhase)
#! readyBytes = (size string) - stringBegin
| stillToReceive<=readyBytes
// wholeString can be filled totally
#! wholeString = strcpy wholeString (total-stillToReceive)
string stringBegin
stillToReceive
newBegin = stringBegin + stillToReceive + 1
(otherStrings, readPhase) = addString (string, newBegin) (ReadingLength 0) maxSize
= ([wholeString:otherStrings], readPhase)
// wholeString can not be filled totally
#! wholeString = strcpy wholeString (total-stillToReceive)
string stringBegin
readyBytes
= ([], ReadingString wholeString (stillToReceive-readyBytes) total)
strcpy :: !*{#Char} !Int !{#Char} !Int !Int -> *{#Char}
strcpy dest destBegin src srcBegin nrOfBytes
| nrOfBytes<=0
= dest
= strcpy { dest & [destBegin] = src.[srcBegin] } (inc destBegin) src (inc srcBegin) (dec nrOfBytes)
implementation module TCPStringChannelsInternal
import StdEnv
import TCPChannelClass, TCPDef, TCPChannels, TCPEvent
//from tcp import ::Tick,class ChannelEnv (channel_env_get_current_tick)
addString :: !(!String, !Int) !ReadPhase !Int -> (![String], !ReadPhase)
/* addString (s,i) rp maxSize
performs a state transition on the ReadPhase which reflects the receiving of (s % (i,(size s)-1))
*/
addString _ readPhase=:EndOfMessages _
= ([], readPhase)
addString (string, stringBegin) readPhase=:(ReadingLength l) maxSize
| stringBegin>=size string
= ([], readPhase)
#! chList = [ string.[i] \\ i<-[stringBegin..(size string)-1] ]
digits = takeWhile isDigit chList
newL = seq (map transition digits) l
// converts character list into an integer
| newL>maxSize && maxSize>0
= ([], EndOfMessages)
| length digits < size string - stringBegin
// the whole number has been read
= addString (string, stringBegin+(length digits)+1) (ReadingString (createArray newL ' ') newL newL) maxSize
// there are still some digits unread
= ([], ReadingLength newL)
where
transition digit int
= 10*int + (digitToInt digit)
addString (string, stringBegin) readPhase=:(ReadingString wholeString stillToReceive total) maxSize
| stringBegin>=size string
= ([], readPhase)
#! readyBytes = (size string) - stringBegin
| stillToReceive<=readyBytes
// wholeString can be filled totally
#! wholeString = strcpy wholeString (total-stillToReceive)
string stringBegin
stillToReceive
newBegin = stringBegin + stillToReceive + 1
(otherStrings, readPhase) = addString (string, newBegin) (ReadingLength 0) maxSize
= ([wholeString:otherStrings], readPhase)
// wholeString can not be filled totally
#! wholeString = strcpy wholeString (total-stillToReceive)
string stringBegin
readyBytes
= ([], ReadingString wholeString (stillToReceive-readyBytes) total)
strcpy :: !*{#Char} !Int !{#Char} !Int !Int -> *{#Char}
strcpy dest destBegin src srcBegin nrOfBytes
| nrOfBytes<=0
= dest
= strcpy { dest & [destBegin] = src.[srcBegin] } (inc destBegin) src (inc srcBegin) (dec nrOfBytes)
This diff is collapsed.
definition module tcp_bytestreams
// ********************************************************************************
// Clean Standard TCP library, version 1.2.2
//
// Author: Martin Wierich
// Modified: 7 September 2001 for Clean 2.0 (Peter Achten)
// ********************************************************************************