Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[feature] stdlib: Added primitive err_cont to Socket.connect.

  • Loading branch information...
commit 14a9b154d77e4f11b2426d78020f24b9cdcda222 1 parent 63ba0a4
@nrs135 nrs135 authored
Showing with 12 additions and 2 deletions.
  1. +10 −2 plugins/socket/bslSocket.ml
  2. +2 −0  stdlib/io/socket/socket.opa
View
12 plugins/socket/bslSocket.ml
@@ -27,16 +27,24 @@ open C.Ops
##extern-type Socket.connection = Scheduler.connection_info
let private_connect ?(secure_mode = Network.Unsecured) (addr: string) port
- (cont: Scheduler.connection_info -> unit) =
+ ?err_cont (cont: Scheduler.connection_info -> unit) =
let inet_addr = Network.inet_addr_of_name addr in
let port_spec = Network.make_port_spec ~socket_type:Network.TCP
~protocol:"raw" inet_addr port in
- Network.connect Scheduler.default port_spec secure_mode cont
+ Network.connect Scheduler.default port_spec secure_mode ?err_cont cont
##register [cps-bypass] connect: string, int,\
continuation(Socket.connection) -> void
let connect addr port cont = private_connect addr port (fun x -> x |> cont)
+(* Patch: for simplicity we turn the exception into a string. Note that it's
+ * not a real continuation, you should exit the program in the err_cont.
+ *)
+##register [cps-bypass] connect_with_err_cont: string, int,\
+ continuation(string), continuation(Socket.connection) -> void
+let connect_with_err_cont addr port err_cont cont =
+ private_connect addr port ~err_cont:(fun exn -> Printexc.to_string exn |> err_cont) (fun x -> x |> cont)
+
##register [cps-bypass] secure_connect: string, int, SSL.secure_type,\
continuation(Socket.connection) -> void
let secure_connect addr port secure_type cont =
View
2  stdlib/io/socket/socket.opa
@@ -40,6 +40,8 @@ Socket = {{
*/
connect: string, int -> Socket.connection = %%BslSocket.connect%%
+ connect_with_err_cont: string, int, continuation(string) -> Socket.connection = %%BslSocket.connect_with_err_cont%%
+
/**
* Connect to a server over an SSL encryption.
*
Please sign in to comment.
Something went wrong with that request. Please try again.