Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
gargantext-ihaskell
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
gargantext
gargantext-ihaskell
Commits
916e7ab7
Commit
916e7ab7
authored
Jul 24, 2015
by
Sumit Sahrawat
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix formatting
parent
f77a7c3e
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
77 additions
and
79 deletions
+77
-79
ZeroMQ.hs
ipython-kernel/src/IHaskell/IPython/ZeroMQ.hs
+77
-79
No files found.
ipython-kernel/src/IHaskell/IPython/ZeroMQ.hs
View file @
916e7ab7
...
@@ -5,13 +5,13 @@
...
@@ -5,13 +5,13 @@
-- The "ZeroMQ" module abstracts away the low-level 0MQ based interface with IPython, replacing it
-- The "ZeroMQ" module abstracts away the low-level 0MQ based interface with IPython, replacing it
-- instead with a Haskell Channel based interface. The `serveProfile` function takes a IPython
-- instead with a Haskell Channel based interface. The `serveProfile` function takes a IPython
-- profile specification and returns the channel interface to use.
-- profile specification and returns the channel interface to use.
module
IHaskell.IPython.ZeroMQ
module
IHaskell.IPython.ZeroMQ
(
(
ZeroMQInterface
(
..
)
ZeroMQInterface
(
..
),
,
ZeroMQStdin
(
..
)
ZeroMQStdin
(
..
),
,
serveProfile
serveProfile
,
,
serveStdin
serveStdin
,
,
ZeroMQEphemeralPorts
ZeroMQEphemeralPorts
,
,
withEphemeralPorts
withEphemeralPorts
,
)
where
)
where
import
Control.Concurrent
import
Control.Concurrent
...
@@ -68,7 +68,8 @@ newZeroMQInterface key = do
...
@@ -68,7 +68,8 @@ newZeroMQInterface key = do
controlReqChan
<-
dupChan
shellReqChan
controlReqChan
<-
dupChan
shellReqChan
controlRepChan
<-
dupChan
shellRepChan
controlRepChan
<-
dupChan
shellRepChan
iopubChan
<-
newChan
iopubChan
<-
newChan
return
$!
Channels
{
shellRequestChannel
=
shellReqChan
return
$!
Channels
{
shellRequestChannel
=
shellReqChan
,
shellReplyChannel
=
shellRepChan
,
shellReplyChannel
=
shellRepChan
,
controlRequestChannel
=
controlReqChan
,
controlRequestChannel
=
controlReqChan
,
controlReplyChannel
=
controlRepChan
,
controlReplyChannel
=
controlRepChan
...
@@ -100,10 +101,11 @@ serveProfile profile debug = do
...
@@ -100,10 +101,11 @@ serveProfile profile debug = do
return
channels
return
channels
-- | Describes ports used when creating an ephemeral ZeroMQ session.
-- | Describes ports used when creating an ephemeral ZeroMQ session. Used to generate the ipython
-- Used to generate the ipython JSON config file.
-- JSON config file.
data
ZeroMQEphemeralPorts
data
ZeroMQEphemeralPorts
=
=
ZeroMQEphemeralPorts
{
ephHbPort
::
!
Port
ZeroMQEphemeralPorts
{
ephHbPort
::
!
Port
,
ephControlPort
::
!
Port
,
ephControlPort
::
!
Port
,
ephShellPort
::
!
Port
,
ephShellPort
::
!
Port
,
ephIOPubPort
::
!
Port
,
ephIOPubPort
::
!
Port
...
@@ -112,7 +114,8 @@ data ZeroMQEphemeralPorts
...
@@ -112,7 +114,8 @@ data ZeroMQEphemeralPorts
instance
ToJSON
ZeroMQEphemeralPorts
where
instance
ToJSON
ZeroMQEphemeralPorts
where
toJSON
ports
=
toJSON
ports
=
object
[
"ip"
.=
(
"127.0.0.1"
::
String
)
object
[
"ip"
.=
(
"127.0.0.1"
::
String
)
,
"transport"
.=
TCP
,
"transport"
.=
TCP
,
"control_port"
.=
ephControlPort
ports
,
"control_port"
.=
ephControlPort
ports
,
"hb_port"
.=
ephHbPort
ports
,
"hb_port"
.=
ephHbPort
ports
...
@@ -123,7 +126,8 @@ instance ToJSON ZeroMQEphemeralPorts where
...
@@ -123,7 +126,8 @@ instance ToJSON ZeroMQEphemeralPorts where
parsePort
::
String
->
Maybe
Int
parsePort
::
String
->
Maybe
Int
parsePort
s
=
readMaybe
num
parsePort
s
=
readMaybe
num
where
num
=
reverse
(
takeWhile
isNumber
(
reverse
s
))
where
num
=
reverse
(
takeWhile
isNumber
(
reverse
s
))
bindLocalEphemeralPort
::
Socket
a
->
IO
Int
bindLocalEphemeralPort
::
Socket
a
->
IO
Int
bindLocalEphemeralPort
socket
=
do
bindLocalEphemeralPort
socket
=
do
...
@@ -135,15 +139,19 @@ bindLocalEphemeralPort socket = do
...
@@ -135,15 +139,19 @@ bindLocalEphemeralPort socket = do
Just
endpointIndex
->
Just
endpointIndex
->
return
endpointIndex
return
endpointIndex
-- | Run session for communicating with an IPython instance on ephemerally allocated
-- | Run session for communicating with an IPython instance on ephemerally allocated
ZMQ4 sockets.
--
ZMQ4 sockets.
The sockets will be closed when the callback returns.
-- The sockets will be closed when the callback returns.
withEphemeralPorts
::
ByteString
withEphemeralPorts
::
ByteString
->
-- ^ HMAC encryption key
-- ^ HMAC encryption key
->
Bool
Bool
->
-- ^ Print debug output
-- ^ Print debug output
->
(
ZeroMQEphemeralPorts
->
ZeroMQInterface
->
IO
a
)
(
ZeroMQEphemeralPorts
->
ZeroMQInterface
->
IO
a
)
-- ^ Callback that takes the interface to the sockets.
->
->
IO
a
-- ^ Callback that takes the
-- interface to the sockets.
IO
a
withEphemeralPorts
key
debug
callback
=
do
withEphemeralPorts
key
debug
callback
=
do
channels
<-
newZeroMQInterface
key
channels
<-
newZeroMQInterface
key
-- Create the ZMQ4 context
-- Create the ZMQ4 context
...
@@ -153,19 +161,13 @@ withEphemeralPorts key debug callback = do
...
@@ -153,19 +161,13 @@ withEphemeralPorts key debug callback = do
withSocket
context
Router
$
\
controlportSocket
->
do
withSocket
context
Router
$
\
controlportSocket
->
do
withSocket
context
Router
$
\
shellportSocket
->
do
withSocket
context
Router
$
\
shellportSocket
->
do
withSocket
context
Pub
$
\
iopubSocket
->
do
withSocket
context
Pub
$
\
iopubSocket
->
do
-- Bind each socket to a local port, getting the port chosen.
-- Bind each socket to a local port, getting the port chosen.
hbPort
<-
bindLocalEphemeralPort
heartbeatSocket
hbPort
<-
bindLocalEphemeralPort
heartbeatSocket
controlPort
<-
bindLocalEphemeralPort
controlportSocket
controlPort
<-
bindLocalEphemeralPort
controlportSocket
shellPort
<-
bindLocalEphemeralPort
shellportSocket
shellPort
<-
bindLocalEphemeralPort
shellportSocket
iopubPort
<-
bindLocalEphemeralPort
iopubSocket
iopubPort
<-
bindLocalEphemeralPort
iopubSocket
-- Create object to store ephemeral ports
-- Create object to store ephemeral ports
let
ports
=
ZeroMQEphemeralPorts
{
ephHbPort
=
hbPort
let
ports
=
ZeroMQEphemeralPorts
{
ephHbPort
=
hbPort
,
ephControlPort
=
controlPort
,
ephShellPort
=
shellPort
,
ephIOPubPort
=
iopubPort
,
ephSignatureKey
=
key
}
,
ephControlPort
=
controlPort
,
ephShellPort
=
shellPort
,
ephIOPubPort
=
iopubPort
,
ephSignatureKey
=
key
}
-- Launch actions to listen to communicate between channels and cockets.
-- Launch actions to listen to communicate between channels and cockets.
_
<-
forkIO
$
forever
$
heartbeat
channels
heartbeatSocket
_
<-
forkIO
$
forever
$
heartbeat
channels
heartbeatSocket
_
<-
forkIO
$
forever
$
control
debug
channels
controlportSocket
_
<-
forkIO
$
forever
$
control
debug
channels
controlportSocket
...
@@ -250,19 +252,15 @@ trySendMessage :: Sender a => String -> Bool -> ByteString -> Socket a -> Messag
...
@@ -250,19 +252,15 @@ trySendMessage :: Sender a => String -> Bool -> ByteString -> Socket a -> Messag
trySendMessage
nm
debug
hmacKey
socket
message
=
do
trySendMessage
nm
debug
hmacKey
socket
message
=
do
let
zmqErrorHandler
::
ZMQError
->
IO
Bool
let
zmqErrorHandler
::
ZMQError
->
IO
Bool
zmqErrorHandler
e
zmqErrorHandler
e
-- Ignore errors if we cannot send.
-- Ignore errors if we cannot send. We may want to forward this to the thread that tried put the
-- We may want to forward this to the thread that tried put the message
-- message in the Chan initially.
-- in the Chan initially.
|
errno
e
==
38
=
return
False
|
errno
e
==
38
=
return
False
|
otherwise
=
throwIO
e
|
otherwise
=
throwIO
e
(
sendMessage
debug
hmacKey
socket
message
>>
return
True
)
(
sendMessage
debug
hmacKey
socket
message
>>
return
True
)
`
catch
`
zmqErrorHandler
`
catch
`
zmqErrorHandler
-- | Send messages via the iopub channel.
-- | Send messages via the iopub channel. This reads messages from the ZeroMQ iopub interface
-- This reads messages from the ZeroMQ iopub interface
-- channel and then writes the messages to the socket. This is a checked implementation which will
-- channel and then writes the messages to the socket.
-- stop if the socket is closed.
-- This is a checked implementation which will stop if the socket is closed.
checkedIOpub
::
Bool
->
ZeroMQInterface
->
Socket
Pub
->
IO
()
checkedIOpub
::
Bool
->
ZeroMQInterface
->
Socket
Pub
->
IO
()
checkedIOpub
debug
channels
socket
=
do
checkedIOpub
debug
channels
socket
=
do
msg
<-
readChan
(
iopubChannel
channels
)
msg
<-
readChan
(
iopubChannel
channels
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment