<commit_before>module Main where
	
import System.IO
import Data.Char (toUpper)
import Data.Bits
--import Network.Socket
import Network.BSD
import Data.List
import Data.Binary
import qualified Data.ByteString.Lazy as LBS
import qualified Data.ByteString as BS
import Data.Char as Char
import Network.Socket hiding (send, sendTo, recv, recvFrom)
import Network.Socket.ByteString
import Control.Concurrent
import Control.Concurrent.MVar
import System.Timeout 
import System.Random

import Prelude hiding (getContents)

import Foreign.LambdaBridge.Service
import Foreign.LambdaBridge.ARQ

-- This Bridge service uses UDP to send and recieve requests,
-- over (default) port 9237.

-- How much to listen for

maxPacketSize :: Int
maxPacketSize = 2000

data SessionHandle = SessionHandle Socket SockAddr

main = bridge_service $ \ args sends recvs -> do
	hPutStrLn stderr "Remote Service:"
	case (args,sends,recvs) of
	  (remote_cmd:hostname:port:rest,[s],[r]) -> do
		print $ "got" ++ show (hostname,port,rest,s,r)
		let rnd = NoRandomErrors

 		addrinfos <- getAddrInfo 
                    (Just (defaultHints {addrFlags = [AI_PASSIVE]}))
                    (Just hostname) (Just port)
		let serveraddr = head addrinfos

       		sock <- socket AF_INET Datagram defaultProtocol

	 	connect sock $ addrAddress serveraddr

		protocol <- arqProtocol $ ARQ_Options
			{ toSocket 	  = sendAll sock
			, fromSocket 	  = recv sock (fromIntegral maxPacketSize)
			, transmitFailure = Nothing
			, receiveFailure  = Nothing
			}

		forkIO $ 
		   let loop = do
			hWaitForInput s (-1)
			bs <- BS.hGetNonBlocking s 100	-- 100???<commit_msg>Send first volley, aka our protocol<commit_after>module Main where
	
import System.IO
import Data.Char (toUpper)
import Data.Bits
--import Network.Socket
import Network.BSD
import Data.List
import Data.Binary
import qualified Data.ByteString.Lazy as LBS
import qualified Data.ByteString as BS
import Data.Char as Char
import Network.Socket hiding (send, sendTo, recv, recvFrom)
import Network.Socket.ByteString
import Control.Concurrent
import Control.Concurrent.MVar
import System.Timeout 
import System.Random

import Prelude hiding (getContents)

import Foreign.LambdaBridge.Service
import Foreign.LambdaBridge.ARQ

-- This Bridge service uses UDP to send and recieve requests,
-- over (default) port 9237.

-- How much to listen for

maxPacketSize :: Int
maxPacketSize = 2000

data SessionHandle = SessionHandle Socket SockAddr

main = bridge_service $ \ args sends recvs -> do
	hPutStrLn stderr "Remote Service:"
	case (args,sends,recvs) of
	  (remote_cmd:hostname:port:rest,[s],[r]) -> do
		print $ "got" ++ show (hostname,port,rest,s,r)
		let rnd = NoRandomErrors

 		addrinfos <- getAddrInfo 
                    (Just (defaultHints {addrFlags = [AI_PASSIVE]}))
                    (Just hostname) (Just port)
		let serveraddr = head addrinfos

       		sock <- socket AF_INET Datagram defaultProtocol

	 	connect sock $ addrAddress serveraddr

		protocol <- arqProtocol $ ARQ_Options
			{ toSocket 	  = sendAll sock
			, fromSocket 	  = recv sock (fromIntegral maxPacketSize)
			, transmitFailure = Nothing
			, receiveFailure  = Nothing
			}

		-- Send first volley, to start the service
		sendByteString protocol (0,BS.pack [0xde,0xad,0xbe,0xef])

		forkIO $ 
		   let loop = do
			hWaitForInput s (-1)
			bs <- BS.hGetNonBlocking s 100	-- 100???
{'fraction_non_alphanumeric': 0.08298877731836976, 'fraction_numerical': 0.010336680448907265, 'mean_word_length': 3.627049180327869, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3262584', 'n_tokens_mistral': 1143, 'n_tokens_neox': 1020, 'n_words': 329}