X-Git-Url: https://git.martlubbers.net/?a=blobdiff_plain;f=Devices%2FmTaskTCP.icl;h=314799b0c9659bd448fd435717a52a578d8734b2;hb=a2b8b2a0de173f92092bf6cbbed23551e674ca3c;hp=bf05e0549485d2899b800a3b0048f8a1ad70fdca;hpb=00fec1dc0792381759d7cfbfb55f17996a11f1a4;p=mTask.git diff --git a/Devices/mTaskTCP.icl b/Devices/mTaskTCP.icl index bf05e05..314799b 100644 --- a/Devices/mTaskTCP.icl +++ b/Devices/mTaskTCP.icl @@ -1,28 +1,31 @@ implementation module Devices.mTaskTCP +import GenPrint +import StdDebug import Devices.mTaskDevice import iTasks derive class iTask TCPSettings +derive gPrint MTaskMSGRecv getmTaskTCPDevice :: Task MTaskResource getmTaskTCPDevice = TCPDevice <$> enterInformation "Settings" [] instance MTaskDuplex TCPSettings where synFun :: TCPSettings (Shared Channels) -> Task () - synFun s channels = catchAll ( + synFun s channels = tcpconnect s.host s.port channels {ConnectionHandlers| onConnect=onConnect, whileConnected=whileConnected, - onDisconnect=onDisconnect} @! ()) - (\v->traceValue v @! ()) + onDisconnect=onDisconnect} @! () where onConnect :: String ([MTaskMSGRecv],[MTaskMSGSend],Bool) -> (MaybeErrorString String, Maybe ([MTaskMSGRecv],[MTaskMSGSend],Bool), [String], Bool) onConnect _ (msgs,send,sendStopped) = (Ok "", Just (msgs,[],sendStopped), map encode send, False) whileConnected :: (Maybe String) String ([MTaskMSGRecv], [MTaskMSGSend],Bool) -> (MaybeErrorString String, Maybe ([MTaskMSGRecv],[MTaskMSGSend],Bool), [String], Bool) - whileConnected Nothing acc (msgs,send,sendStopped) = (Ok acc, Nothing, [], False) - whileConnected (Just newData) acc (msgs,send,sendStopped) = (Ok acc, Just (msgs ++ [decode newData],[],False), map encode send, False) + whileConnected Nothing _ (_,[],_) = (Ok "", Nothing, [], False) + whileConnected md _ (msgs,send,sendStopped) + = (Ok "", Just (msgs++map decode (maybeToList md),[],sendStopped), map encode send, False) onDisconnect :: String ([MTaskMSGRecv],[MTaskMSGSend],Bool) -> (MaybeErrorString String, Maybe ([MTaskMSGRecv],[MTaskMSGSend],Bool)) - onDisconnect l (msgs,send,sendStopped) = (Ok l, Nothing) + onDisconnect _ (msgs,send,sendStopped) = (Ok "", Nothing)