Remove Conn.closeRead (#4970)

This commit is contained in:
Ryan Dahl 2020-04-28 15:17:55 -04:00 committed by GitHub
parent f899d76667
commit ea28a088a4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 5 additions and 80 deletions

View file

@ -1899,11 +1899,12 @@ declare namespace Deno {
readonly remoteAddr: Addr;
/** The resource ID of the connection. */
readonly rid: number;
/** Shuts down (`shutdown(2)`) the reading side of the TCP connection. Most
* callers should just use `close()`. */
closeRead(): void;
/** Shuts down (`shutdown(2)`) the writing side of the TCP connection. Most
* callers should just use `close()`. */
* callers should just use `close()`.
*
* **Unstable** because of lack of testing and because Deno.shutdown is also
* unstable.
* */
closeWrite(): void;
}

View file

@ -48,10 +48,6 @@ export class ConnImpl implements Conn {
close(this.rid);
}
closeRead(): void {
netOps.shutdown(this.rid, netOps.ShutdownMode.Read);
}
closeWrite(): void {
netOps.shutdown(this.rid, netOps.ShutdownMode.Write);
}
@ -130,7 +126,6 @@ export interface Conn extends Reader, Writer, Closer {
localAddr: Addr;
remoteAddr: Addr;
rid: number;
closeRead(): void;
closeWrite(): void;
}

View file

@ -368,75 +368,6 @@ unitTest(
}
);
unitTest(
{
// FIXME(bartlomieju)
ignore: true,
perms: { net: true },
},
async function netCloseReadSuccess() {
const addr = { hostname: "127.0.0.1", port: 4500 };
const listener = Deno.listen(addr);
const closeDeferred = createResolvable();
const closeReadDeferred = createResolvable();
listener.accept().then(async (conn) => {
await closeReadDeferred;
await conn.write(new Uint8Array([1, 2, 3]));
const buf = new Uint8Array(1024);
const readResult = await conn.read(buf);
assertEquals(3, readResult);
assertEquals(4, buf[0]);
assertEquals(5, buf[1]);
assertEquals(6, buf[2]);
conn.close();
closeDeferred.resolve();
});
const conn = await Deno.connect(addr);
conn.closeRead(); // closing read
closeReadDeferred.resolve();
const buf = new Uint8Array(1024);
const readResult = await conn.read(buf);
assertEquals(readResult, null); // with immediate EOF
// Ensure closeRead does not impact write
await conn.write(new Uint8Array([4, 5, 6]));
await closeDeferred;
listener.close();
conn.close();
}
);
unitTest(
{
// FIXME(bartlomieju)
ignore: true,
perms: { net: true },
},
async function netDoubleCloseRead() {
const addr = { hostname: "127.0.0.1", port: 4500 };
const listener = Deno.listen(addr);
const closeDeferred = createResolvable();
listener.accept().then(async (conn) => {
await conn.write(new Uint8Array([1, 2, 3]));
await closeDeferred;
conn.close();
});
const conn = await Deno.connect(addr);
conn.closeRead(); // closing read
let err;
try {
// Duplicated close should throw error
conn.closeRead();
} catch (e) {
err = e;
}
assert(!!err);
assert(err instanceof Deno.errors.NotConnected);
closeDeferred.resolve();
listener.close();
conn.close();
}
);
unitTest(
{
// FIXME(bartlomieju)

View file

@ -12,7 +12,6 @@ export function mockConn(base: Partial<Deno.Conn> = {}): Deno.Conn {
port: 0,
},
rid: -1,
closeRead: (): void => {},
closeWrite: (): void => {},
read: (): Promise<number | null> => {
return Promise.resolve(0);

View file

@ -276,7 +276,6 @@ test("[ws] ws.close() should use 1000 as close code", async () => {
function dummyConn(r: Reader, w: Writer): Conn {
return {
rid: -1,
closeRead: (): void => {},
closeWrite: (): void => {},
read: (x): Promise<number | null> => r.read(x),
write: (x): Promise<number> => w.write(x),