<commit_before>{-# LANGUAGE OverloadedStrings #-}
module Main where

import Control.Monad
import Control.Exception
import Control.Concurrent
import Control.Concurrent.Async

import Data.Int
import Data.Monoid
import qualified Data.ByteString.Lazy as LBS

import System.Socket
import System.Socket.Family.Inet as Inet

main :: IO ()
main = do
  bracket
      ( do  server <- socket `onException` print "E01" :: IO (Socket Inet Stream TCP)
            client <- socket `onException` print "E02" :: IO (Socket Inet Stream TCP)
            return (server, client)
      )
      (\(server,client)-> do
            close server                                        `onException` print "E03"
            close client                                        `onException` print "E04"
      )
      (\(server,client)-> do
            bind server addr                                    `onException` print "E06"
            listen server 5                                     `onException` print "E07"

            connect client addr                                 `onException` print "E08"
            (peerSock, _) <- accept server                      `onException` print "E09"
            _ <- send client "This should be received." mempty  `onException` print "E10"
            _ <- receive peerSock 4096 mempty                   `onException` print "E11"
            close peerSock                                      `onException` print "E12"

            e1 <- try $ send client "This might fail."  mempty  `onException` print "E13"
            case e1 of
              Right _ -> return ()
              Left  e -> if e == ePipe
                           then return ()
                           else throwIO e                       `onException` print "E14"

            e2 <- try $ send client "This should fail." mempty  `onException` print "E15"<commit_msg>Added additional delay to relax the inherent race condition.<commit_after>{-# LANGUAGE OverloadedStrings #-}
module Main where

import Control.Monad
import Control.Exception
import Control.Concurrent
import Control.Concurrent.Async

import Data.Int
import Data.Monoid
import qualified Data.ByteString.Lazy as LBS

import System.Socket
import System.Socket.Family.Inet as Inet

main :: IO ()
main = do
  bracket
      ( do  server <- socket `onException` print "E01" :: IO (Socket Inet Stream TCP)
            client <- socket `onException` print "E02" :: IO (Socket Inet Stream TCP)
            return (server, client)
      )
      (\(server,client)-> do
            close server                                        `onException` print "E03"
            close client                                        `onException` print "E04"
      )
      (\(server,client)-> do
            bind server addr                                    `onException` print "E06"
            listen server 5                                     `onException` print "E07"

            connect client addr                                 `onException` print "E08"
            (peerSock, _) <- accept server                      `onException` print "E09"
            _ <- send client "This should be received." mempty  `onException` print "E10"
            _ <- receive peerSock 4096 mempty                   `onException` print "E11"
            close peerSock                                      `onException` print "E12"

            threadDelay 1000000

            e1 <- try $ send client "This might fail."  mempty  `onException` print "E13"
            case e1 of
              Right _ -> return ()
              Left  e -> if e == ePipe
                           then return ()
                           else throwIO e                       `onException` print "E14"

            threadDelay 1000000

            e2 <- try $ send client "This should fail." mempty  `onException` print "E15"
{'fraction_non_alphanumeric': 0.07772290096178841, 'fraction_numerical': 0.022355081881985962, 'mean_word_length': 1.3782447466007417, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 14, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6090590', 'n_tokens_mistral': 1002, 'n_tokens_neox': 914, 'n_words': 327}