diff --git a/packages/net/_test.pony b/packages/net/_test.pony index 2f461c9a209..2b4be11da58 100644 --- a/packages/net/_test.pony +++ b/packages/net/_test.pony @@ -282,8 +282,12 @@ class _TestTCPExpectNotify is TCPConnectionNotify fun ref accepted(conn: TCPConnection ref) => conn.set_nodelay(true) - conn.expect(_expect) - _send(conn, "hi there") + try + conn.expect(_expect)? + _send(conn, "hi there") + else + conn.close() + end fun ref connect_failed(conn: TCPConnection ref) => _h.fail_action("client connect failed") @@ -291,7 +295,11 @@ class _TestTCPExpectNotify is TCPConnectionNotify fun ref connected(conn: TCPConnection ref) => _h.complete_action("client connect") conn.set_nodelay(true) - conn.expect(_expect) + try + conn.expect(_expect)? + else + conn.close() + end fun ref expect(conn: TCPConnection ref, qty: USize): USize => _h.complete_action("expect received") @@ -326,7 +334,11 @@ class _TestTCPExpectNotify is TCPConnectionNotify _expect = 4 end - conn.expect(_expect) + try + conn.expect(_expect)? + else + conn.close() + end true fun ref _send(conn: TCPConnection ref, data: String) => diff --git a/packages/net/tcp_connection.pony b/packages/net/tcp_connection.pony index 981c528dd23..f22db02ea3c 100644 --- a/packages/net/tcp_connection.pony +++ b/packages/net/tcp_connection.pony @@ -463,15 +463,22 @@ actor TCPConnection @pony_os_peername[Bool](_fd, ip) ip - fun ref expect(qty: USize = 0) => + fun ref expect(qty: USize = 0) ? => """ A `received` call on the notifier must contain exactly `qty` bytes. If `qty` is zero, the call can contain any amount of data. This has no effect if called in the `sent` notifier callback. + + `qty` can not exceed the max buffer size as indicated by the + read_buffer_size` supplied when the connection was created. """ - if not _in_sent then - _expect = _notify.expect(this, qty) - _read_buf_size() + if qty <= _read_buffer_size then + if not _in_sent then + _expect = _notify.expect(this, qty) + _read_buf_size() + end + else + error end fun ref set_nodelay(state: Bool) =>