From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@sympa.inria.fr Delivered-To: caml-list@sympa.inria.fr Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by sympa.inria.fr (Postfix) with ESMTPS id 92F757EEF6 for ; Tue, 16 Jun 2015 17:48:04 +0200 (CEST) Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of kennethadammiller@gmail.com) identity=pra; client-ip=209.85.218.54; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="kennethadammiller@gmail.com"; x-sender="kennethadammiller@gmail.com"; x-conformance=sidf_compatible Received-SPF: Pass (mail3-smtp-sop.national.inria.fr: domain of kennethadammiller@gmail.com designates 209.85.218.54 as permitted sender) identity=mailfrom; client-ip=209.85.218.54; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="kennethadammiller@gmail.com"; x-sender="kennethadammiller@gmail.com"; x-conformance=sidf_compatible; x-record-type="v=spf1" Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of postmaster@mail-oi0-f54.google.com) identity=helo; client-ip=209.85.218.54; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="kennethadammiller@gmail.com"; x-sender="postmaster@mail-oi0-f54.google.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A0DXAQDdQ4BVmzbaVdFbgkWBfgaDGMJkAiiBEgdMAQEBAQEBEgEBAQEBBgsLCSEuhBoIAQEBAwESEQQZARsdAQMBCwYDAgsNIAEJAgIhAQERAQUBHBkIGoVRgiYBAwoImVGQaz4xiz+Ba4J5i3wKGScNV4RiAQEBAQEBAQMBAQEBAQEWAQUOizaCTYFuSweCaA+BNgEEk1+JZIFhgTOHEYg+gzuCERIjgQwJgi4fgW4iMYEDJIEgAQEF X-IPAS-Result: A0DXAQDdQ4BVmzbaVdFbgkWBfgaDGMJkAiiBEgdMAQEBAQEBEgEBAQEBBgsLCSEuhBoIAQEBAwESEQQZARsdAQMBCwYDAgsNIAEJAgIhAQERAQUBHBkIGoVRgiYBAwoImVGQaz4xiz+Ba4J5i3wKGScNV4RiAQEBAQEBAQMBAQEBAQEWAQUOizaCTYFuSweCaA+BNgEEk1+JZIFhgTOHEYg+gzuCERIjgQwJgi4fgW4iMYEDJIEgAQEF X-IronPort-AV: E=Sophos;i="5.13,627,1427752800"; d="scan'208";a="136513238" Received: from mail-oi0-f54.google.com ([209.85.218.54]) by mail3-smtp-sop.national.inria.fr with ESMTP/TLS/RC4-SHA; 16 Jun 2015 17:48:03 +0200 Received: by oigx81 with SMTP id x81so14382397oig.1 for ; Tue, 16 Jun 2015 08:48:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=wpdwzJ2jhmv7EQSY1Y7+uF2s3Ym1MhsPcfSW5NnhWqw=; b=lcsg+34jUh7tHYymZw2J1Dkdmh5gK6OZWnOlm0JB0i0vGwp8j40ZU9N8o2j5eXDWmw 0Mtg6Vb+rDJBbNlvybanyPaXG79zy6Mcaqu6s4zEVulopTtVGY+RFysSPHcggnGe5JDN ontdD9fjoj8NaToaVR4hf0klXkbxcFGnGfx8lOqZMVkio0wVnnFMO6Gr3wgpadfVTgxB fafiCOtI95oBssVyjPe+JoE8V7fehOrnWuBAGapBqCCT4WhFpAnW331C41e1sMCzvdx4 VXtOKwzJawgL7K5A8GC8gO/xeNxtFovaTIoOriNAlJlVIfWdSpL/Jsx/UOxoQtK+XopA ETwA== MIME-Version: 1.0 X-Received: by 10.60.40.228 with SMTP id a4mr246433oel.7.1434469682129; Tue, 16 Jun 2015 08:48:02 -0700 (PDT) Received: by 10.202.191.8 with HTTP; Tue, 16 Jun 2015 08:48:02 -0700 (PDT) In-Reply-To: References: Date: Tue, 16 Jun 2015 11:48:02 -0400 Message-ID: From: Kenneth Adam Miller Cc: caml users Content-Type: multipart/alternative; boundary=089e013a0910d852860518a47f07 Subject: Re: [Caml-list] Async Server not executing --089e013a0910d852860518a47f07 Content-Type: text/plain; charset=UTF-8 Ah. Well I think I can incorporate from that what I can, but my unit tests need to be reflective of the use case I have. I'm sending protobuf encoded messages between two processes on one machine-whatever the size of the message, that's the size that should be received on the other end (I've read about the returning partial bytes, I can't decode a part of a proto message, it has to be the right size). I can't use write_line, I'll have to find a way to delimit the messages based on size. I think I'll just prepend every message with the size that it should expect, and then read a integer off the stream and then that many bytes. On Tue, Jun 16, 2015 at 11:41 AM, David House wrote: > Ah, now I read your code in more detail I think I see why. > > Reader.contents on the server side will block until eof. The client side > sends some stuff, but does not close the writer, so the server never sees > eof. (Recall that sockets are not like files: it's possible to read all of > the available data right now, but not reach eof.) > > Network protocols normally have some explicit "this is the end of one > message" marker, like a newline or something similar. Then the server just > reads chunks until it sees that marker, at which point it can put the > message together and to something with it. > > For example, you could use Writer.write_line on the client side and > Reader.read_line on the server side. > > On 16 June 2015 at 16:36, Kenneth Adam Miller > wrote: > >> So, now I can get server received if I add that into the callback, but at >> "writing shutdown to server" I don't see response received or even >> something for Eof. >> >> On Tue, Jun 16, 2015 at 11:09 AM, David House >> wrote: >> >>> The first thing to try is to make sure that everything is getting >>> flushed. For temporary debugging messages I strongly recommend just using >>> [Core.Std.eprintf "\n%!"]. >>> >>> On 16 June 2015 at 16:03, Kenneth Adam Miller < >>> kennethadammiller@gmail.com> wrote: >>> >>>> I'm having trouble with OCaml Async. I wrote a small server with it, >>>> and right now I'm trying to unit test that server. Here's my code for the >>>> server: >>>> >>>> >>>> let _main ()= >>>> print_endline "Server running"; >>>> let handler = print_endline in >>>> let socket = Tcp.on_port 5554 in >>>> let server = Tcp.Server.create socket (fun addr r w -> >>>> (Reader.contents r) >>| handler; (Writer.write w "got it")) in >>>> server >>>> >>>> >>>> >>>> In my unit test code I have: >>>> >>>> let test_shutdown test_ctxt = Thread_safe.block_on_async_exn (fun () -> >>>> ( >>>> print_endline "test_shutdown"; >>>> let server = Server._main () in >>>> server >>= fun server -> >>>> let where = Tcp.to_host_and_port "127.0.0.1" 5554 in >>>> Tcp.connect where >>= fun s -> >>>> let socket, r, w = s in >>>> ignore (Writer.write w "kill"); >>>> ignore (Writer.flushed w); >>>> (Reader.recv r >>> function >>>> | `Ok result -> print_endline ("writing shutdown to server" >>>> ^ result) >>>> | `Eof -> ()); >>>> return () >>>> )); () >>>> >>>> >>>> >>>> I see test_shutdown and Server running, but not sign of "writing >>>> shutdown to server" or even "got it"; why isn't my server or even any of >>>> the connection executing? >>>> >>> >>> >> > --089e013a0910d852860518a47f07 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
Ah. Well I think I can incorporate from that what I can, b= ut my unit tests need to be reflective of the use case I have. I'm send= ing protobuf encoded messages between two processes on one machine-whatever= the size of the message, that's the size that should be received on th= e other end (I've read about the returning partial bytes, I can't d= ecode a part of a proto message, it has to be the right size).=C2=A0
I can't use write_line, I'll have to find a way to del= imit the messages based on size. I think I'll just prepend every messag= e with the size that it should expect, and then read a integer off the stre= am and then that many bytes.

On Tue, Jun 16, 2015 at 11:41 AM, David House <= dhouse@janestreet.com> wrote:
Ah, now I read your code in more detail I think I see w= hy.

Reader.contents on the server side will block until = eof. The client side sends some stuff, but does not close the writer, so th= e server never sees eof. (Recall that sockets are not like files: it's = possible to read all of the available data right now, but not reach eof.)

Network protocols normally have some explicit "= ;this is the end of one message" marker, like a newline or something s= imilar. Then the server just reads chunks until it sees that marker, at whi= ch point it can put the message together and to something with it.

For example, you could use Writer.write_line on the client= side and Reader.read_line on the server side.

On 16 June 2015 at 16:36, Kenneth Adam Miller <<= a href=3D"mailto:kennethadammiller@gmail.com" target=3D"_blank">kennethadam= miller@gmail.com> wrote:
So, now I can get server received if I add that into the cal= lback, but at "writing shutdown to server" I don't see respon= se received or even something for Eof.

On Tue, Jun 16, 2015 at 11:09 AM, Davi= d House <dhouse@janestreet.com> wrote:
The first thing to try is to make sure th= at everything is getting flushed. For temporary debugging messages I strong= ly recommend just using [Core.Std.eprintf "<message>\n%!"].=

O= n 16 June 2015 at 16:03, Kenneth Adam Miller <kennethadammiller= @gmail.com> wrote:
I'm having trouble with OCaml Async. I wrote a small server with it= , and right now I'm trying to unit test that server. Here's my code= for the server:
=

let _main=C2=A0()=3D
=C2=A0 print_endline=C2=A0
"Server ru= nning";
=C2=A0 le= t handler=C2=A0
=3D=C2=A0p= rint_endline=C2=A0in
=C2= =A0 let socket=C2=A0
=3D= =C2=A0Tcp.on_port=C2=A05554=C2=A0in
=C2=A0 let= server=C2=A0
=3D=C2=A0Tcp.Server.create so= cket=C2=A0(fun addr r w= =C2=A0->
=C2=A0 =C2= =A0 =C2=A0=C2=A0
(Read= er.contents r)
=C2=A0>= ;>|=C2=A0handler;
=C2=A0(Writer.write w=C2=A0<= /span>"got it"))=C2=A0in=
=C2=A0 server



In my unit test code I have:

let test_shutdown test_ctxt=C2=A0=3D=C2=A0Thread_safe= .block_on_async_exn=C2=A0= (fun=C2=A0()=C2=A0->= =C2=A0(
=C2=A0 =C2=A0 =C2=A0 print_endline=C2=A0
&= quot;test_shutdown";=
=C2=A0 =C2=A0 =C2=A0 let server=C2=A0
=3D=C2=A0Server._main=C2=A0()<= /span>=C2=A0in
=C2=A0 =C2=A0 =C2=A0 server=C2=A0
>&g= t;=3D=C2=A0fun server=C2=A0
=C2=A0 =C2=A0 =C2=A0 let=C2=A0
where
=C2=A0= =3D=C2=A0Tcp.to_host_and_port=C2=A0"127.0.0.1"=C2=A05554=C2=A0in
=C2=A0 =C2=A0 =C2=A0=C2=A0
.connect=C2=A0where=C2=A0>>=3D=C2=A0fun s=C2=A0->=C2=A0
=C2=A0 =C2=A0 =C2=A0 =C2=A0 = let socket
,=C2=A0r= ,=C2=A0w=C2=A0=3D=C2=A0s=C2=A0in=
=C2=A0 =C2=A0 =C2=A0 =C2=A0 ignore=C2=A0
<= span style=3D"margin:0px;padding:0px;border:0px;vertical-align:baseline;col= or:rgb(102,102,0)">(
Writer.write w=C2=A0"ki= ll");
=C2=A0 =C2= =A0 =C2=A0 =C2=A0 ignore=C2=A0
(Writer.flushed = w);
=C2=A0 =C2=A0 =C2= =A0 =C2=A0=C2=A0
(Read= er.recv r=C2=A0>>>
=C2=A0function
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0=C2=A0
|=C2=A0`Ok result -> =C2=A0print_endline ("writing shutdow= n to server" ^ result)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 | `Eof=C2=A0->=C2=A0());
=C2=A0 =C2=A0 =C2=A0 =C2=A0=C2=A0
return=C2=A0()
=C2=A0 =C2=A0=C2=A0
));
=C2=A0()
=


I see test_shutdown and Serve= r running, but not sign of "writing shutdown to server" or even &= quot;got it"; why isn't my server or even any of the connection ex= ecuting?




--089e013a0910d852860518a47f07--