Permalink
Browse files

Make zmq_setsockopt typesafe

  • Loading branch information...
doublec committed Oct 25, 2011
1 parent 278190c commit f2293f54443641fbdeadeb259692b965b5d2103e
Showing with 5 additions and 8 deletions.
  1. +2 −1 SATS/libzmq.sats
  2. +1 −3 TEST/msreader.dats
  3. +2 −4 TEST/wuclient.dats
View
@@ -141,7 +141,8 @@ overload ~ with zmqsocket_isnot_null
fun zmq_socket {l:agz} (context: !zmqcontext l, type: zmqsockettype): [l2:addr] zmqsocket l2 = "mac#zmq_socket"
fun zmq_close {l:agz} (socket: zmqsocket l): int = "mac#zmq_close"
-fun zmq_setsockopt {l:agz} {l2:addr} (socket: !zmqsocket l, option_name: zmqsocketoption, option_value: ptr l2, option_len: size_t): int = "mac#zmq_setsockopt"
+fun zmq_setsockopt {a:t@ype} {l:agz} (socket: !zmqsocket l, option_name: zmqsocketoption, option_value: &a, option_len: sizeof_t a): int = "mac#zmq_setsockopt"
+fun zmq_setsockopt_string {l:agz} {n:nat} (socket: !zmqsocket l, option_name: zmqsocketoption, option_value: string n, option_len: size_t n): int = "mac#zmq_setsockopt"
fun zmq_getsockopt {l,l2:agz} {n:nat} (socket: !zmqsocket l, option_name: zmqsocketoption, option_value: ptr l2, option_len: size_t n): int = "mac#zmq_getsockopt"
fun zmq_bind {l:agz} (socket: !zmqsocket l, endpoint: string): int = "mac#zmq_bind"
fun zmq_connect {l:agz} (socket: !zmqsocket l, endpoint: string): int = "mac#zmq_connect"
View
@@ -5,8 +5,6 @@
staload "contrib/libzmq/SATS/libzmq.sats"
staload "libc/SATS/unistd.sats"
-extern castfn ptr_of_string (x: string):<> [l:agz] ptr l
-
implement main () = {
(* Prepare our context and sockets *)
val context = zmq_init (1)
@@ -27,7 +25,7 @@ implement main () = {
val () = assertloc (r = 0)
val filter = "10001 "
- val r = zmq_setsockopt (subscriber, ZMQ_SUBSCRIBE, ptr_of_string (filter), string_length (filter))
+ val r = zmq_setsockopt_string (subscriber, ZMQ_SUBSCRIBE, filter, string_length (filter))
val () = assertloc (r = 0)
(* Process messages from both sockets
View
@@ -5,8 +5,6 @@
*)
staload "contrib/libzmq/SATS/libzmq.sats"
-extern castfn ptr_of_string (x: string):<> [l:agz] ptr l
-
implement main (argc, argv) = {
val context = zmq_init (1)
val () = assertloc (~context)
@@ -18,8 +16,8 @@ implement main (argc, argv) = {
val _ = zmq_connect (subscriber, "tcp://localhost:5556")
(* Subscribe to zipcode, default is NYC, 10001 *)
- val filter = if argc > 1 then argv.[1] else "10001 "
- val r = zmq_setsockopt (subscriber, ZMQ_SUBSCRIBE, ptr_of_string (filter), string_length (filter))
+ val filter = string1_of_string (if argc > 1 then argv.[1] else "10001 ")
+ val r = zmq_setsockopt_string (subscriber, ZMQ_SUBSCRIBE, filter, string_length (filter))
(* Process 100 updates *)
val update_nbr = 100

0 comments on commit f2293f5

Please sign in to comment.