Permalink
Browse files

[contrib] merge: pull request #22 from git://github.com/shadinger/pat…

…ch-1
  • Loading branch information...
2 parents 47e7e11 + 3c79d47 commit 8d33111f58aecc00735ac4c29e561ad36c9dc02f @BourgerieQuentin BourgerieQuentin committed Nov 21, 2011
Showing with 11,034 additions and 1,081 deletions.
  1. +5 −0 appruntime/connection.ml
  2. +40 −2 appruntime/scheduler.ml
  3. +11 −0 appruntime/scheduler.mli
  4. +40 −2 doc/book/hello_chat/hello_chat.adoc
  5. +111 −115 doc/book/hello_web_services/hello_web_services.adoc
  6. +39 −28 doc/book/hello_web_services/hello_wiki_rest.opa
  7. +69 −59 doc/book/hello_web_services/hello_wiki_rest_client.opa
  8. +78 −80 doc/book/hello_web_services/hello_wiki_rest_client_customizable.opa
  9. +55 −200 doc/book/hello_wiki/hello_wiki.adoc
  10. +20 −29 doc/book/hello_wiki/hello_wiki.opa
  11. +21 −30 doc/book/hello_wiki/hello_wiki_simple.opa
  12. +7 −0 libbase.mllib
  13. +3 −0 libbase/_tags
  14. +231 −0 libbase/baseStringSlice.ml
  15. +59 −0 libbase/baseStringSlice.mli
  16. +968 −0 libbase/bson.ml
  17. +236 −0 libbase/bson.mli
  18. +171 −0 libbase/buf.ml
  19. +63 −0 libbase/buf.mli
  20. +1 −0 libbase/debugVariables.ml
  21. +6 −0 libbase/debugVariables.mli
  22. +56 −0 libbase/endian.ml
  23. +199 −0 libbase/endianc.c
  24. +1 −0 libbase/libstubs.clib
  25. +509 −0 libbase/mongo.ml
  26. +80 −0 libbase/mongo.mli
  27. +235 −0 libbase/stuff.ml
  28. +81 −0 libbase/stuff.mli
  29. +56 −13 libnet/http/compression.ml
  30. +36 −28 libnet/httpServer.ml
  31. +78 −78 libnet/httpServerCommon.ml
  32. +117 −62 libnet/httpTools.ml
  33. +6 −1 libnet/httpTools.mli
  34. +28 −5 opa/pass_OpaDocApi.ml
  35. +39 −0 opabsl/jsbsl/bslClientOnly.js
  36. +13 −0 opabsl/jsbsl/bslDom.js
  37. +2 −0 opabsl/mlbsl/bsl-sources
  38. +10 −8 opabsl/mlbsl/bslDispatcher.ml
  39. +422 −0 opabsl/mlbsl/bslMongo.ml
  40. +29 −28 opabsl/mlbsl/bslNet.ml
  41. +4 −1 opabsl/mlbsl/bslSession.ml
  42. +72 −0 opabsl/mlbsl/mongolink.ml
  43. +8 −0 opacapi/opacapi.ml
  44. +6 −0 opadoc/common/opaDocTy.opa
  45. +1 −1 opadoc/generator/opaDocHtml.opa
  46. +9 −8 oparuntime/pingRegister.ml
  47. 0 { → packages/experimental}/OPAges/Makefile
  48. 0 { → packages/experimental}/OPAges/Makefile.common
  49. 0 { → packages/experimental}/OPAges/README
  50. 0 { → packages/experimental}/OPAges/opace/Makefile
  51. 0 { → packages/experimental}/OPAges/opace/Makefile.common
  52. 0 { → packages/experimental}/OPAges/opace/ace.opa
  53. 0 { → packages/experimental}/OPAges/opace/plugin/ace/LICENSE
  54. 0 { → packages/experimental}/OPAges/opace/plugin/ace/Makefile
  55. 0 { → packages/experimental}/OPAges/opace/plugin/ace/external_ACE.js
  56. 0 { → packages/experimental}/OPAges/opace/plugin/ace/myconf.jsconf
  57. 0 { → packages/experimental}/OPAges/opace/plugin/ace/plugin_ACE.js
  58. 0 { → packages/experimental}/OPAges/src/main.opa
  59. 0 { → packages/experimental}/OPAges/src/page.opa
  60. 0 { → packages/experimental}/OPAges/src/template_demo.opa
  61. 0 { → packages/experimental}/OPAges/src/users.opa
  62. 0 { → packages/experimental}/OPAges/static-include/admin/style.css
  63. +487 −0 packages/experimental/framework/application.opa
  64. +1 −0 plugins/_tags
  65. +36 −1 plugins/browser_canvas/bslCanvas.js
  66. +1 −1 plugins/socket/_tags
  67. +53 −0 plugins/socket/bslSocket.ml
  68. +7 −1 stdlib/apis/common/api_libs.opa
  69. +49 −0 stdlib/apis/mongo/MongoDb.opa
  70. +18 −0 stdlib/apis/mongo/README
  71. +955 −0 stdlib/apis/mongo/bson.opa
  72. +491 −0 stdlib/apis/mongo/collection.opa
  73. +732 −0 stdlib/apis/mongo/commands.opa
  74. +238 −0 stdlib/apis/mongo/connection.opa
  75. +385 −0 stdlib/apis/mongo/cursor.opa
  76. +725 −0 stdlib/apis/mongo/dbMongo.opa
  77. +83 −0 stdlib/apis/mongo/log.opa
  78. +867 −0 stdlib/apis/mongo/mongo.opa
  79. +254 −0 stdlib/apis/mongo/replset.opa
  80. +435 −0 stdlib/apis/mongo/selectupdate.opa
  81. +240 −0 stdlib/apis/mongo/types.opa
  82. +83 −0 stdlib/apis/mongo/utils.opa
  83. +192 −0 stdlib/apis/mongo/view.opa
  84. +18 −19 stdlib/core/list.opa
  85. +3 −2 stdlib/core/rpc/core/oparpc.opa
  86. +4 −4 stdlib/core/rpc/core/opaserialize.opa
  87. +1 −1 stdlib/core/rpc/core/session_private.opa
  88. +2 −1 stdlib/core/web/core/reply.opa
  89. +3 −3 stdlib/core/web/resource/dynamic_resource.opa
  90. +4 −3 stdlib/core/web/resource/resource_private.opa
  91. +1 −1 stdlib/core/web/server/server.opa
  92. +17 −2 stdlib/core/xhtml/dom.opa
  93. +1 −1 stdlib/core/xhtml/xhtml.opa
  94. +1 −1 stdlib/graph/dot.opa
  95. +37 −5 stdlib/io/socket/socket.opa
  96. +13 −12 stdlib/themes/bootstrap/core/core.opa
  97. BIN stdlib/themes/bootstrap/images/icons16-black.png
  98. BIN stdlib/themes/bootstrap/images/icons16-color.png
  99. BIN stdlib/themes/bootstrap/images/icons16-darkGray.png
  100. BIN stdlib/themes/bootstrap/images/icons16-gray.png
  101. BIN stdlib/themes/bootstrap/images/icons16-white.png
  102. BIN stdlib/themes/bootstrap/images/icons32-black.png
  103. BIN stdlib/themes/bootstrap/images/icons32-color.png
  104. BIN stdlib/themes/bootstrap/images/icons32-darkGray.png
  105. BIN stdlib/themes/bootstrap/images/icons32-gray.png
  106. BIN stdlib/themes/bootstrap/images/icons32-white.png
  107. +2 −2 stdlib/tools/markdown/markdown.opa
  108. +46 −1 stdlib/web/canvas/canvas.opa
  109. +10 −1 stdlib/web/client/client.opa
  110. +3 −36 stdlib/web/template/template.opa
  111. +193 −167 stdlib/web/template/template_base_engine.opa
  112. +8 −34 stdlib/web/template/template_type.opa
  113. +3 −3 stdlib/widgets/bootstrap/bootstrap.opa
  114. +1 −1 stdlib/widgets/tabs/tabs.opa
