No, it does not call flush. Should I call it everytime a write is
performed? If so, will this have a negative impact on performance?
Even if it does, it seems calling flush may be unavoidable?

(defn connection-write [#^Socket conn #^bytes data]
  "writes data to the specified socket"
  (let [#^OutputStream ostream (. conn (getOutputStream))]
    (. ostream write data)))

BTW, I sincerely appreciate you taking the time to help me with this.
The Clojure community rocks!

Travis


On Jun 1, 10:26 am, Timothy Pratley <timothyprat...@gmail.com> wrote:
> Great! That largely indicates that we are reading the right amount of
> data. So I'm thinking (connection-write) doesn't call flush?
>
> On Jun 1, 11:30 pm, tmountain <tinymount...@gmail.com> wrote:
>
> > You're correct. Debugging with print statements shows that the
> > otherwise clause is never being reached. That being said, simply
> > inserting a Thread.sleep(0) before the data is returned makes the
> > program behave properly. If I remove that sleep, the client gives back
> > a malformed packet response. It seems like there's a race condition
> > with the buffer not being totally full before it's returned, but I
> > don't know how that could happen.
>
> > Thanks,
> > Travis
>
> > On Jun 1, 8:16 am, Timothy Pratley <timothyprat...@gmail.com> wrote:
>
> > > Hi Travis,
>
> > > Indeed. I re-read your code and think I have a clearer understanding
> > > of your intent now:
> > > You have an open TCP connection down which 'messages' are being sent
> > > which are prefaced by 'data length'. The 'messages' should be handled
> > > one at a time.
>
> > > So regardless of the maths
> > >           ; otherwise, read more data
> > > Isn't quite right because you are using a blocking read, bytes-read
> > > can only return 'data length' or an error has occured, in which case
> > > you cannot read more data. I was confused by this because it looked
> > > like a typical non-blocking 'work around'. In any case I don't expect
> > > that part of the code is ever being reached (it shouldn't happen
> > > unless the connection gets buggered).
>
> > > Unfortunately that puts us back to square one somewhat... maybe
> > > something in (connection-write) or the state transition? I think it
> > > might be printf time!
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to