Movatterモバイル変換
[0]ホーム
{-# LANGUAGE Unsafe #-}{-# LANGUAGE ExistentialQuantification, NoImplicitPrelude #-}moduleGHC.Event.Internal(-- * Event back endBackend,backend,delete,poll,modifyFd,modifyFdOnce-- * Event type,Event,evtRead,evtWrite,evtClose,eventIs-- * Lifetimes,Lifetime(..),EventLifetime,eventLifetime,elLifetime,elEvent-- * Timeout type,Timeout(..)-- * Helpers,throwErrnoIfMinus1NoRetry)whereimportData.Bits((.|.),(.&.))importData.OldList(foldl',filter,intercalate,null)importForeign.C.Error(eINTR,getErrno,throwErrno)importSystem.Posix.Types(Fd)importGHC.BaseimportGHC.Word(Word64)importGHC.Num(Num(..))importGHC.Show(Show(..))importData.Semigroup.Internal(stimesMonoid)-- | An I\/O event.newtypeEvent=EventIntderivingEq-- ^ @since 4.4.0.0evtNothing::EventevtNothing=Event0{-# INLINEevtNothing#-}-- | Data is available to be read.evtRead::EventevtRead=Event1{-# INLINEevtRead#-}-- | The file descriptor is ready to accept a write.evtWrite::EventevtWrite=Event2{-# INLINEevtWrite#-}-- | Another thread closed the file descriptor.evtClose::EventevtClose=Event4{-# INLINEevtClose#-}eventIs::Event->Event->BooleventIs(Eventa)(Eventb)=a.&.b/=0-- | @since 4.4.0.0instanceShowEventwhereshowe='[':(intercalate",".filter(not.null)$[evtRead`so`"evtRead",evtWrite`so`"evtWrite",evtClose`so`"evtClose"])++"]"whereev`so`disp|e`eventIs`ev=disp|otherwise=""-- | @since 4.10.0.0instanceSemigroupEventwhere(<>)=evtCombinestimes=stimesMonoid-- | @since 4.4.0.0instanceMonoidEventwheremempty=evtNothingmconcat=evtConcatevtCombine::Event->Event->EventevtCombine(Eventa)(Eventb)=Event(a.|.b){-# INLINEevtCombine#-}evtConcat::[Event]->EventevtConcat=foldl'evtCombineevtNothing{-# INLINEevtConcat#-}-- | The lifetime of an event registration.---- @since 4.8.1.0dataLifetime=OneShot-- ^ the registration will be active for only one-- event|MultiShot-- ^ the registration will trigger multiple timesderiving(Show-- ^ @since 4.8.1.0,Eq-- ^ @since 4.8.1.0)-- | The longer of two lifetimes.elSupremum::Lifetime->Lifetime->LifetimeelSupremumOneShotOneShot=OneShotelSupremum__=MultiShot{-# INLINEelSupremum#-}-- | @since 4.10.0.0instanceSemigroupLifetimewhere(<>)=elSupremumstimes=stimesMonoid-- | @mappend@ takes the longer of two lifetimes.---- @since 4.8.0.0instanceMonoidLifetimewheremempty=OneShot-- | A pair of an event and lifetime---- Here we encode the event in the bottom three bits and the lifetime-- in the fourth bit.newtypeEventLifetime=ELIntderiving(Show-- ^ @since 4.8.0.0,Eq-- ^ @since 4.8.0.0)-- | @since 4.11.0.0instanceSemigroupEventLifetimewhereELa<>ELb=EL(a.|.b)-- | @since 4.8.0.0instanceMonoidEventLifetimewheremempty=EL0eventLifetime::Event->Lifetime->EventLifetimeeventLifetime(Evente)l=EL(e.|.lifetimeBitl)wherelifetimeBitOneShot=0lifetimeBitMultiShot=8{-# INLINEeventLifetime#-}elLifetime::EventLifetime->LifetimeelLifetime(ELx)=ifx.&.8==0thenOneShotelseMultiShot{-# INLINEelLifetime#-}elEvent::EventLifetime->EventelEvent(ELx)=Event(x.&.0x7){-# INLINEelEvent#-}-- | A type alias for timeouts, specified in nanoseconds.dataTimeout=Timeout{-# UNPACK#-}!Word64|ForeverderivingShow-- ^ @since 4.4.0.0-- | Event notification backend.dataBackend=foralla.Backend{_beState::!a-- | Poll backend for new events. The provided callback is called-- once per file descriptor with new events.,_bePoll::a-- backend state->MaybeTimeout-- timeout in milliseconds ('Nothing' for non-blocking poll)->(Fd->Event->IO())-- I/O callback->IOInt-- | Register, modify, or unregister interest in the given events-- on the given file descriptor.,_beModifyFd::a->Fd-- file descriptor->Event-- old events to watch for ('mempty' for new)->Event-- new events to watch for ('mempty' to delete)->IOBool-- | Register interest in new events on a given file descriptor, set-- to be deactivated after the first event.,_beModifyFdOnce::a->Fd-- file descriptor->Event-- new events to watch->IOBool,_beDelete::a->IO()}backend::(a->MaybeTimeout->(Fd->Event->IO())->IOInt)->(a->Fd->Event->Event->IOBool)->(a->Fd->Event->IOBool)->(a->IO())->a->BackendbackendbPollbModifyFdbModifyFdOncebDeletestate=BackendstatebPollbModifyFdbModifyFdOncebDelete{-# INLINEbackend#-}poll::Backend->MaybeTimeout->(Fd->Event->IO())->IOIntpoll(BackendbStatebPoll___)=bPollbState{-# INLINEpoll#-}-- | Returns 'True' if the modification succeeded.-- Returns 'False' if this backend does not support-- event notifications on this type of file.modifyFd::Backend->Fd->Event->Event->IOBoolmodifyFd(BackendbState_bModifyFd__)=bModifyFdbState{-# INLINEmodifyFd#-}-- | Returns 'True' if the modification succeeded.-- Returns 'False' if this backend does not support-- event notifications on this type of file.modifyFdOnce::Backend->Fd->Event->IOBoolmodifyFdOnce(BackendbState__bModifyFdOnce_)=bModifyFdOncebState{-# INLINEmodifyFdOnce#-}delete::Backend->IO()delete(BackendbState___bDelete)=bDeletebState{-# INLINEdelete#-}-- | Throw an 'IOError' corresponding to the current value of-- 'getErrno' if the result value of the 'IO' action is -1 and-- 'getErrno' is not 'eINTR'. If the result value is -1 and-- 'getErrno' returns 'eINTR' 0 is returned. Otherwise the result-- value is returned.throwErrnoIfMinus1NoRetry::(Eqa,Numa)=>String->IOa->IOathrowErrnoIfMinus1NoRetrylocf=dores<-fifres==-1thendoerr<-getErrnoiferr==eINTRthenreturn0elsethrowErrnolocelsereturnres
[8]ページ先頭