Skip to content

Instantly share code, notes, and snippets.

@joelreymont
Created May 16, 2011 11:56
Show Gist options
  • Save joelreymont/974321 to your computer and use it in GitHub Desktop.
Save joelreymont/974321 to your computer and use it in GitHub Desktop.
module Socket :
sig
type 'a t
type 'a kind
val pair : [>`Pair] kind
val pub : [>`Pub] kind
val sub : [>`Sub] kind
val req : [>`Req] kind
val rep : [>`Rep] kind
val dealer : [>`Dealer] kind
val router : [>`Router] kind
val pull : [>`Pull] kind
val push : [>`Push] kind
val create : 'a kind -> 'a t
val connect : 'a t -> string -> unit
val bind : 'a t -> string -> unit
val subscribe : [`Sub] t -> string -> unit
val unsubscribe : [`Sub] t -> string -> unit
end = struct
type 'a t = int
type 'a kind = int
let pair = 0
let pub = 1
let sub = 2
let req = 3
let rep = 4
let dealer = 5
let router = 6
let pull = 7
let push = 8
let create kind = 1
let connect sock endpoint = ()
let bind sock endpoint = ()
let subscribe socket new_subscription = ()
let unsubscribe socket old_subscription = ()
end
module Device :
sig
val streamer : [`Pull] Socket.t -> [`Push] Socket.t -> unit
val forwarder : [`Sub] Socket.t -> [`Pub] Socket.t -> unit
val queue : [`Router] Socket.t -> [`Dealer] Socket.t -> unit
end = struct
let streamer sock1 sock2 = ()
let forwarder sock1 sock2 = ()
let queue sock1 sock2 = ()
end
module Poll :
sig
type t
type event_mask = In | Out | In_out
type poll_socket = [`Pair|`Pub|`Sub|`Req|`Rep|`Dealer|`Router|`Pull|`Push] Socket.t
type poll_item = (poll_socket * event_mask)
val of_poll_items : poll_item array -> t
end = struct
type t = string
type event_mask = In | Out | In_out
type poll_socket = [`Pair|`Pub|`Sub|`Req|`Rep|`Dealer|`Router|`Pull|`Push] Socket.t
type poll_item = (poll_socket * event_mask)
let of_poll_items items = "create poll set"
end
open Socket
open Poll
let pub_endpoint = "tcp://127.0.0.1:9997"
let pull_endpoint = "tcp://127.0.0.1:9996"
let pub =
let sock = Socket.create pub in
connect sock pub_endpoint;
sock
let pull =
let sock = Socket.create pull in
connect sock pull_endpoint;
sock
let timeout = 1000000 (* 1s *)
let poll_set = of_poll_items [| pull, In; pub, Out |]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment