Skip to content

Commit

Permalink
Revert "Add connectionAddr and pendingAddr to connection data type"
Browse files Browse the repository at this point in the history
This reverts commit 9035faf.
  • Loading branch information
jaspervdj committed Aug 1, 2015
1 parent b52586f commit d1f7eeb
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 15 deletions.
1 change: 0 additions & 1 deletion src/Network/WebSockets/Client.hs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ runClientWithStream stream host path opts customHeaders app = do
, connectionParse = parse
, connectionWrite = write
, connectionSentClose = sentRef
, connectionAddr = S.SockAddrUnix "No address"
}
where
protocol = defaultProtocol -- TODO
Expand Down
6 changes: 0 additions & 6 deletions src/Network/WebSockets/Connection.hs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ import Data.List (find)
import qualified Data.Text as T
import Data.Word (Word16)

import qualified Network.Socket as S

--------------------------------------------------------------------------------
import Network.WebSockets.Http
Expand All @@ -65,8 +64,6 @@ data PendingConnection = PendingConnection
-- the accepting response is sent to the client.
, pendingStream :: !Stream
-- ^ Input/output stream
, pendingAddr :: !S.SockAddr
-- ^ Peer socket address
}


Expand Down Expand Up @@ -112,7 +109,6 @@ acceptRequestWith pc ar = case find (flip compatible request) protocols of
, connectionParse = parse
, connectionWrite = write
, connectionSentClose = sentRef
, connectionAddr = pendingAddr pc
}

pendingOnAccept pc connection
Expand Down Expand Up @@ -141,8 +137,6 @@ data Connection = Connection
-- the first close message but then the other party must respond. Finally,
-- the server is in charge of closing the TCP connection. This IORef tracks
-- if we have sent a close message and are waiting for the peer to respond.
, connectionAddr :: !S.SockAddr
-- ^ Peer socket address
}


Expand Down
8 changes: 3 additions & 5 deletions src/Network/WebSockets/Server.hs
Original file line number Diff line number Diff line change
Expand Up @@ -97,16 +97,15 @@ runApp socket opts app =
makePendingConnection
:: Socket -> ConnectionOptions -> IO PendingConnection
makePendingConnection socket opts = do
addr <- S.getPeerName socket
stream <- Stream.makeSocketStream socket
makePendingConnectionFromStream stream addr opts
makePendingConnectionFromStream stream opts


-- | More general version of 'makePendingConnection' for 'Stream.Stream'
-- instead of a 'Socket'.
makePendingConnectionFromStream
:: Stream.Stream -> S.SockAddr -> ConnectionOptions -> IO PendingConnection
makePendingConnectionFromStream stream addr opts = do
:: Stream.Stream -> ConnectionOptions -> IO PendingConnection
makePendingConnectionFromStream stream opts = do
-- TODO: we probably want to send a 40x if the request is bad?
mbRequest <- Stream.parse stream (decodeRequestHead False)
case mbRequest of
Expand All @@ -116,5 +115,4 @@ makePendingConnectionFromStream stream addr opts = do
, pendingRequest = request
, pendingOnAccept = \_ -> return ()
, pendingStream = stream
, pendingAddr = addr
}
4 changes: 1 addition & 3 deletions tests/haskell/Network/WebSockets/Handshake/Tests.hs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import Test.Framework (Test, testGroup)
import Test.Framework.Providers.HUnit (testCase)
import Test.HUnit (Assertion, assert, (@?=))

import qualified Network.Socket as S

--------------------------------------------------------------------------------
import Network.WebSockets
Expand All @@ -40,7 +39,7 @@ testHandshake :: RequestHead -> (PendingConnection -> IO a) -> IO ResponseHead
testHandshake rq app = do
echo <- Stream.makeEchoStream
_ <- forkIO $ do
_ <- app (PendingConnection defaultConnectionOptions rq nullify echo addr)
_ <- app (PendingConnection defaultConnectionOptions rq nullify echo)
return ()
mbRh <- Stream.parse echo decodeResponseHead
Stream.close echo
Expand All @@ -49,7 +48,6 @@ testHandshake rq app = do
Just rh -> return rh
where
nullify _ = return ()
addr = S.SockAddrUnix "No Address"


--------------------------------------------------------------------------------
Expand Down

2 comments on commit d1f7eeb

@dustin
Copy link

@dustin dustin commented on d1f7eeb Jun 1, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any reason this was reverted? I've written a server that uses websockets and it's surprising that I can't figure out who's connecting to me.

@jaspervdj
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dustin This is a while ago so I don't remember all the details. IIRC there was no easy way to obtain this that worked for both backends (WAI and Snap), and it was easier for users to just do this e.g. in the Snap monad and store/log it from there.

Please sign in to comment.