Skip to content

Commit

Permalink
Change from close-X to mark-closed on Reader and Writer. (#2210)
Browse files Browse the repository at this point in the history
  • Loading branch information
floitsch authored Apr 10, 2024
1 parent a2f60f4 commit fa5f367
Show file tree
Hide file tree
Showing 57 changed files with 270 additions and 22 deletions.
3 changes: 3 additions & 0 deletions external/gold/pkg-http__examples__client_get.toit.gold
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<pkg:..>/server.toit:265:5: warning: Deprecated 'OutMixin.close-writer_'
close_writer_
^~~~~~~~~~~~~
3 changes: 3 additions & 0 deletions external/gold/pkg-http__examples__client_get_tls.toit.gold
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<pkg:..>/server.toit:265:5: warning: Deprecated 'OutMixin.close-writer_'
close_writer_
^~~~~~~~~~~~~
3 changes: 3 additions & 0 deletions external/gold/pkg-http__examples__client_post.toit.gold
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<pkg:..>/server.toit:265:5: warning: Deprecated 'OutMixin.close-writer_'
close_writer_
^~~~~~~~~~~~~
3 changes: 3 additions & 0 deletions external/gold/pkg-http__examples__local_ws_client.toit.gold
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<pkg:..>/server.toit:265:5: warning: Deprecated 'OutMixin.close-writer_'
close_writer_
^~~~~~~~~~~~~
3 changes: 3 additions & 0 deletions external/gold/pkg-http__examples__server.toit.gold
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<pkg:..>/server.toit:265:5: warning: Deprecated 'OutMixin.close-writer_'
close_writer_
^~~~~~~~~~~~~
3 changes: 3 additions & 0 deletions external/gold/pkg-http__examples__server_tls.toit.gold
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<pkg:..>/server.toit:265:5: warning: Deprecated 'OutMixin.close-writer_'
close_writer_
^~~~~~~~~~~~~
3 changes: 3 additions & 0 deletions external/gold/pkg-http__examples__ws_talk_to_self.toit.gold
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<pkg:..>/server.toit:265:5: warning: Deprecated 'OutMixin.close-writer_'
close_writer_
^~~~~~~~~~~~~
3 changes: 3 additions & 0 deletions external/gold/pkg-http__src__chunked.toit.gold
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pkg-http/src/server.toit:265:5: warning: Deprecated 'OutMixin.close-writer_'
close_writer_
^~~~~~~~~~~~~
3 changes: 3 additions & 0 deletions external/gold/pkg-http__src__client.toit.gold
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pkg-http/src/server.toit:265:5: warning: Deprecated 'OutMixin.close-writer_'
close_writer_
^~~~~~~~~~~~~
3 changes: 3 additions & 0 deletions external/gold/pkg-http__src__connection.toit.gold
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pkg-http/src/server.toit:265:5: warning: Deprecated 'OutMixin.close-writer_'
close_writer_
^~~~~~~~~~~~~
3 changes: 3 additions & 0 deletions external/gold/pkg-http__src__http.toit.gold
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pkg-http/src/server.toit:265:5: warning: Deprecated 'OutMixin.close-writer_'
close_writer_
^~~~~~~~~~~~~
3 changes: 3 additions & 0 deletions external/gold/pkg-http__src__request.toit.gold
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pkg-http/src/server.toit:265:5: warning: Deprecated 'OutMixin.close-writer_'
close_writer_
^~~~~~~~~~~~~
3 changes: 3 additions & 0 deletions external/gold/pkg-http__src__response.toit.gold
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pkg-http/src/server.toit:265:5: warning: Deprecated 'OutMixin.close-writer_'
close_writer_
^~~~~~~~~~~~~
3 changes: 3 additions & 0 deletions external/gold/pkg-http__src__server.toit.gold
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pkg-http/src/server.toit:265:5: warning: Deprecated 'OutMixin.close-writer_'
close_writer_
^~~~~~~~~~~~~
3 changes: 3 additions & 0 deletions external/gold/pkg-http__src__web_socket.toit.gold
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pkg-http/src/server.toit:265:5: warning: Deprecated 'OutMixin.close-writer_'
close_writer_
^~~~~~~~~~~~~
3 changes: 3 additions & 0 deletions external/gold/pkg-http__tests__google_404_test.toit.gold
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<pkg:..>/server.toit:265:5: warning: Deprecated 'OutMixin.close-writer_'
close_writer_
^~~~~~~~~~~~~
3 changes: 3 additions & 0 deletions external/gold/pkg-http__tests__google_test.toit.gold
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<pkg:..>/server.toit:265:5: warning: Deprecated 'OutMixin.close-writer_'
close_writer_
^~~~~~~~~~~~~
3 changes: 3 additions & 0 deletions external/gold/pkg-http__tests__headers_test.toit.gold
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<pkg:..>/server.toit:265:5: warning: Deprecated 'OutMixin.close-writer_'
close_writer_
^~~~~~~~~~~~~
3 changes: 3 additions & 0 deletions external/gold/pkg-http__tests__http_finalizer_test.toit.gold
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<pkg:..>/server.toit:265:5: warning: Deprecated 'OutMixin.close-writer_'
close_writer_
^~~~~~~~~~~~~
3 changes: 3 additions & 0 deletions external/gold/pkg-http__tests__http_overload_test.toit.gold
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<pkg:..>/server.toit:265:5: warning: Deprecated 'OutMixin.close-writer_'
close_writer_
^~~~~~~~~~~~~
3 changes: 3 additions & 0 deletions external/gold/pkg-http__tests__http_standalone_test.toit.gold
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<pkg:..>/server.toit:265:5: warning: Deprecated 'OutMixin.close-writer_'
close_writer_
^~~~~~~~~~~~~
3 changes: 3 additions & 0 deletions external/gold/pkg-http__tests__parse_url_test.toit.gold
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<pkg:..>/server.toit:265:5: warning: Deprecated 'OutMixin.close-writer_'
close_writer_
^~~~~~~~~~~~~
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<pkg:..>/server.toit:265:5: warning: Deprecated 'OutMixin.close-writer_'
close_writer_
^~~~~~~~~~~~~
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<pkg:..>/server.toit:265:5: warning: Deprecated 'OutMixin.close-writer_'
close_writer_
^~~~~~~~~~~~~
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<pkg:..>/server.toit:265:5: warning: Deprecated 'OutMixin.close-writer_'
close_writer_
^~~~~~~~~~~~~
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<pkg:..>/server.toit:265:5: warning: Deprecated 'OutMixin.close-writer_'
close_writer_
^~~~~~~~~~~~~
64 changes: 53 additions & 11 deletions lib/io/reader.toit
Original file line number Diff line number Diff line change
Expand Up @@ -723,11 +723,23 @@ abstract class Reader implements old-reader.Reader:
Sets the internal boolean to 'closed'.
Further reads return null.
Deprecated. Use $mark-closed_ instead.
*/
// This is a protected method. It should not be "private".
close-reader_:
is-closed_ = true

/**
Marks this reader as closed.
Sets the internal boolean to 'closed'.
Further reads return null.
*/
// This is a protected method. It should not be "private".
mark-closed_:
is-closed_ = true

abstract class CloseableReader extends Reader:
/**
Closes this reader.
Expand All @@ -741,8 +753,10 @@ abstract class CloseableReader extends Reader:
close --clear-buffered/bool=false -> none:
if clear-buffered: clear
if is-closed_: return
close_
close-reader_
try:
close_
finally:
mark-closed_

/** Whether this reader is closed. */
is-closed -> bool:
Expand All @@ -761,27 +775,42 @@ abstract class CloseableReader extends Reader:
abstract close_ -> none

abstract mixin InMixin:
in_/In_? := null
_in_/In_? := null

in -> Reader:
result := in_
result := _in_
if not result:
result = In_ this
in_ = result
return in_
_in_ = result
return _in_

/**
Closes the writer if it exists.
Closes the reader if it exists.
The $in $Reader doesn't have a 'close' method. However, we can set
the internal boolean to closed, so that further reads return null.
Any existing read needs to be aborted by the caller of this method. The $read_
method should return null.
Deprecated. Use $mark-reader-closed_ instead.
*/
// This is a protected method. It should not be "private".
close-reader_ -> none:
if in_: in_.close-reader_
if _in_: _in_.mark-closed_

/**
Marks the reader as closed.
The $in $Reader doesn't have a 'close' method. It only sets the
the internal boolean to closed, so that further reads return null.
Any existing read needs to be aborted by the caller of this method. The $read_
method should then return null.
*/
// This is a protected method. It should not be "private".
mark-reader-closed_ -> none:
if _in_: _in_.mark-closed_

/**
Reads the next bytes.
Expand All @@ -793,11 +822,24 @@ abstract mixin InMixin:
abstract read_ -> ByteArray?

abstract mixin CloseableInMixin:
in_/CloseableIn_? := null
_in_/CloseableIn_? := null

in -> CloseableReader:
if not in_: in_ = CloseableIn_ this
return in_
if not _in_: _in_ = CloseableIn_ this
return _in_

/**
Marks the reader as closed.
The $in $Reader doesn't have a 'close' method. It only sets the
the internal boolean to closed, so that further reads return null.
Any existing read needs to be aborted by the caller of this method. The $read_
method should then return null.
*/
// This is a protected method. It should not be "private".
mark-reader-closed_ -> none:
if _in_: _in_.mark-closed_

/**
Reads the next bytes.
Expand Down
62 changes: 53 additions & 9 deletions lib/io/writer.toit
Original file line number Diff line number Diff line change
Expand Up @@ -178,11 +178,23 @@ abstract class Writer:
Sets the internal boolean to 'closed'.
Further writes throw an exception.
Deprecated. Use $mark-closed_ instead.
*/
// This is a protected method. It should not be "private".
close-writer_:
is-closed_ = true

/**
Marks this writer as closed.
Sets the internal boolean to 'closed'.
Further writes throw an exception.
*/
// This is a protected method. It should not be "private".
mark-closed_:
is-closed_ = true

/**
Gives the resource the opportunity to make room for more data.
Expand All @@ -203,8 +215,10 @@ abstract class CloseableWriter extends Writer:
*/
close:
if is-closed_: return
close_
is-closed_ = true
try:
close_
finally:
mark-closed_

/** Whether this writer is closed. */
is-closed -> bool:
Expand All @@ -222,13 +236,13 @@ abstract class CloseableWriter extends Writer:
abstract close_ -> none

abstract mixin OutMixin:
out_/Out_? := null
_out_/Out_? := null

out -> Writer:
result := out_
result := _out_
if not result:
result = Out_ this
out_ = result
_out_ = result
return result

/**
Expand All @@ -241,10 +255,26 @@ abstract mixin OutMixin:
Any existing write needs to be aborted by the caller of this method.
The $try-write_ should either throw or return the number of bytes that have been
written so far. See $CloseableWriter.close_.
Deprecated. Use $mark-writer-closed_ instead.
*/
// This is a protected method. It should not be "private".
close-writer_ -> none:
if out_: out_.close-writer_
if _out_: _out_.mark-closed_

/**
Marks the writer as closed.
The $out $Writer doesn't have a 'close' method. It only sets the
the internal boolean to closed, so that further writes throw.
Any existing write needs to be aborted by the caller of this method.
The $try-write_ should either throw or return the number of bytes that have been
written so far. See $CloseableWriter.close_.
*/
// This is a protected method. It should not be "private".
mark-writer-closed_ -> none:
if _out_: _out_.mark-closed_

/**
Writes the given $data to this writer.
Expand All @@ -258,11 +288,25 @@ abstract mixin OutMixin:
abstract try-write_ data/Data from/int to/int -> int

abstract mixin CloseableOutMixin:
out_/CloseableOut_? := null
_out_/CloseableOut_? := null

out -> CloseableWriter:
if not out_: out_ = CloseableOut_ this
return out_
if not _out_: _out_ = CloseableOut_ this
return _out_

/**
Marks the writer as closed.
The $out $Writer doesn't have a 'close' method. It only sets the
the internal boolean to closed, so that further writes throw.
Any existing write needs to be aborted by the caller of this method.
The $try-write_ should either throw or return the number of bytes that have been
written so far. See $CloseableWriter.close_.
*/
// This is a protected method. It should not be "private".
mark-writer-closed_ -> none:
if _out_: _out_.mark-closed_

/**
Writes the given $data to this writer.
Expand Down
4 changes: 2 additions & 2 deletions lib/uart.toit
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,8 @@ class Port extends Object with io.InMixin implements reader.Reader:
*/
close:
if not uart_: return
close-reader_
if out_: out_.close-writer_
mark-reader-closed_
if out_: out_.mark-closed_
critical-do:
state_.dispose
uart-close_ resource-group_ uart_
Expand Down
3 changes: 3 additions & 0 deletions tests/health/gold/sdk/examples__http__http.toit.gold
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
<pkg:pkg-http>/server.toit:265:5: warning: Deprecated 'OutMixin.close-writer_'
close_writer_
^~~~~~~~~~~~~
<sdk>/bytes.toit:254:7: warning: Class 'BufferConsumer' is deprecated
class BufferSizeCounter extends BufferConsumer:
^~~~~~~~~~~~~~~~~
Expand Down
3 changes: 3 additions & 0 deletions tests/health/gold/sdk/tests__pkg__package-test.toit.gold
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
<pkg:toit-cert-roots>/certificate_roots.toit:10829:39: warning: Deprecated 'STAAT-DER-NEDERLANDEN-EV-ROOT-CA'
"Staat der Nederlanden EV Root CA": STAAT_DER_NEDERLANDEN_EV_ROOT_CA,
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<pkg:pkg-http>/server.toit:265:5: warning: Deprecated 'OutMixin.close-writer_'
close_writer_
^~~~~~~~~~~~~
<pkg:toit-cert-roots>/certificate_roots.toit:11093:3: warning: Deprecated 'CYBERTRUST-GLOBAL-ROOT'
CYBERTRUST_GLOBAL_ROOT.install
^~~~~~~~~~~~~~~~~~~~~~
Expand Down
3 changes: 3 additions & 0 deletions tests/health/gold/sdk/tests__pkg__registry-test.toit.gold
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
<pkg:toit-cert-roots>/certificate_roots.toit:10829:39: warning: Deprecated 'STAAT-DER-NEDERLANDEN-EV-ROOT-CA'
"Staat der Nederlanden EV Root CA": STAAT_DER_NEDERLANDEN_EV_ROOT_CA,
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<pkg:pkg-http>/server.toit:265:5: warning: Deprecated 'OutMixin.close-writer_'
close_writer_
^~~~~~~~~~~~~
<pkg:toit-cert-roots>/certificate_roots.toit:11093:3: warning: Deprecated 'CYBERTRUST-GLOBAL-ROOT'
CYBERTRUST_GLOBAL_ROOT.install
^~~~~~~~~~~~~~~~~~~~~~
Expand Down
3 changes: 3 additions & 0 deletions tests/health/gold/sdk/tools__pkg__commands__clean.toit.gold
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
<pkg:toit-cert-roots>/certificate_roots.toit:10829:39: warning: Deprecated 'STAAT-DER-NEDERLANDEN-EV-ROOT-CA'
"Staat der Nederlanden EV Root CA": STAAT_DER_NEDERLANDEN_EV_ROOT_CA,
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<pkg:pkg-http>/server.toit:265:5: warning: Deprecated 'OutMixin.close-writer_'
close_writer_
^~~~~~~~~~~~~
<pkg:toit-cert-roots>/certificate_roots.toit:11093:3: warning: Deprecated 'CYBERTRUST-GLOBAL-ROOT'
CYBERTRUST_GLOBAL_ROOT.install
^~~~~~~~~~~~~~~~~~~~~~
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
<pkg:toit-cert-roots>/certificate_roots.toit:10829:39: warning: Deprecated 'STAAT-DER-NEDERLANDEN-EV-ROOT-CA'
"Staat der Nederlanden EV Root CA": STAAT_DER_NEDERLANDEN_EV_ROOT_CA,
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<pkg:pkg-http>/server.toit:265:5: warning: Deprecated 'OutMixin.close-writer_'
close_writer_
^~~~~~~~~~~~~
<pkg:toit-cert-roots>/certificate_roots.toit:11093:3: warning: Deprecated 'CYBERTRUST-GLOBAL-ROOT'
CYBERTRUST_GLOBAL_ROOT.install
^~~~~~~~~~~~~~~~~~~~~~
Expand Down
3 changes: 3 additions & 0 deletions tests/health/gold/sdk/tools__pkg__commands__init.toit.gold
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
<pkg:toit-cert-roots>/certificate_roots.toit:10829:39: warning: Deprecated 'STAAT-DER-NEDERLANDEN-EV-ROOT-CA'
"Staat der Nederlanden EV Root CA": STAAT_DER_NEDERLANDEN_EV_ROOT_CA,
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<pkg:pkg-http>/server.toit:265:5: warning: Deprecated 'OutMixin.close-writer_'
close_writer_
^~~~~~~~~~~~~
<pkg:toit-cert-roots>/certificate_roots.toit:11093:3: warning: Deprecated 'CYBERTRUST-GLOBAL-ROOT'
CYBERTRUST_GLOBAL_ROOT.install
^~~~~~~~~~~~~~~~~~~~~~
Expand Down
Loading

0 comments on commit fa5f367

Please sign in to comment.