View
@@ -109,6 +109,11 @@ let read_more2 conn buf =
let () = Buffer.add_substring buf read_buff 0 nread in
nread, buf
+let read_more4 conn buf =
+ let nread, _ = read_aux conn read_buff read_buff_length in
+ let () = Buf.add_substring buf read_buff 0 nread in
+ nread, buf
+
let read_from conn =
let nread, addr = read_aux conn read_buff read_buff_length in
let get_peer = lazy (Unix.getpeername (NA.get_fd conn)) in
View
@@ -120,10 +120,10 @@ let get_err_cont sched conn err_cont =
| Timeout | _ -> ()
) err_cont
-let write sched conn ?(block_size=32768) ?timeout buf ?err_cont finalize =
+let write sched conn ?(block_size=32768) ?timeout buf ?(len=0) ?err_cont finalize =
#<If> L.info_conn "write" conn.addr #<End>;
let error = get_err_cont sched conn err_cont in
- let buflen = String.length buf in
+ let buflen = if len = 0 then String.length buf else len in
let decide (nwrite, pos) =
if nwrite = 0 then
Job.Error Connection_closed
@@ -311,6 +311,44 @@ let read_more2 sched conn ?read_max ?timeout buf ?(size_max=(-1)) ?err_cont fina
in
()
+let read_more4 sched conn ?read_max ?timeout buf ?(size_max=(-1)) ?err_cont finalize =
+ (* TODO: read_max and size_max (windows) unused *)
+ #<If> L.info_conn "read_more4" conn.addr #<End>;
+ let _ = read_max in
+ let _ = size_max in
+ let decide (nb_read, buf) =
+ if nb_read = -1 then Job.Execute buf
+ else if nb_read = 0 then Job.Error Connection_closed
+ else Job.Finalize (nb_read, buf)
+ in
+ let execute buf =
+ try
+ let nread, buf = C.read_more4 conn.addr buf in
+ NetStats.register_recv ~size:nread ~conn:conn.addr sched.stats;
+ nread, buf
+ with
+ | C.Busy ->
+ #<If> L.info_conn "read" ~s:"busy" conn.addr #<End>;
+ (-1, buf)
+ | e -> raise e
+ in
+ let error = get_err_cont sched conn err_cont in
+ let _ =
+ Job.make
+ sched.operation
+ sched.priority
+ sched.counter
+ (NA.get_fd conn.addr)
+ K.Operation.In
+ timeout
+ decide
+ execute
+ error
+ finalize
+ (-1, buf)
+ in
+ ()
+
let read sched conn ?timeout ?err_cont finalize =
#<If> L.info_conn "read" conn.addr #<End>;
let decide (nb_read, str) =
View
@@ -226,6 +226,16 @@ val read_more2 :
?err_cont:(exn -> unit) ->
(int * Buffer.t -> unit) -> unit
+val read_more4 :
+ t ->
+ connection_info ->
+ ?read_max:int ->
+ ?timeout:Time.t ->
+ Buf.t ->
+ ?size_max:int ->
+ ?err_cont:(exn -> unit) ->
+ (int * Buf.t -> unit) -> unit
+
val read :
t ->
connection_info ->
@@ -311,6 +321,7 @@ val write :
?block_size:int ->
?timeout:Time.t ->
string ->
+ ?len:int ->
?err_cont:(exn -> unit) ->
(int -> unit) -> unit
(** Writes over a [connection_info]
@@ -826,9 +826,47 @@ a comparison is a boolean. We write that the type of function
========================
In Opa, booleans are values +{true = void}+ and +{false = void}+, or, more
concisely but equivalently, +\{true\}+ and +\{false\}+.
-You can check whether boolean +b+ is true or false by using +if b then ... else ...+ or,
-equivalently, +match b with \{true\} -> ... | \{false\} -> ...+.
+
+Their type declaration looks as follow: +type bool = \{true\} / \{false\}+.
+Such types, admitting one of a number of variants, are called sum types.
+========================
+
+[TIP]
+.About sum types
========================
+A value has a _sum type_ +t / u+, meaning that the values of this type are either
+of the two variants: either a value of type +t+ or a value of type +u+.
+
+A good example of sum type are the aforementioned boolean values, which are defined
+as +type bool = \{false\}/\{true\}+.
+
+Another good example of sum type is the type +list+ of linked lists; its definition
+can be summed up as +\{nil\} / \{hd: ...; tl: list\}+.
+
+Note that sum types are not limited to two cases. Sum types with tens of cases
+are not uncommon in real applications.
+=======================
+
+Safely determining which variant was used to construct a value of a sum type
+can be accomplished with pattern matching.
+
+[TIP]
+.About pattern-matching
+========================
+The operation used to branch according to the case of a sum type
+is called _pattern-matching_. A good example of pattern-matching
+is +if ... then ... else ...+ . The more general syntax for pattern matching is
++match ... with | case_1 \-> ... | case_2 \-> ... | case_3 \-> ...+
+
+The operation is actually more powerful than just determining which case of a
+sum type is used. Indeed, if we use the vocabulary of languages such as Java or
+C#, pattern-matching combines features of +if+, +switch+, +instanceof+/+is+,
+multiple assignment and dereferenciation, but without the possible safety issues
+of +instanceof+/+is+ and with fewer chances of misuse than +switch+.
+
+As an example, you can check whether boolean +b+ is true or false by using
++if b then ... else ...+ or, equivalently, +match b with \{true\} -> ... | \{false\} -> ...+.
+=======================
Distinguishing messages between users
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Oops, something went wrong.

0 comments on commit 8d33111

Please sign in to comment.