Skip to content

Commit

Permalink
Make package compatible with new SDK. (#118)
Browse files Browse the repository at this point in the history
Does not change the API in any way.
  • Loading branch information
floitsch authored Apr 3, 2024
1 parent 97bdea9 commit ae287f7
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 54 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ jobs:
os: [ ubuntu-latest, windows-latest, macos-latest ]
# The versions should contain (at least) the lowest requirement
# and a version that is more up to date.
toit-version: [ v2.0.0-alpha.79, latest ]
toit-version: [ v2.0.0-alpha.144, latest ]
include:
- toit-version: v2.0.0-alpha.79
- toit-version: v2.0.0-alpha.144
version-name: old
- toit-version: latest
version-name: new
Expand Down
4 changes: 1 addition & 3 deletions package.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
# Toit Package.
name: http
description: An HTTP server and client.
environment:
# alpha 79 added session resume in TLS.
sdk: ^2.0.0-alpha.79
sdk: ^2.0.0-alpha.144
52 changes: 3 additions & 49 deletions src/connection.toit
Original file line number Diff line number Diff line change
Expand Up @@ -161,13 +161,14 @@ class Connection:
body_reader := current_reader_ or ContentLengthReader this reader_ 0
return RequestIncoming.private_ this body_reader method path version headers

detach -> DetachedSocket_:
detach -> tcp.Socket:
if not socket_: throw "ALREADY_CLOSED"
socket := socket_
socket_ = null
buffered := reader_.read_bytes reader_.buffered
socket.in.unget buffered
remove_finalizer this
return DetachedSocket_ socket buffered
return socket

read_response -> Response:
if current_reader_: throw "Previous response not completed"
Expand Down Expand Up @@ -324,53 +325,6 @@ class ContentLengthWriter implements BodyWriter:
connection_.writing_done_ this
connection_ = null

/**
A $tcp.Socket doesn't support ungetting data that was already read for it, so we
have this shim that will first return the data that was read before switching
protocols. Other functions are just passed through.
*/
class DetachedSocket_ implements tcp.Socket:
socket_/tcp.Socket
buffered_/ByteArray? := ?
constructor .socket_ .buffered_:

local_address -> net.SocketAddress:
return socket_.local_address
peer_address -> net.SocketAddress:
return socket_.peer_address
mtu -> int:
return socket_.mtu

no_delay -> bool:
return socket_.no_delay
no_delay= value/bool -> none:
socket_.no_delay = value

read -> ByteArray?:
if result := buffered_:
buffered_ = null
if result.size > 0:
return result
return socket_.read

write data from/int=0 to/int=data.size -> int:
return socket_.write data from to

close_write -> none:
socket_.close_write
close -> none:
socket_.close

// TODO(kasper): Remove this. Here for backwards compatibility.
set_no_delay enabled/bool:
no_delay = enabled

in:
throw "UNIMPLEMENTED"

out:
throw "UNIMPLEMENTED"

is_close_exception_ exception -> bool:
return exception == reader.UNEXPECTED_END_OF_READER_EXCEPTION
or exception == "Broken pipe"
Expand Down

0 comments on commit ae287f7

Please sign in to comment.