caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* Socket and Threads on windows
@ 2005-02-07  8:41 Julien Boulnois
  2005-02-07 10:33 ` [Caml-list] " Olivier Pérès
  0 siblings, 1 reply; 5+ messages in thread
From: Julien Boulnois @ 2005-02-07  8:41 UTC (permalink / raw)
  To: caml-list

Hi,

I try to use socket and threads for a receiving/sending client. My code works fine on linux but seems to block the whole program on windows ...

It looks like this:

***

let sock=Unix.socket Unix.PF_INET Unix.SOCK_STREAM 0;;

(* sock connection ... *)

let (ic,oc)=(Unix.in_channel_of_descr sock,Unix.out_channel_of_descr sock);;

let my_receive()=
  let d=input_value ic in
 (* data utilisation ... *)
;;
let my_send d=
  output_value oc d;;

let run()=
 while true do
  my_receive()
 done;;

let t=Thread.create (fun()->run()) ();;

(* ... *)

***

Now when I try to send data with my_send, the program just block and nothing more happen ...

I want to know if it exists some issue on windows for this case.

Thanks.

Julien Boulnois





^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Caml-list] Socket and Threads on windows
  2005-02-07  8:41 Socket and Threads on windows Julien Boulnois
@ 2005-02-07 10:33 ` Olivier Pérès
  2005-02-07 11:05   ` Julien Boulnois
  0 siblings, 1 reply; 5+ messages in thread
From: Olivier Pérès @ 2005-02-07 10:33 UTC (permalink / raw)
  To: Caml-list

Julien Boulnois a écrit :
> let (ic,oc)=(Unix.in_channel_of_descr sock,Unix.out_channel_of_descr sock);;

    According to the manual, none of *_channel_of_descr works on sockets 
on Windows 95/98/Me. What are you using ? As for me, to avoid that kind 
of problems, when writing Amble I made my own send/receive functions. 
Send is trivial (Marshal to string and Unix.write), receive is also 
pretty simple :

let receive_message fd =
     (* 1 - allocate and read the header *)
     let hs = Marshal.header_size in
     let headerbuf = String.create hs in
     let hlen = Unix.read fd headerbuf 0 hs in

     (* 2 - prepare the buffer as a string that has the same size as the 
message
      *     and copy the header in the beginning
      *)
     let ds = Marshal.data_size headerbuf 0 in
     let buf = String.create (hs+ds) in
     String.blit headerbuf 0 buf 0 hs;

     (* 3 - receive the rest of the message (data part) *)
     let dlen = Unix.read fd buf hs ds in

     (* 4 - decoding (unmarshalling) *)
     Marshal.from_string buf 0

    You can get the whole thing from http://home.gna.org/amble/ ; 
licence : GPL.

    Hope this helps,

    Olivier.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Re: [Caml-list] Socket and Threads on windows
  2005-02-07 10:33 ` [Caml-list] " Olivier Pérès
@ 2005-02-07 11:05   ` Julien Boulnois
  2005-02-10 16:23     ` OCAML Newby Question: unbound module? Juancarlo Añez
  0 siblings, 1 reply; 5+ messages in thread
From: Julien Boulnois @ 2005-02-07 11:05 UTC (permalink / raw)
  To: caml-list


>    According to the manual, none of *_channel_of_descr works on sockets 
>on Windows 95/98/Me. What are you using ? 
I have see this issue but I'm using windows xp. When I compile my program with pure cygwin, the code works fine but when i make cygwin-free compilation, its blocking.
I think the receive loop in thread block the send.

I will test your code anyway. 
Thanks 

Julien Boulnois


^ permalink raw reply	[flat|nested] 5+ messages in thread

* OCAML Newby Question: unbound module?
  2005-02-07 11:05   ` Julien Boulnois
@ 2005-02-10 16:23     ` Juancarlo Añez
  2005-02-11 14:45       ` [Caml-list] " John Prevost
  0 siblings, 1 reply; 5+ messages in thread
From: Juancarlo Añez @ 2005-02-10 16:23 UTC (permalink / raw)
  To: caml-list

I'm trying to write my first OCAML program. It will be a module that helps
handlings sets of path, like Apache Ant and WANT
(http://www.suigeneris.org/want) do.

Below is the first few lines of code I wrote. Whey I try to run it with
ocaml, I get:

"File "pattensets.ml", line 1, characters 0-11:
Unbound module Dumper"

Dumper.mil and dumper.ml are in the same directory.

What am I doing wrong?

--
Juanco
---

open Dumper;;

type fileName = string;;

type path = fileName list;;

let rec extract_file_name = function
    | ([], name)        -> ([], name)
    | ('/'::tail, name) -> (tail, name)
    | (c::tail, name)   -> extract_file_name (tail, name @ [c])
    ;;

let a = extract_file_name (['a';'b';'c'], [])
in
  prerr_endline (Dumper.dump a);;


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Caml-list] OCAML Newby Question: unbound module?
  2005-02-10 16:23     ` OCAML Newby Question: unbound module? Juancarlo Añez
@ 2005-02-11 14:45       ` John Prevost
  0 siblings, 0 replies; 5+ messages in thread
From: John Prevost @ 2005-02-11 14:45 UTC (permalink / raw)
  To: Juancarlo Añez; +Cc: caml-list

On Thu, 10 Feb 2005 12:23:57 -0400, Juancarlo Añez
<juanca@suigeneris.org> wrote:
> Below is the first few lines of code I wrote. Whey I try to run it with
> ocaml, I get:
> 
> "File "pattensets.ml", line 1, characters 0-11:
> Unbound module Dumper"
> 
> Dumper.mil and dumper.ml are in the same directory.
> 
> What am I doing wrong?

First, the filenames should be dumper.mli and dumper.ml  (I expect
these are correct, but just checking.)  Second, unlike with javac, you
must tell ocamlc which source files to compile and/or link, and in
what order.  In this case:

# produce the .cmi file from the .mli file
ocamlc -c dumper.mli
# produce the .cmo file from the .ml file
ocamlc -c dumper.ml
# produce the .cmo file from the .ml file
ocamlc -c program.ml
# produce the executable from the .cmo files
ocamlc -o program dumper.cmo program.cmo

Or in short:
ocamlc -o program dumper.mli dumper.ml program.ml

Note that ocamlopt is pretty much the same, but the extensions of .cmo
change to .cmx.  The reason that you need to specify the order in
which files are listed for linking is that this determines which
modules are in scope at any point, and also determines an order for
the initialization of each module.

Finally, if you are trying to run in the ocaml toplevel, you want to
do the steps above to produce the .cmo file for dumper, then:

#load "dumper.cmo";;

in the toplevel will cause the compiled code for dumper to be loaded
into memory.  (The compiled interface, dumper.cmi, will be found and
loaded automatically when you first refer to the Dumper module, but
until you load the .cmo file, the values from the module will not be
available.)

You might want to take a look at the ocaml beginner's list:
http://groups.yahoo.com/group/ocaml_beginners
or at chapter 8 of the manual (Batch Compilation (ocamlc)) if you have
more problems like this.

John.


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2005-02-11 14:45 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-02-07  8:41 Socket and Threads on windows Julien Boulnois
2005-02-07 10:33 ` [Caml-list] " Olivier Pérès
2005-02-07 11:05   ` Julien Boulnois
2005-02-10 16:23     ` OCAML Newby Question: unbound module? Juancarlo Añez
2005-02-11 14:45       ` [Caml-list] " John Prevost

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).