help-smalltalk
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Help-smalltalk] Proxy learning exercise


From: Paolo Bonzini
Subject: Re: [Help-smalltalk] Proxy learning exercise
Date: Mon, 11 Aug 2008 08:47:43 +0200
User-agent: Thunderbird 2.0.0.16 (Macintosh/20080707)


1. It doesn't close the client (source) socket when the server (dest) socket closes.
 2. The loop is CPU intensive

You can use two processes.

p1 := [
    source ensureReadable.
    source isPeerAlive ifFalse: [ p1 terminate. p2 terminate ].
    dest nextPutAllFlush: source nextHunk ] newProcess.
p2 := [
    dest ensureReadable.
    dest isPeerAlive ifFalse: [ p1 terminate. p2 terminate ].
    source nextPutAllFlush: dest nextHunk ] newProcess.

p1 resume.
p2 resume


In 3.0c there is no #nextHunk, so you can use StreamSocket to remove the write buffering and do

p1 := [
    source ensureReadable.
    source isPeerAlive ifFalse: [ p1 terminate. p2 terminate ].
    source nextAvailablePutAllOn: dest ] newProcess.
p2 := [
    dest ensureReadable.
    dest isPeerAlive ifFalse: [ p1 terminate. p2 terminate ].
    dest nextAvailablePutAllOn: source ] newProcess.

p1 resume.
p2 resume


This has better performance because it does not do unnecessary copies and creation of objects.

Paolo




reply via email to

[Prev in Thread] Current Thread [Next in Thread]