From b4de6c79262e5b8059fd6b81ab74f1d519353c2d Mon Sep 17 00:00:00 2001 From: "hyunghwan.chung" Date: Thu, 19 Apr 2018 15:34:25 +0000 Subject: [PATCH] a bit of experiments with semaphores for socket writing --- moo/kernel/Socket.moo | 33 ++++++++++++++++++++++----------- moo/lib/comp.c | 2 +- 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/moo/kernel/Socket.moo b/moo/kernel/Socket.moo index fd04b33..ff1a53a 100644 --- a/moo/kernel/Socket.moo +++ b/moo/kernel/Socket.moo @@ -331,7 +331,7 @@ class AsyncHandle(Object) }. } - method writeBytes: bytes offset: offset length: length semaphore: sem + method writeBytes: bytes offset: offset length: length signal: sem { | oldact n | ####################################### @@ -379,19 +379,19 @@ class AsyncHandle(Object) self watchOutput. } - method writeBytes: bytes semaphore: sem + method writeBytes: bytes signal: sem { - ^self writeBytes: bytes offset: 0 length: (bytes size) semaphore: sem. + ^self writeBytes: bytes offset: 0 length: (bytes size) signal: sem. } method writeBytes: bytes offset: offset length: length { - ^self writeBytes: bytes offset: offset length: length semaphore: nil. + ^self writeBytes: bytes offset: offset length: length signal: nil. } method writeBytes: bytes { - ^self writeBytes: bytes offset: 0 length: (bytes size) semaphore: nil. + ^self writeBytes: bytes offset: 0 length: (bytes size) signal: nil. } } @@ -607,20 +607,29 @@ error -> exception if (state) { 'CONNECTED NOW.............' dump. - ###sck inputTimeout: 10; outputTimeout: 10; connectTimeout: 10. + +############################################# write_more := [:sem | - sck writeBytes: %[ $h, $e, $l, $l, $o, $-, $m, $o, count + 65, $o, $o, C'\n' ] semaphore: x. - if (count > 26) { count := 0 } - else { count := count + 1 }. + if (count <= 26) + { + sck writeBytes: %[ $h, $e, $l, $l, $o, $-, $m, $o, count + 65, $o, $o, C'\n' ] signal: x. + count := count + 1. + } + else + { + System removeAsyncSemaphore: x. + }. ]. x := Semaphore new. x signalAction: write_more. System addAsyncSemaphore: x. + x signal. - sck outputAction: outact. - sck writeBytes: #[ $h, $e, $l, $l, $o, $-, $m, $o, $o, C'\n' ] semaphore: x. + ##sck outputAction: outact. + ##sck writeBytes: #[ $h, $e, $l, $l, $o, $-, $m, $o, $o, C'\n' ] signal: x. +############################################### sck inputAction: inact. sck watchInput. @@ -648,6 +657,8 @@ error -> exception newsck writeBytes: #[ $W, $e, $l, $c, $o, $m, $e, $., C'\n' ]. ]. + + [ | s s2 st sg ss | [ diff --git a/moo/lib/comp.c b/moo/lib/comp.c index 207adbd..b4d6e9f 100644 --- a/moo/lib/comp.c +++ b/moo/lib/comp.c @@ -8097,7 +8097,7 @@ static int compile_pragma_definition (moo_t* moo) #endif if (is_token_word(moo, VOCA_QC)) { - /* #pragma qc(on). #pragma qc(off) */ + /* #pragma qc(on). #pragma qc(off) - enable/disable double-quoted comments */ GET_TOKEN(moo); if (TOKEN_TYPE(moo) != MOO_IOTOK_LPAREN)