Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
GHC
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Gesh
GHC
Commits
1a8ef592
Commit
1a8ef592
authored
26 years ago
by
sof
Browse files
Options
Downloads
Patches
Plain Diff
[project @ 1998-08-14 13:06:28 by sof]
socketToHandle changed to use new IO impl
parent
dc94052c
Loading
Loading
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
ghc/lib/misc/SocketPrim.lhs
+48
-33
48 additions, 33 deletions
ghc/lib/misc/SocketPrim.lhs
with
48 additions
and
33 deletions
ghc/lib/misc/SocketPrim.lhs
+
48
−
33
View file @
1a8ef592
...
...
@@ -42,8 +42,6 @@ module SocketPrim (
-- sendmsg -- :: Socket -> Message -> MsgFlags -> IO Int
-- recvmsg -- :: Socket -> MsgFlags -> IO Message
shutdown, -- :: Socket -> ShutdownCmd -> IO ()
sClose, -- :: Socket -> IO ()
inet_addr, -- :: String -> IO HostAddress
inet_ntoa, -- :: HostAddress -> IO String
...
...
@@ -53,6 +51,8 @@ module SocketPrim (
sIsListening, -- :: Socket -> IO Bool
sIsReadable, -- :: Socket -> IO Bool
sIsWritable, -- :: Socket -> IO Bool
shutdown, -- :: Socket -> ShutdownCmd -> IO ()
sClose, -- :: Socket -> IO ()
-- socket opts
SocketOption(..),
...
...
@@ -71,7 +71,7 @@ module SocketPrim (
-- The following are exported ONLY for use in the BSD module and
-- should not be used
else wher
e.
-- should not be used
anywhere els
e.
packFamily, unpackFamily,
packSocketType,
...
...
@@ -163,6 +163,13 @@ type HostAddress = Word
newtype PortNumber = PNum Int -- 16-bit value stored in network byte order.
deriving ( Eq )
instance Show PortNumber where
showsPrec p (PNum pn) = showsPrec p pn_host
where
pn_host :: Int
pn_host = unsafePerformIO (_casm_ ``%r=(int)ntohs((int)%0); '' pn)
mkPortNumber :: Int -> PortNumber
mkPortNumber v = unsafePerformIO $ do
po <- _casm_ ``%r=(int)htons((int)%0); '' v
...
...
@@ -423,7 +430,7 @@ readSocket (MkSocket s family stype protocol status) nbytes = do
fail (userError ("readSocket: can't perform read on socket in status " ++
show currentStatus))
else do
ptr <- stToIO (newCharArray (
0
, nbytes))
ptr <- stToIO (newCharArray (
1
, nbytes))
nbytes <- _ccall_ readDescriptor s ptr nbytes
case nbytes of
-1 -> constructErrorAndFail "readSocket"
...
...
@@ -524,45 +531,49 @@ getSocketName (MkSocket s family stype protocol status) = do
\begin{code}
data SocketOption
=
Broadcast
{- SO_
BROADCAST
-}
|
Debug
{- SO_
DEBUG
-}
|
DontRoute
{- SO_
DONTROUTE
-}
=
Debug
{- SO_
DEBUG
-}
|
ReuseAddr
{- SO_
REUSEADDR
-}
|
Type
{- SO_
TYPE
-}
| SoError {- SO_ERROR -}
| DontRoute {- SO_DONTROUTE -}
| Broadcast {- SO_BROADCAST -}
| SendBuffer {- SO_SNDBUF -}
| RecvBuffer {- SO_RCVBUF -}
| KeepAlive {- SO_KEEPALIVE -}
-- | Linger {- SO_LINGER -}
| OOBInline {- SO_OOBINLINE -}
| RecvBuffer {- SO_RCVBUF -}
| SendBuffer {- SO_SNDBUF -}
| MaxSegment {- TCP_MAXSEG -}
| NoDelay {- TCP_NODELAY -}
-- | Linger {- SO_LINGER -}
#if 0
| RecvLowWater {- SO_RCVLOWAT -}
| SendLowWater {- SO_SNDLOWAT -}
| RecvTimeOut {- SO_RCVTIMEO -}
| SendTimeOut {- SO_SNDTIMEO -}
| ReuseAddr {- SO_REUSEADDR -}
| Type {- SO_TYPE -}
| UseLoopBack {- SO_USELOOPBACK -} -- not used, I believe.
| MaxSegment {- TCP_MAXSEG -}
| NoDelay {- TCP_NODELAY -}
#endif
packSocketOption :: SocketOption -> Int
packSocketOption so =
case so of
Broadcast -> ``SO_BROADCAST''
Debug -> ``SO_DEBUG''
DontRoute -> ``SO_DONTROUTE''
ReuseAddr -> ``SO_REUSEADDR''
Type -> ``SO_TYPE''
SoError -> ``SO_ERROR''
DontRoute -> ``SO_DONTROUTE''
Broadcast -> ``SO_BROADCAST''
SendBuffer -> ``SO_SNDBUF''
RecvBuffer -> ``SO_RCVBUF''
KeepAlive -> ``SO_KEEPALIVE''
OOBInline -> ``SO_OOBINLINE''
RecvBuffer -> ``SO_RCVBUF''
SendBuffer -> ``SO_SNDBUF''
MaxSegment -> ``TCP_MAXSEG''
NoDelay -> ``TCP_NODELAY''
#if 0
RecvLowWater -> ``SO_RCVLOWAT''
SendLowWater -> ``SO_SNDLOWAT''
RecvTimeOut -> ``SO_RCVTIMEO''
SendTimeOut -> ``SO_SNDTIMEO''
ReuseAddr -> ``SO_REUSEADDR''
Type -> ``SO_TYPE''
UseLoopBack -> ``SO_USELOOPBACK''
MaxSegment -> ``TCP_MAXSEG''
NoDelay -> ``TCP_NODELAY''
#endif
setSocketOption :: Socket
-> SocketOption -- Option Name
...
...
@@ -982,7 +993,9 @@ packSocketType stype = 1 + (index (Stream, Packet) stype)
%************************************************************************
\begin{code}
aNY_PORT = 0::Int
aNY_PORT :: PortNumber
aNY_PORT = mkPortNumber 0
iNADDR_ANY :: HostAddress
iNADDR_ANY = unsafePerformIO (_casm_ `` %r = htonl(INADDR_ANY); '')
...
...
@@ -1172,19 +1185,21 @@ it subsequently.
#ifndef __PARALLEL_HASKELL__
socketToHandle :: Socket -> IOMode -> IO Handle
socketToHandle (MkSocket
s
family stype protocol status) m = do
ptr
<- _c
asm_ ``%r = fdopen (%0, (char *)%1);'' s m'
f
p
<- makeForeignObj
ptr
(``&freeFile'' :: Addr)
hndl <- newHandle (htype fp Nothing False)
h
SetBuffering hndl NoBuffering
socketToHandle (MkSocket
fd
family stype protocol status) m = do
fo
<- _c
call_ openFd fd file_mode flush_on_close
f
o
<- makeForeignObj
fo
(``&freeFile
Object
'' :: Addr)
mkBuffer__ fo 0 -- not buffered
h
ndl <- newHandle (Handle__ fo htype NoBuffering socket_str)
return hndl
where
m' =
socket_str = "<socket: "++show fd
(flush_on_close, file_mode) =
case m of
ReadMode -> "r"
WriteMode -> "w"
AppendMode -> "a"
ReadWriteMode -> "r+"
AppendMode -> (1, 0)
WriteMode -> (1, 1)
ReadMode -> (0, 2)
ReadWriteMode -> (1, 3)
htype =
case m of
ReadMode -> ReadHandle
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment