Add createServer (#18)

This commit is contained in:
Kyle Carberry 2019-01-23 18:00:38 -06:00
parent ec909bdd0c
commit 6c178d615d
No known key found for this signature in database
GPG Key ID: A0409BDB6B0B3EDB
11 changed files with 1671 additions and 50 deletions

View File

@ -1,8 +1,8 @@
import { ReadWriteConnection, InitData, OperatingSystem, ISharedProcessData } from "../common/connection";
import { NewEvalMessage, ServerMessage, EvalDoneMessage, EvalFailedMessage, TypedValue, ClientMessage, NewSessionMessage, TTYDimensions, SessionOutputMessage, CloseSessionInputMessage, WorkingInitMessage, NewConnectionMessage } from "../proto";
import { NewEvalMessage, ServerMessage, EvalDoneMessage, EvalFailedMessage, TypedValue, ClientMessage, NewSessionMessage, TTYDimensions, SessionOutputMessage, CloseSessionInputMessage, WorkingInitMessage, NewConnectionMessage, NewServerMessage } from "../proto";
import { Emitter, Event } from "@coder/events";
import { logger, field } from "@coder/logger";
import { ChildProcess, SpawnOptions, ServerProcess, ServerSocket, Socket } from "./command";
import { ChildProcess, SpawnOptions, ServerProcess, ServerSocket, Socket, ServerListener, Server } from "./command";
/**
* Client accepts an arbitrary connection intended to communicate with the Server.
@ -18,6 +18,9 @@ export class Client {
private connectionId: number = 0;
private readonly connections: Map<number, ServerSocket> = new Map();
private serverId: number = 0;
private readonly servers: Map<number, ServerListener> = new Map();
private _initData: InitData | undefined;
private initDataEmitter = new Emitter<InitData>();
private initDataPromise: Promise<InitData>;
@ -189,6 +192,14 @@ export class Client {
return socket;
}
public createServer(callback?: () => void): Server {
const id = this.serverId++;
const server = new ServerListener(this.connection, id, callback);
this.servers.set(id, server);
return server;
}
private doSpawn(command: string, args: string[] = [], options?: SpawnOptions, isFork: boolean = false, isBootstrapFork: boolean = true): ChildProcess {
const id = this.sessionId++;
const newSess = new NewSessionMessage();
@ -333,6 +344,36 @@ export class Client {
this.sharedProcessActiveEmitter.emit({
socketPath: message.getSharedProcessActive()!.getSocketPath(),
});
} else if (message.hasServerEstablished()) {
const s = this.servers.get(message.getServerEstablished()!.getId());
if (!s) {
return;
}
s.emit("connect");
} else if (message.hasServerConnectionEstablished()) {
const s = this.servers.get(message.getServerConnectionEstablished()!.getServerId());
if (!s) {
return;
}
const conId = message.getServerConnectionEstablished()!.getConnectionId();
const serverSocket = new ServerSocket(this.connection, conId);
serverSocket.emit("connect");
this.connections.set(conId, serverSocket);
s.emit("connection", serverSocket);
} else if (message.getServerFailure()) {
const s = this.servers.get(message.getServerFailure()!.getId());
if (!s) {
return;
}
s.emit("error", new Error(message.getNewSessionFailure()!.getReason().toString()));
this.servers.delete(message.getNewSessionFailure()!.getId());
} else if (message.hasServerClose()) {
const s = this.servers.get(message.getServerClose()!.getId());
if (!s) {
return;
}
s.emit("close");
this.servers.delete(message.getServerClose()!.getId());
}
}
}

View File

@ -1,7 +1,7 @@
import * as events from "events";
import * as stream from "stream";
import { ReadWriteConnection } from "../common/connection";
import { ShutdownSessionMessage, ClientMessage, WriteToSessionMessage, ResizeSessionTTYMessage, TTYDimensions as ProtoTTYDimensions, ConnectionOutputMessage, ConnectionCloseMessage } from "../proto";
import { ShutdownSessionMessage, ClientMessage, WriteToSessionMessage, ResizeSessionTTYMessage, TTYDimensions as ProtoTTYDimensions, ConnectionOutputMessage, ConnectionCloseMessage, ServerCloseMessage, NewServerMessage } from "../proto";
export interface TTYDimensions {
readonly columns: number;
@ -237,3 +237,83 @@ export class ServerSocket extends events.EventEmitter implements Socket {
throw new Error("Method not implemented.");
}
}
export interface Server {
addListener(event: "close", listener: () => void): this;
addListener(event: "connect", listener: (socket: Socket) => void): this;
addListener(event: "error", listener: (err: Error) => void): this;
on(event: "close", listener: () => void): this;
on(event: "connection", listener: (socket: Socket) => void): this;
on(event: "error", listener: (err: Error) => void): this;
once(event: "close", listener: () => void): this;
once(event: "connection", listener: (socket: Socket) => void): this;
once(event: "error", listener: (err: Error) => void): this;
removeListener(event: "close", listener: () => void): this;
removeListener(event: "connection", listener: (socket: Socket) => void): this;
removeListener(event: "error", listener: (err: Error) => void): this;
emit(event: "close"): boolean;
emit(event: "connection"): boolean;
emit(event: "error"): boolean;
listen(path: string, listeningListener?: () => void): this;
close(callback?: () => void): this;
readonly listening: boolean;
}
export class ServerListener extends events.EventEmitter implements Server {
private _listening: boolean = false;
public constructor(
private readonly connection: ReadWriteConnection,
private readonly id: number,
connectCallback?: () => void,
) {
super();
this.on("connect", () => {
this._listening = true;
if (connectCallback) {
connectCallback();
}
});
}
public get listening(): boolean {
return this._listening;
}
public listen(path: string, listener?: () => void): this {
const ns = new NewServerMessage();
ns.setId(this.id);
ns.setPath(path!);
const cm = new ClientMessage();
cm.setNewServer(ns);
this.connection.send(cm.serializeBinary());
if (typeof listener !== "undefined") {
this.once("connect", listener);
}
return this;
}
public close(callback?: Function | undefined): this {
const closeMsg = new ServerCloseMessage();
closeMsg.setId(this.id);
closeMsg.setReason("Manually closed");
const clientMsg = new ClientMessage();
clientMsg.setServerClose(closeMsg);
this.connection.send(clientMsg.serializeBinary());
if (callback) {
callback();
}
return this;
}
}

View File

@ -3,7 +3,7 @@ import * as net from "net";
import * as nodePty from "node-pty";
import * as stream from "stream";
import { TextEncoder } from "text-encoding";
import { NewSessionMessage, ServerMessage, SessionDoneMessage, SessionOutputMessage, IdentifySessionMessage, NewConnectionMessage, ConnectionEstablishedMessage, NewConnectionFailureMessage, ConnectionCloseMessage, ConnectionOutputMessage } from "../proto";
import { NewSessionMessage, ServerMessage, SessionDoneMessage, SessionOutputMessage, IdentifySessionMessage, NewConnectionMessage, ConnectionEstablishedMessage, NewConnectionFailureMessage, ConnectionCloseMessage, ConnectionOutputMessage, NewServerMessage, ServerEstablishedMessage, NewServerFailureMessage, ServerCloseMessage, ServerConnectionEstablishedMessage } from "../proto";
import { SendableConnection } from "../common/connection";
import { ServerOptions } from "./server";
@ -180,3 +180,48 @@ export const handleNewConnection = (connection: SendableConnection, newConnectio
return socket;
};
export const handleNewServer = (connection: SendableConnection, newServer: NewServerMessage, addSocket: (socket: net.Socket) => number, onExit: () => void): net.Server => {
const s = net.createServer();
try {
s.listen(newServer.getPath() ? newServer.getPath() : newServer.getPort(), () => {
const se = new ServerEstablishedMessage();
se.setId(newServer.getId());
const sm = new ServerMessage();
sm.setServerEstablished(se);
connection.send(sm.serializeBinary());
});
} catch (ex) {
const sf = new NewServerFailureMessage();
sf.setId(newServer.getId());
const sm = new ServerMessage();
sm.setServerFailure(sf);
connection.send(sm.serializeBinary());
onExit();
}
s.on("close", () => {
const sc = new ServerCloseMessage();
sc.setId(newServer.getId());
const sm = new ServerMessage();
sm.setServerClose(sc);
connection.send(sm.serializeBinary());
onExit();
});
s.on("connection", (socket) => {
const socketId = addSocket(socket);
const sock = new ServerConnectionEstablishedMessage();
sock.setServerId(newServer.getId());
sock.setConnectionId(socketId);
const sm = new ServerMessage();
sm.setServerConnectionEstablished(sock);
connection.send(sm.serializeBinary());
});
return s;
};

View File

@ -8,7 +8,7 @@ import { logger, field } from "@coder/logger";
import { ClientMessage, WorkingInitMessage, ServerMessage, NewSessionMessage, WriteToSessionMessage } from "../proto";
import { evaluate } from "./evaluate";
import { ReadWriteConnection } from "../common/connection";
import { Process, handleNewSession, handleNewConnection } from "./command";
import { Process, handleNewSession, handleNewConnection, handleNewServer } from "./command";
import * as net from "net";
export interface ServerOptions {
@ -22,6 +22,9 @@ export class Server {
private readonly sessions: Map<number, Process> = new Map();
private readonly connections: Map<number, net.Socket> = new Map();
private readonly servers: Map<number, net.Server> = new Map();
private connectionId: number = Number.MAX_SAFE_INTEGER;
public constructor(
private readonly connection: ReadWriteConnection,
@ -147,9 +150,28 @@ export class Server {
return;
}
c.end();
} else if (message.hasNewServer()) {
const s = handleNewServer(this.connection, message.getNewServer()!, (socket) => {
const id = this.connectionId--;
this.connections.set(id, socket);
return id;
}, () => {
this.connections.delete(message.getNewServer()!.getId());
});
this.servers.set(message.getNewServer()!.getId(), s);
} else if (message.hasServerClose()) {
const s = this.getServer(message.getServerClose()!.getId());
if (!s) {
return;
}
s.close();
}
}
private getServer(id: number): net.Server | undefined {
return this.servers.get(id);
}
private getConnection(id: number): net.Socket | undefined {
return this.connections.get(id);
}

View File

@ -14,9 +14,11 @@ message ClientMessage {
NewConnectionMessage new_connection = 6;
ConnectionOutputMessage connection_output = 7;
ConnectionCloseMessage connection_close = 8;
NewServerMessage new_server = 9;
ServerCloseMessage server_close = 10;
// node.proto
NewEvalMessage new_eval = 9;
NewEvalMessage new_eval = 11;
}
}
@ -31,15 +33,19 @@ message ServerMessage {
ConnectionOutputMessage connection_output = 6;
ConnectionCloseMessage connection_close = 7;
ConnectionEstablishedMessage connection_established = 8;
NewServerFailureMessage server_failure = 9;
ServerEstablishedMessage server_established = 10;
ServerCloseMessage server_close = 11;
ServerConnectionEstablishedMessage server_connection_established = 12;
// node.proto
EvalFailedMessage eval_failed = 9;
EvalDoneMessage eval_done = 10;
EvalFailedMessage eval_failed = 13;
EvalDoneMessage eval_done = 14;
WorkingInitMessage init = 11;
WorkingInitMessage init = 15;
// vscode.proto
SharedProcessActiveMessage shared_process_active = 12;
SharedProcessActiveMessage shared_process_active = 16;
}
}

View File

@ -47,6 +47,16 @@ export class ClientMessage extends jspb.Message {
getConnectionClose(): command_pb.ConnectionCloseMessage | undefined;
setConnectionClose(value?: command_pb.ConnectionCloseMessage): void;
hasNewServer(): boolean;
clearNewServer(): void;
getNewServer(): command_pb.NewServerMessage | undefined;
setNewServer(value?: command_pb.NewServerMessage): void;
hasServerClose(): boolean;
clearServerClose(): void;
getServerClose(): command_pb.ServerCloseMessage | undefined;
setServerClose(value?: command_pb.ServerCloseMessage): void;
hasNewEval(): boolean;
clearNewEval(): void;
getNewEval(): node_pb.NewEvalMessage | undefined;
@ -73,6 +83,8 @@ export namespace ClientMessage {
newConnection?: command_pb.NewConnectionMessage.AsObject,
connectionOutput?: command_pb.ConnectionOutputMessage.AsObject,
connectionClose?: command_pb.ConnectionCloseMessage.AsObject,
newServer?: command_pb.NewServerMessage.AsObject,
serverClose?: command_pb.ServerCloseMessage.AsObject,
newEval?: node_pb.NewEvalMessage.AsObject,
}
@ -86,7 +98,9 @@ export namespace ClientMessage {
NEW_CONNECTION = 6,
CONNECTION_OUTPUT = 7,
CONNECTION_CLOSE = 8,
NEW_EVAL = 9,
NEW_SERVER = 9,
SERVER_CLOSE = 10,
NEW_EVAL = 11,
}
}
@ -131,6 +145,26 @@ export class ServerMessage extends jspb.Message {
getConnectionEstablished(): command_pb.ConnectionEstablishedMessage | undefined;
setConnectionEstablished(value?: command_pb.ConnectionEstablishedMessage): void;
hasServerFailure(): boolean;
clearServerFailure(): void;
getServerFailure(): command_pb.NewServerFailureMessage | undefined;
setServerFailure(value?: command_pb.NewServerFailureMessage): void;
hasServerEstablished(): boolean;
clearServerEstablished(): void;
getServerEstablished(): command_pb.ServerEstablishedMessage | undefined;
setServerEstablished(value?: command_pb.ServerEstablishedMessage): void;
hasServerClose(): boolean;
clearServerClose(): void;
getServerClose(): command_pb.ServerCloseMessage | undefined;
setServerClose(value?: command_pb.ServerCloseMessage): void;
hasServerConnectionEstablished(): boolean;
clearServerConnectionEstablished(): void;
getServerConnectionEstablished(): command_pb.ServerConnectionEstablishedMessage | undefined;
setServerConnectionEstablished(value?: command_pb.ServerConnectionEstablishedMessage): void;
hasEvalFailed(): boolean;
clearEvalFailed(): void;
getEvalFailed(): node_pb.EvalFailedMessage | undefined;
@ -172,6 +206,10 @@ export namespace ServerMessage {
connectionOutput?: command_pb.ConnectionOutputMessage.AsObject,
connectionClose?: command_pb.ConnectionCloseMessage.AsObject,
connectionEstablished?: command_pb.ConnectionEstablishedMessage.AsObject,
serverFailure?: command_pb.NewServerFailureMessage.AsObject,
serverEstablished?: command_pb.ServerEstablishedMessage.AsObject,
serverClose?: command_pb.ServerCloseMessage.AsObject,
serverConnectionEstablished?: command_pb.ServerConnectionEstablishedMessage.AsObject,
evalFailed?: node_pb.EvalFailedMessage.AsObject,
evalDone?: node_pb.EvalDoneMessage.AsObject,
init?: WorkingInitMessage.AsObject,
@ -188,10 +226,14 @@ export namespace ServerMessage {
CONNECTION_OUTPUT = 6,
CONNECTION_CLOSE = 7,
CONNECTION_ESTABLISHED = 8,
EVAL_FAILED = 9,
EVAL_DONE = 10,
INIT = 11,
SHARED_PROCESS_ACTIVE = 12,
SERVER_FAILURE = 9,
SERVER_ESTABLISHED = 10,
SERVER_CLOSE = 11,
SERVER_CONNECTION_ESTABLISHED = 12,
EVAL_FAILED = 13,
EVAL_DONE = 14,
INIT = 15,
SHARED_PROCESS_ACTIVE = 16,
}
}

View File

@ -42,7 +42,7 @@ if (goog.DEBUG && !COMPILED) {
* @private {!Array<!Array<number>>}
* @const
*/
proto.ClientMessage.oneofGroups_ = [[1,2,3,4,5,6,7,8,9]];
proto.ClientMessage.oneofGroups_ = [[1,2,3,4,5,6,7,8,9,10,11]];
/**
* @enum {number}
@ -57,7 +57,9 @@ proto.ClientMessage.MsgCase = {
NEW_CONNECTION: 6,
CONNECTION_OUTPUT: 7,
CONNECTION_CLOSE: 8,
NEW_EVAL: 9
NEW_SERVER: 9,
SERVER_CLOSE: 10,
NEW_EVAL: 11
};
/**
@ -103,6 +105,8 @@ proto.ClientMessage.toObject = function(includeInstance, msg) {
newConnection: (f = msg.getNewConnection()) && command_pb.NewConnectionMessage.toObject(includeInstance, f),
connectionOutput: (f = msg.getConnectionOutput()) && command_pb.ConnectionOutputMessage.toObject(includeInstance, f),
connectionClose: (f = msg.getConnectionClose()) && command_pb.ConnectionCloseMessage.toObject(includeInstance, f),
newServer: (f = msg.getNewServer()) && command_pb.NewServerMessage.toObject(includeInstance, f),
serverClose: (f = msg.getServerClose()) && command_pb.ServerCloseMessage.toObject(includeInstance, f),
newEval: (f = msg.getNewEval()) && node_pb.NewEvalMessage.toObject(includeInstance, f)
};
@ -181,6 +185,16 @@ proto.ClientMessage.deserializeBinaryFromReader = function(msg, reader) {
msg.setConnectionClose(value);
break;
case 9:
var value = new command_pb.NewServerMessage;
reader.readMessage(value,command_pb.NewServerMessage.deserializeBinaryFromReader);
msg.setNewServer(value);
break;
case 10:
var value = new command_pb.ServerCloseMessage;
reader.readMessage(value,command_pb.ServerCloseMessage.deserializeBinaryFromReader);
msg.setServerClose(value);
break;
case 11:
var value = new node_pb.NewEvalMessage;
reader.readMessage(value,node_pb.NewEvalMessage.deserializeBinaryFromReader);
msg.setNewEval(value);
@ -287,11 +301,27 @@ proto.ClientMessage.prototype.serializeBinaryToWriter = function (writer) {
command_pb.ConnectionCloseMessage.serializeBinaryToWriter
);
}
f = this.getNewEval();
f = this.getNewServer();
if (f != null) {
writer.writeMessage(
9,
f,
command_pb.NewServerMessage.serializeBinaryToWriter
);
}
f = this.getServerClose();
if (f != null) {
writer.writeMessage(
10,
f,
command_pb.ServerCloseMessage.serializeBinaryToWriter
);
}
f = this.getNewEval();
if (f != null) {
writer.writeMessage(
11,
f,
node_pb.NewEvalMessage.serializeBinaryToWriter
);
}
@ -548,18 +578,78 @@ proto.ClientMessage.prototype.hasConnectionClose = function() {
/**
* optional NewEvalMessage new_eval = 9;
* optional NewServerMessage new_server = 9;
* @return {proto.NewServerMessage}
*/
proto.ClientMessage.prototype.getNewServer = function() {
return /** @type{proto.NewServerMessage} */ (
jspb.Message.getWrapperField(this, command_pb.NewServerMessage, 9));
};
/** @param {proto.NewServerMessage|undefined} value */
proto.ClientMessage.prototype.setNewServer = function(value) {
jspb.Message.setOneofWrapperField(this, 9, proto.ClientMessage.oneofGroups_[0], value);
};
proto.ClientMessage.prototype.clearNewServer = function() {
this.setNewServer(undefined);
};
/**
* Returns whether this field is set.
* @return{!boolean}
*/
proto.ClientMessage.prototype.hasNewServer = function() {
return jspb.Message.getField(this, 9) != null;
};
/**
* optional ServerCloseMessage server_close = 10;
* @return {proto.ServerCloseMessage}
*/
proto.ClientMessage.prototype.getServerClose = function() {
return /** @type{proto.ServerCloseMessage} */ (
jspb.Message.getWrapperField(this, command_pb.ServerCloseMessage, 10));
};
/** @param {proto.ServerCloseMessage|undefined} value */
proto.ClientMessage.prototype.setServerClose = function(value) {
jspb.Message.setOneofWrapperField(this, 10, proto.ClientMessage.oneofGroups_[0], value);
};
proto.ClientMessage.prototype.clearServerClose = function() {
this.setServerClose(undefined);
};
/**
* Returns whether this field is set.
* @return{!boolean}
*/
proto.ClientMessage.prototype.hasServerClose = function() {
return jspb.Message.getField(this, 10) != null;
};
/**
* optional NewEvalMessage new_eval = 11;
* @return {proto.NewEvalMessage}
*/
proto.ClientMessage.prototype.getNewEval = function() {
return /** @type{proto.NewEvalMessage} */ (
jspb.Message.getWrapperField(this, node_pb.NewEvalMessage, 9));
jspb.Message.getWrapperField(this, node_pb.NewEvalMessage, 11));
};
/** @param {proto.NewEvalMessage|undefined} value */
proto.ClientMessage.prototype.setNewEval = function(value) {
jspb.Message.setOneofWrapperField(this, 9, proto.ClientMessage.oneofGroups_[0], value);
jspb.Message.setOneofWrapperField(this, 11, proto.ClientMessage.oneofGroups_[0], value);
};
@ -573,7 +663,7 @@ proto.ClientMessage.prototype.clearNewEval = function() {
* @return{!boolean}
*/
proto.ClientMessage.prototype.hasNewEval = function() {
return jspb.Message.getField(this, 9) != null;
return jspb.Message.getField(this, 11) != null;
};
@ -603,7 +693,7 @@ if (goog.DEBUG && !COMPILED) {
* @private {!Array<!Array<number>>}
* @const
*/
proto.ServerMessage.oneofGroups_ = [[1,2,3,4,5,6,7,8,9,10,11,12]];
proto.ServerMessage.oneofGroups_ = [[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16]];
/**
* @enum {number}
@ -618,10 +708,14 @@ proto.ServerMessage.MsgCase = {
CONNECTION_OUTPUT: 6,
CONNECTION_CLOSE: 7,
CONNECTION_ESTABLISHED: 8,
EVAL_FAILED: 9,
EVAL_DONE: 10,
INIT: 11,
SHARED_PROCESS_ACTIVE: 12
SERVER_FAILURE: 9,
SERVER_ESTABLISHED: 10,
SERVER_CLOSE: 11,
SERVER_CONNECTION_ESTABLISHED: 12,
EVAL_FAILED: 13,
EVAL_DONE: 14,
INIT: 15,
SHARED_PROCESS_ACTIVE: 16
};
/**
@ -667,6 +761,10 @@ proto.ServerMessage.toObject = function(includeInstance, msg) {
connectionOutput: (f = msg.getConnectionOutput()) && command_pb.ConnectionOutputMessage.toObject(includeInstance, f),
connectionClose: (f = msg.getConnectionClose()) && command_pb.ConnectionCloseMessage.toObject(includeInstance, f),
connectionEstablished: (f = msg.getConnectionEstablished()) && command_pb.ConnectionEstablishedMessage.toObject(includeInstance, f),
serverFailure: (f = msg.getServerFailure()) && command_pb.NewServerFailureMessage.toObject(includeInstance, f),
serverEstablished: (f = msg.getServerEstablished()) && command_pb.ServerEstablishedMessage.toObject(includeInstance, f),
serverClose: (f = msg.getServerClose()) && command_pb.ServerCloseMessage.toObject(includeInstance, f),
serverConnectionEstablished: (f = msg.getServerConnectionEstablished()) && command_pb.ServerConnectionEstablishedMessage.toObject(includeInstance, f),
evalFailed: (f = msg.getEvalFailed()) && node_pb.EvalFailedMessage.toObject(includeInstance, f),
evalDone: (f = msg.getEvalDone()) && node_pb.EvalDoneMessage.toObject(includeInstance, f),
init: (f = msg.getInit()) && proto.WorkingInitMessage.toObject(includeInstance, f),
@ -748,21 +846,41 @@ proto.ServerMessage.deserializeBinaryFromReader = function(msg, reader) {
msg.setConnectionEstablished(value);
break;
case 9:
var value = new command_pb.NewServerFailureMessage;
reader.readMessage(value,command_pb.NewServerFailureMessage.deserializeBinaryFromReader);
msg.setServerFailure(value);
break;
case 10:
var value = new command_pb.ServerEstablishedMessage;
reader.readMessage(value,command_pb.ServerEstablishedMessage.deserializeBinaryFromReader);
msg.setServerEstablished(value);
break;
case 11:
var value = new command_pb.ServerCloseMessage;
reader.readMessage(value,command_pb.ServerCloseMessage.deserializeBinaryFromReader);
msg.setServerClose(value);
break;
case 12:
var value = new command_pb.ServerConnectionEstablishedMessage;
reader.readMessage(value,command_pb.ServerConnectionEstablishedMessage.deserializeBinaryFromReader);
msg.setServerConnectionEstablished(value);
break;
case 13:
var value = new node_pb.EvalFailedMessage;
reader.readMessage(value,node_pb.EvalFailedMessage.deserializeBinaryFromReader);
msg.setEvalFailed(value);
break;
case 10:
case 14:
var value = new node_pb.EvalDoneMessage;
reader.readMessage(value,node_pb.EvalDoneMessage.deserializeBinaryFromReader);
msg.setEvalDone(value);
break;
case 11:
case 15:
var value = new proto.WorkingInitMessage;
reader.readMessage(value,proto.WorkingInitMessage.deserializeBinaryFromReader);
msg.setInit(value);
break;
case 12:
case 16:
var value = new vscode_pb.SharedProcessActiveMessage;
reader.readMessage(value,vscode_pb.SharedProcessActiveMessage.deserializeBinaryFromReader);
msg.setSharedProcessActive(value);
@ -869,18 +987,50 @@ proto.ServerMessage.prototype.serializeBinaryToWriter = function (writer) {
command_pb.ConnectionEstablishedMessage.serializeBinaryToWriter
);
}
f = this.getEvalFailed();
f = this.getServerFailure();
if (f != null) {
writer.writeMessage(
9,
f,
command_pb.NewServerFailureMessage.serializeBinaryToWriter
);
}
f = this.getServerEstablished();
if (f != null) {
writer.writeMessage(
10,
f,
command_pb.ServerEstablishedMessage.serializeBinaryToWriter
);
}
f = this.getServerClose();
if (f != null) {
writer.writeMessage(
11,
f,
command_pb.ServerCloseMessage.serializeBinaryToWriter
);
}
f = this.getServerConnectionEstablished();
if (f != null) {
writer.writeMessage(
12,
f,
command_pb.ServerConnectionEstablishedMessage.serializeBinaryToWriter
);
}
f = this.getEvalFailed();
if (f != null) {
writer.writeMessage(
13,
f,
node_pb.EvalFailedMessage.serializeBinaryToWriter
);
}
f = this.getEvalDone();
if (f != null) {
writer.writeMessage(
10,
14,
f,
node_pb.EvalDoneMessage.serializeBinaryToWriter
);
@ -888,7 +1038,7 @@ proto.ServerMessage.prototype.serializeBinaryToWriter = function (writer) {
f = this.getInit();
if (f != null) {
writer.writeMessage(
11,
15,
f,
proto.WorkingInitMessage.serializeBinaryToWriter
);
@ -896,7 +1046,7 @@ proto.ServerMessage.prototype.serializeBinaryToWriter = function (writer) {
f = this.getSharedProcessActive();
if (f != null) {
writer.writeMessage(
12,
16,
f,
vscode_pb.SharedProcessActiveMessage.serializeBinaryToWriter
);
@ -1154,18 +1304,138 @@ proto.ServerMessage.prototype.hasConnectionEstablished = function() {
/**
* optional EvalFailedMessage eval_failed = 9;
* optional NewServerFailureMessage server_failure = 9;
* @return {proto.NewServerFailureMessage}
*/
proto.ServerMessage.prototype.getServerFailure = function() {
return /** @type{proto.NewServerFailureMessage} */ (
jspb.Message.getWrapperField(this, command_pb.NewServerFailureMessage, 9));
};
/** @param {proto.NewServerFailureMessage|undefined} value */
proto.ServerMessage.prototype.setServerFailure = function(value) {
jspb.Message.setOneofWrapperField(this, 9, proto.ServerMessage.oneofGroups_[0], value);
};
proto.ServerMessage.prototype.clearServerFailure = function() {
this.setServerFailure(undefined);
};
/**
* Returns whether this field is set.
* @return{!boolean}
*/
proto.ServerMessage.prototype.hasServerFailure = function() {
return jspb.Message.getField(this, 9) != null;
};
/**
* optional ServerEstablishedMessage server_established = 10;
* @return {proto.ServerEstablishedMessage}
*/
proto.ServerMessage.prototype.getServerEstablished = function() {
return /** @type{proto.ServerEstablishedMessage} */ (
jspb.Message.getWrapperField(this, command_pb.ServerEstablishedMessage, 10));
};
/** @param {proto.ServerEstablishedMessage|undefined} value */
proto.ServerMessage.prototype.setServerEstablished = function(value) {
jspb.Message.setOneofWrapperField(this, 10, proto.ServerMessage.oneofGroups_[0], value);
};
proto.ServerMessage.prototype.clearServerEstablished = function() {
this.setServerEstablished(undefined);
};
/**
* Returns whether this field is set.
* @return{!boolean}
*/
proto.ServerMessage.prototype.hasServerEstablished = function() {
return jspb.Message.getField(this, 10) != null;
};
/**
* optional ServerCloseMessage server_close = 11;
* @return {proto.ServerCloseMessage}
*/
proto.ServerMessage.prototype.getServerClose = function() {
return /** @type{proto.ServerCloseMessage} */ (
jspb.Message.getWrapperField(this, command_pb.ServerCloseMessage, 11));
};
/** @param {proto.ServerCloseMessage|undefined} value */
proto.ServerMessage.prototype.setServerClose = function(value) {
jspb.Message.setOneofWrapperField(this, 11, proto.ServerMessage.oneofGroups_[0], value);
};
proto.ServerMessage.prototype.clearServerClose = function() {
this.setServerClose(undefined);
};
/**
* Returns whether this field is set.
* @return{!boolean}
*/
proto.ServerMessage.prototype.hasServerClose = function() {
return jspb.Message.getField(this, 11) != null;
};
/**
* optional ServerConnectionEstablishedMessage server_connection_established = 12;
* @return {proto.ServerConnectionEstablishedMessage}
*/
proto.ServerMessage.prototype.getServerConnectionEstablished = function() {
return /** @type{proto.ServerConnectionEstablishedMessage} */ (
jspb.Message.getWrapperField(this, command_pb.ServerConnectionEstablishedMessage, 12));
};
/** @param {proto.ServerConnectionEstablishedMessage|undefined} value */
proto.ServerMessage.prototype.setServerConnectionEstablished = function(value) {
jspb.Message.setOneofWrapperField(this, 12, proto.ServerMessage.oneofGroups_[0], value);
};
proto.ServerMessage.prototype.clearServerConnectionEstablished = function() {
this.setServerConnectionEstablished(undefined);
};
/**
* Returns whether this field is set.
* @return{!boolean}
*/
proto.ServerMessage.prototype.hasServerConnectionEstablished = function() {
return jspb.Message.getField(this, 12) != null;
};
/**
* optional EvalFailedMessage eval_failed = 13;
* @return {proto.EvalFailedMessage}
*/
proto.ServerMessage.prototype.getEvalFailed = function() {
return /** @type{proto.EvalFailedMessage} */ (
jspb.Message.getWrapperField(this, node_pb.EvalFailedMessage, 9));
jspb.Message.getWrapperField(this, node_pb.EvalFailedMessage, 13));
};
/** @param {proto.EvalFailedMessage|undefined} value */
proto.ServerMessage.prototype.setEvalFailed = function(value) {
jspb.Message.setOneofWrapperField(this, 9, proto.ServerMessage.oneofGroups_[0], value);
jspb.Message.setOneofWrapperField(this, 13, proto.ServerMessage.oneofGroups_[0], value);
};
@ -1179,23 +1449,23 @@ proto.ServerMessage.prototype.clearEvalFailed = function() {
* @return{!boolean}
*/
proto.ServerMessage.prototype.hasEvalFailed = function() {
return jspb.Message.getField(this, 9) != null;
return jspb.Message.getField(this, 13) != null;
};
/**
* optional EvalDoneMessage eval_done = 10;
* optional EvalDoneMessage eval_done = 14;
* @return {proto.EvalDoneMessage}
*/
proto.ServerMessage.prototype.getEvalDone = function() {
return /** @type{proto.EvalDoneMessage} */ (
jspb.Message.getWrapperField(this, node_pb.EvalDoneMessage, 10));
jspb.Message.getWrapperField(this, node_pb.EvalDoneMessage, 14));
};
/** @param {proto.EvalDoneMessage|undefined} value */
proto.ServerMessage.prototype.setEvalDone = function(value) {
jspb.Message.setOneofWrapperField(this, 10, proto.ServerMessage.oneofGroups_[0], value);
jspb.Message.setOneofWrapperField(this, 14, proto.ServerMessage.oneofGroups_[0], value);
};
@ -1209,23 +1479,23 @@ proto.ServerMessage.prototype.clearEvalDone = function() {
* @return{!boolean}
*/
proto.ServerMessage.prototype.hasEvalDone = function() {
return jspb.Message.getField(this, 10) != null;
return jspb.Message.getField(this, 14) != null;
};
/**
* optional WorkingInitMessage init = 11;
* optional WorkingInitMessage init = 15;
* @return {proto.WorkingInitMessage}
*/
proto.ServerMessage.prototype.getInit = function() {
return /** @type{proto.WorkingInitMessage} */ (
jspb.Message.getWrapperField(this, proto.WorkingInitMessage, 11));
jspb.Message.getWrapperField(this, proto.WorkingInitMessage, 15));
};
/** @param {proto.WorkingInitMessage|undefined} value */
proto.ServerMessage.prototype.setInit = function(value) {
jspb.Message.setOneofWrapperField(this, 11, proto.ServerMessage.oneofGroups_[0], value);
jspb.Message.setOneofWrapperField(this, 15, proto.ServerMessage.oneofGroups_[0], value);
};
@ -1239,23 +1509,23 @@ proto.ServerMessage.prototype.clearInit = function() {
* @return{!boolean}
*/
proto.ServerMessage.prototype.hasInit = function() {
return jspb.Message.getField(this, 11) != null;
return jspb.Message.getField(this, 15) != null;
};
/**
* optional SharedProcessActiveMessage shared_process_active = 12;
* optional SharedProcessActiveMessage shared_process_active = 16;
* @return {proto.SharedProcessActiveMessage}
*/
proto.ServerMessage.prototype.getSharedProcessActive = function() {
return /** @type{proto.SharedProcessActiveMessage} */ (
jspb.Message.getWrapperField(this, vscode_pb.SharedProcessActiveMessage, 12));
jspb.Message.getWrapperField(this, vscode_pb.SharedProcessActiveMessage, 16));
};
/** @param {proto.SharedProcessActiveMessage|undefined} value */
proto.ServerMessage.prototype.setSharedProcessActive = function(value) {
jspb.Message.setOneofWrapperField(this, 12, proto.ServerMessage.oneofGroups_[0], value);
jspb.Message.setOneofWrapperField(this, 16, proto.ServerMessage.oneofGroups_[0], value);
};
@ -1269,7 +1539,7 @@ proto.ServerMessage.prototype.clearSharedProcessActive = function() {
* @return{!boolean}
*/
proto.ServerMessage.prototype.hasSharedProcessActive = function() {
return jspb.Message.getField(this, 12) != null;
return jspb.Message.getField(this, 16) != null;
};

View File

@ -114,3 +114,28 @@ message ConnectionOutputMessage {
message ConnectionCloseMessage {
uint64 id = 1;
}
message NewServerMessage {
uint64 id = 1;
uint64 port = 2;
string path = 3;
}
message NewServerFailureMessage {
uint64 id = 1;
string message = 2;
}
message ServerEstablishedMessage {
uint64 id = 1;
}
message ServerCloseMessage {
uint64 id = 1;
string reason = 2;
}
message ServerConnectionEstablishedMessage {
uint64 server_id = 1;
uint64 connection_id = 2;
}

View File

@ -418,3 +418,123 @@ export namespace ConnectionCloseMessage {
}
}
export class NewServerMessage extends jspb.Message {
getId(): number;
setId(value: number): void;
getPort(): number;
setPort(value: number): void;
getPath(): string;
setPath(value: string): void;
serializeBinary(): Uint8Array;
toObject(includeInstance?: boolean): NewServerMessage.AsObject;
static toObject(includeInstance: boolean, msg: NewServerMessage): NewServerMessage.AsObject;
static extensions: {[key: number]: jspb.ExtensionFieldInfo<jspb.Message>};
static extensionsBinary: {[key: number]: jspb.ExtensionFieldBinaryInfo<jspb.Message>};
static serializeBinaryToWriter(message: NewServerMessage, writer: jspb.BinaryWriter): void;
static deserializeBinary(bytes: Uint8Array): NewServerMessage;
static deserializeBinaryFromReader(message: NewServerMessage, reader: jspb.BinaryReader): NewServerMessage;
}
export namespace NewServerMessage {
export type AsObject = {
id: number,
port: number,
path: string,
}
}
export class NewServerFailureMessage extends jspb.Message {
getId(): number;
setId(value: number): void;
getMessage(): string;
setMessage(value: string): void;
serializeBinary(): Uint8Array;
toObject(includeInstance?: boolean): NewServerFailureMessage.AsObject;
static toObject(includeInstance: boolean, msg: NewServerFailureMessage): NewServerFailureMessage.AsObject;
static extensions: {[key: number]: jspb.ExtensionFieldInfo<jspb.Message>};
static extensionsBinary: {[key: number]: jspb.ExtensionFieldBinaryInfo<jspb.Message>};
static serializeBinaryToWriter(message: NewServerFailureMessage, writer: jspb.BinaryWriter): void;
static deserializeBinary(bytes: Uint8Array): NewServerFailureMessage;
static deserializeBinaryFromReader(message: NewServerFailureMessage, reader: jspb.BinaryReader): NewServerFailureMessage;
}
export namespace NewServerFailureMessage {
export type AsObject = {
id: number,
message: string,
}
}
export class ServerEstablishedMessage extends jspb.Message {
getId(): number;
setId(value: number): void;
serializeBinary(): Uint8Array;
toObject(includeInstance?: boolean): ServerEstablishedMessage.AsObject;
static toObject(includeInstance: boolean, msg: ServerEstablishedMessage): ServerEstablishedMessage.AsObject;
static extensions: {[key: number]: jspb.ExtensionFieldInfo<jspb.Message>};
static extensionsBinary: {[key: number]: jspb.ExtensionFieldBinaryInfo<jspb.Message>};
static serializeBinaryToWriter(message: ServerEstablishedMessage, writer: jspb.BinaryWriter): void;
static deserializeBinary(bytes: Uint8Array): ServerEstablishedMessage;
static deserializeBinaryFromReader(message: ServerEstablishedMessage, reader: jspb.BinaryReader): ServerEstablishedMessage;
}
export namespace ServerEstablishedMessage {
export type AsObject = {
id: number,
}
}
export class ServerCloseMessage extends jspb.Message {
getId(): number;
setId(value: number): void;
getReason(): string;
setReason(value: string): void;
serializeBinary(): Uint8Array;
toObject(includeInstance?: boolean): ServerCloseMessage.AsObject;
static toObject(includeInstance: boolean, msg: ServerCloseMessage): ServerCloseMessage.AsObject;
static extensions: {[key: number]: jspb.ExtensionFieldInfo<jspb.Message>};
static extensionsBinary: {[key: number]: jspb.ExtensionFieldBinaryInfo<jspb.Message>};
static serializeBinaryToWriter(message: ServerCloseMessage, writer: jspb.BinaryWriter): void;
static deserializeBinary(bytes: Uint8Array): ServerCloseMessage;
static deserializeBinaryFromReader(message: ServerCloseMessage, reader: jspb.BinaryReader): ServerCloseMessage;
}
export namespace ServerCloseMessage {
export type AsObject = {
id: number,
reason: string,
}
}
export class ServerConnectionEstablishedMessage extends jspb.Message {
getServerId(): number;
setServerId(value: number): void;
getConnectionId(): number;
setConnectionId(value: number): void;
serializeBinary(): Uint8Array;
toObject(includeInstance?: boolean): ServerConnectionEstablishedMessage.AsObject;
static toObject(includeInstance: boolean, msg: ServerConnectionEstablishedMessage): ServerConnectionEstablishedMessage.AsObject;
static extensions: {[key: number]: jspb.ExtensionFieldInfo<jspb.Message>};
static extensionsBinary: {[key: number]: jspb.ExtensionFieldBinaryInfo<jspb.Message>};
static serializeBinaryToWriter(message: ServerConnectionEstablishedMessage, writer: jspb.BinaryWriter): void;
static deserializeBinary(bytes: Uint8Array): ServerConnectionEstablishedMessage;
static deserializeBinaryFromReader(message: ServerConnectionEstablishedMessage, reader: jspb.BinaryReader): ServerConnectionEstablishedMessage;
}
export namespace ServerConnectionEstablishedMessage {
export type AsObject = {
serverId: number,
connectionId: number,
}
}

View File

@ -16,10 +16,15 @@ goog.exportSymbol('proto.ConnectionOutputMessage', null, global);
goog.exportSymbol('proto.IdentifySessionMessage', null, global);
goog.exportSymbol('proto.NewConnectionFailureMessage', null, global);
goog.exportSymbol('proto.NewConnectionMessage', null, global);
goog.exportSymbol('proto.NewServerFailureMessage', null, global);
goog.exportSymbol('proto.NewServerMessage', null, global);
goog.exportSymbol('proto.NewSessionFailureMessage', null, global);
goog.exportSymbol('proto.NewSessionFailureMessage.Reason', null, global);
goog.exportSymbol('proto.NewSessionMessage', null, global);
goog.exportSymbol('proto.ResizeSessionTTYMessage', null, global);
goog.exportSymbol('proto.ServerCloseMessage', null, global);
goog.exportSymbol('proto.ServerConnectionEstablishedMessage', null, global);
goog.exportSymbol('proto.ServerEstablishedMessage', null, global);
goog.exportSymbol('proto.SessionDoneMessage', null, global);
goog.exportSymbol('proto.SessionOutputMessage', null, global);
goog.exportSymbol('proto.SessionOutputMessage.Source', null, global);
@ -3153,4 +3158,934 @@ proto.ConnectionCloseMessage.prototype.setId = function(value) {
};
/**
* Generated by JsPbCodeGenerator.
* @param {Array=} opt_data Optional initial data array, typically from a
* server response, or constructed directly in Javascript. The array is used
* in place and becomes part of the constructed object. It is not cloned.
* If no data is provided, the constructed object will be empty, but still
* valid.
* @extends {jspb.Message}
* @constructor
*/
proto.NewServerMessage = function(opt_data) {
jspb.Message.initialize(this, opt_data, 0, -1, null, null);
};
goog.inherits(proto.NewServerMessage, jspb.Message);
if (goog.DEBUG && !COMPILED) {
proto.NewServerMessage.displayName = 'proto.NewServerMessage';
}
if (jspb.Message.GENERATE_TO_OBJECT) {
/**
* Creates an object representation of this proto suitable for use in Soy templates.
* Field names that are reserved in JavaScript and will be renamed to pb_name.
* To access a reserved field use, foo.pb_<name>, eg, foo.pb_default.
* For the list of reserved names please see:
* com.google.apps.jspb.JsClassTemplate.JS_RESERVED_WORDS.
* @param {boolean=} opt_includeInstance Whether to include the JSPB instance
* for transitional soy proto support: http://goto/soy-param-migration
* @return {!Object}
*/
proto.NewServerMessage.prototype.toObject = function(opt_includeInstance) {
return proto.NewServerMessage.toObject(opt_includeInstance, this);
};
/**
* Static version of the {@see toObject} method.
* @param {boolean|undefined} includeInstance Whether to include the JSPB
* instance for transitional soy proto support:
* http://goto/soy-param-migration
* @param {!proto.NewServerMessage} msg The msg instance to transform.
* @return {!Object}
*/
proto.NewServerMessage.toObject = function(includeInstance, msg) {
var f, obj = {
id: msg.getId(),
port: msg.getPort(),
path: msg.getPath()
};
if (includeInstance) {
obj.$jspbMessageInstance = msg;
}
return obj;
};
}
/**
* Deserializes binary data (in protobuf wire format).
* @param {jspb.ByteSource} bytes The bytes to deserialize.
* @return {!proto.NewServerMessage}
*/
proto.NewServerMessage.deserializeBinary = function(bytes) {
var reader = new jspb.BinaryReader(bytes);
var msg = new proto.NewServerMessage;
return proto.NewServerMessage.deserializeBinaryFromReader(msg, reader);
};
/**
* Deserializes binary data (in protobuf wire format) from the
* given reader into the given message object.
* @param {!proto.NewServerMessage} msg The message object to deserialize into.
* @param {!jspb.BinaryReader} reader The BinaryReader to use.
* @return {!proto.NewServerMessage}
*/
proto.NewServerMessage.deserializeBinaryFromReader = function(msg, reader) {
while (reader.nextField()) {
if (reader.isEndGroup()) {
break;
}
var field = reader.getFieldNumber();
switch (field) {
case 1:
var value = /** @type {number} */ (reader.readUint64());
msg.setId(value);
break;
case 2:
var value = /** @type {number} */ (reader.readUint64());
msg.setPort(value);
break;
case 3:
var value = /** @type {string} */ (reader.readString());
msg.setPath(value);
break;
default:
reader.skipField();
break;
}
}
return msg;
};
/**
* Class method variant: serializes the given message to binary data
* (in protobuf wire format), writing to the given BinaryWriter.
* @param {!proto.NewServerMessage} message
* @param {!jspb.BinaryWriter} writer
*/
proto.NewServerMessage.serializeBinaryToWriter = function(message, writer) {
message.serializeBinaryToWriter(writer);
};
/**
* Serializes the message to binary data (in protobuf wire format).
* @return {!Uint8Array}
*/
proto.NewServerMessage.prototype.serializeBinary = function() {
var writer = new jspb.BinaryWriter();
this.serializeBinaryToWriter(writer);
return writer.getResultBuffer();
};
/**
* Serializes the message to binary data (in protobuf wire format),
* writing to the given BinaryWriter.
* @param {!jspb.BinaryWriter} writer
*/
proto.NewServerMessage.prototype.serializeBinaryToWriter = function (writer) {
var f = undefined;
f = this.getId();
if (f !== 0) {
writer.writeUint64(
1,
f
);
}
f = this.getPort();
if (f !== 0) {
writer.writeUint64(
2,
f
);
}
f = this.getPath();
if (f.length > 0) {
writer.writeString(
3,
f
);
}
};
/**
* Creates a deep clone of this proto. No data is shared with the original.
* @return {!proto.NewServerMessage} The clone.
*/
proto.NewServerMessage.prototype.cloneMessage = function() {
return /** @type {!proto.NewServerMessage} */ (jspb.Message.cloneMessage(this));
};
/**
* optional uint64 id = 1;
* @return {number}
*/
proto.NewServerMessage.prototype.getId = function() {
return /** @type {number} */ (jspb.Message.getFieldProto3(this, 1, 0));
};
/** @param {number} value */
proto.NewServerMessage.prototype.setId = function(value) {
jspb.Message.setField(this, 1, value);
};
/**
* optional uint64 port = 2;
* @return {number}
*/
proto.NewServerMessage.prototype.getPort = function() {
return /** @type {number} */ (jspb.Message.getFieldProto3(this, 2, 0));
};
/** @param {number} value */
proto.NewServerMessage.prototype.setPort = function(value) {
jspb.Message.setField(this, 2, value);
};
/**
* optional string path = 3;
* @return {string}
*/
proto.NewServerMessage.prototype.getPath = function() {
return /** @type {string} */ (jspb.Message.getFieldProto3(this, 3, ""));
};
/** @param {string} value */
proto.NewServerMessage.prototype.setPath = function(value) {
jspb.Message.setField(this, 3, value);
};
/**
* Generated by JsPbCodeGenerator.
* @param {Array=} opt_data Optional initial data array, typically from a
* server response, or constructed directly in Javascript. The array is used
* in place and becomes part of the constructed object. It is not cloned.
* If no data is provided, the constructed object will be empty, but still
* valid.
* @extends {jspb.Message}
* @constructor
*/
proto.NewServerFailureMessage = function(opt_data) {
jspb.Message.initialize(this, opt_data, 0, -1, null, null);
};
goog.inherits(proto.NewServerFailureMessage, jspb.Message);
if (goog.DEBUG && !COMPILED) {
proto.NewServerFailureMessage.displayName = 'proto.NewServerFailureMessage';
}
if (jspb.Message.GENERATE_TO_OBJECT) {
/**
* Creates an object representation of this proto suitable for use in Soy templates.
* Field names that are reserved in JavaScript and will be renamed to pb_name.
* To access a reserved field use, foo.pb_<name>, eg, foo.pb_default.
* For the list of reserved names please see:
* com.google.apps.jspb.JsClassTemplate.JS_RESERVED_WORDS.
* @param {boolean=} opt_includeInstance Whether to include the JSPB instance
* for transitional soy proto support: http://goto/soy-param-migration
* @return {!Object}
*/
proto.NewServerFailureMessage.prototype.toObject = function(opt_includeInstance) {
return proto.NewServerFailureMessage.toObject(opt_includeInstance, this);
};
/**
* Static version of the {@see toObject} method.
* @param {boolean|undefined} includeInstance Whether to include the JSPB
* instance for transitional soy proto support:
* http://goto/soy-param-migration
* @param {!proto.NewServerFailureMessage} msg The msg instance to transform.
* @return {!Object}
*/
proto.NewServerFailureMessage.toObject = function(includeInstance, msg) {
var f, obj = {
id: msg.getId(),
message: msg.getMessage()
};
if (includeInstance) {
obj.$jspbMessageInstance = msg;
}
return obj;
};
}
/**
* Deserializes binary data (in protobuf wire format).
* @param {jspb.ByteSource} bytes The bytes to deserialize.
* @return {!proto.NewServerFailureMessage}
*/
proto.NewServerFailureMessage.deserializeBinary = function(bytes) {
var reader = new jspb.BinaryReader(bytes);
var msg = new proto.NewServerFailureMessage;
return proto.NewServerFailureMessage.deserializeBinaryFromReader(msg, reader);
};
/**
* Deserializes binary data (in protobuf wire format) from the
* given reader into the given message object.
* @param {!proto.NewServerFailureMessage} msg The message object to deserialize into.
* @param {!jspb.BinaryReader} reader The BinaryReader to use.
* @return {!proto.NewServerFailureMessage}
*/
proto.NewServerFailureMessage.deserializeBinaryFromReader = function(msg, reader) {
while (reader.nextField()) {
if (reader.isEndGroup()) {
break;
}
var field = reader.getFieldNumber();
switch (field) {
case 1:
var value = /** @type {number} */ (reader.readUint64());
msg.setId(value);
break;
case 2:
var value = /** @type {string} */ (reader.readString());
msg.setMessage(value);
break;
default:
reader.skipField();
break;
}
}
return msg;
};
/**
* Class method variant: serializes the given message to binary data
* (in protobuf wire format), writing to the given BinaryWriter.
* @param {!proto.NewServerFailureMessage} message
* @param {!jspb.BinaryWriter} writer
*/
proto.NewServerFailureMessage.serializeBinaryToWriter = function(message, writer) {
message.serializeBinaryToWriter(writer);
};
/**
* Serializes the message to binary data (in protobuf wire format).
* @return {!Uint8Array}
*/
proto.NewServerFailureMessage.prototype.serializeBinary = function() {
var writer = new jspb.BinaryWriter();
this.serializeBinaryToWriter(writer);
return writer.getResultBuffer();
};
/**
* Serializes the message to binary data (in protobuf wire format),
* writing to the given BinaryWriter.
* @param {!jspb.BinaryWriter} writer
*/
proto.NewServerFailureMessage.prototype.serializeBinaryToWriter = function (writer) {
var f = undefined;
f = this.getId();
if (f !== 0) {
writer.writeUint64(
1,
f
);
}
f = this.getMessage();
if (f.length > 0) {
writer.writeString(
2,
f
);
}
};
/**
* Creates a deep clone of this proto. No data is shared with the original.
* @return {!proto.NewServerFailureMessage} The clone.
*/
proto.NewServerFailureMessage.prototype.cloneMessage = function() {
return /** @type {!proto.NewServerFailureMessage} */ (jspb.Message.cloneMessage(this));
};
/**
* optional uint64 id = 1;
* @return {number}
*/
proto.NewServerFailureMessage.prototype.getId = function() {
return /** @type {number} */ (jspb.Message.getFieldProto3(this, 1, 0));
};
/** @param {number} value */
proto.NewServerFailureMessage.prototype.setId = function(value) {
jspb.Message.setField(this, 1, value);
};
/**
* optional string message = 2;
* @return {string}
*/
proto.NewServerFailureMessage.prototype.getMessage = function() {
return /** @type {string} */ (jspb.Message.getFieldProto3(this, 2, ""));
};
/** @param {string} value */
proto.NewServerFailureMessage.prototype.setMessage = function(value) {
jspb.Message.setField(this, 2, value);
};
/**
* Generated by JsPbCodeGenerator.
* @param {Array=} opt_data Optional initial data array, typically from a
* server response, or constructed directly in Javascript. The array is used
* in place and becomes part of the constructed object. It is not cloned.
* If no data is provided, the constructed object will be empty, but still
* valid.
* @extends {jspb.Message}
* @constructor
*/
proto.ServerEstablishedMessage = function(opt_data) {
jspb.Message.initialize(this, opt_data, 0, -1, null, null);
};
goog.inherits(proto.ServerEstablishedMessage, jspb.Message);
if (goog.DEBUG && !COMPILED) {
proto.ServerEstablishedMessage.displayName = 'proto.ServerEstablishedMessage';
}
if (jspb.Message.GENERATE_TO_OBJECT) {
/**
* Creates an object representation of this proto suitable for use in Soy templates.
* Field names that are reserved in JavaScript and will be renamed to pb_name.
* To access a reserved field use, foo.pb_<name>, eg, foo.pb_default.
* For the list of reserved names please see:
* com.google.apps.jspb.JsClassTemplate.JS_RESERVED_WORDS.
* @param {boolean=} opt_includeInstance Whether to include the JSPB instance
* for transitional soy proto support: http://goto/soy-param-migration
* @return {!Object}
*/
proto.ServerEstablishedMessage.prototype.toObject = function(opt_includeInstance) {
return proto.ServerEstablishedMessage.toObject(opt_includeInstance, this);
};
/**
* Static version of the {@see toObject} method.
* @param {boolean|undefined} includeInstance Whether to include the JSPB
* instance for transitional soy proto support:
* http://goto/soy-param-migration
* @param {!proto.ServerEstablishedMessage} msg The msg instance to transform.
* @return {!Object}
*/
proto.ServerEstablishedMessage.toObject = function(includeInstance, msg) {
var f, obj = {
id: msg.getId()
};
if (includeInstance) {
obj.$jspbMessageInstance = msg;
}
return obj;
};
}
/**
* Deserializes binary data (in protobuf wire format).
* @param {jspb.ByteSource} bytes The bytes to deserialize.
* @return {!proto.ServerEstablishedMessage}
*/
proto.ServerEstablishedMessage.deserializeBinary = function(bytes) {
var reader = new jspb.BinaryReader(bytes);
var msg = new proto.ServerEstablishedMessage;
return proto.ServerEstablishedMessage.deserializeBinaryFromReader(msg, reader);
};
/**
* Deserializes binary data (in protobuf wire format) from the
* given reader into the given message object.
* @param {!proto.ServerEstablishedMessage} msg The message object to deserialize into.
* @param {!jspb.BinaryReader} reader The BinaryReader to use.
* @return {!proto.ServerEstablishedMessage}
*/
proto.ServerEstablishedMessage.deserializeBinaryFromReader = function(msg, reader) {
while (reader.nextField()) {
if (reader.isEndGroup()) {
break;
}
var field = reader.getFieldNumber();
switch (field) {
case 1:
var value = /** @type {number} */ (reader.readUint64());
msg.setId(value);
break;
default:
reader.skipField();
break;
}
}
return msg;
};
/**
* Class method variant: serializes the given message to binary data
* (in protobuf wire format), writing to the given BinaryWriter.
* @param {!proto.ServerEstablishedMessage} message
* @param {!jspb.BinaryWriter} writer
*/
proto.ServerEstablishedMessage.serializeBinaryToWriter = function(message, writer) {
message.serializeBinaryToWriter(writer);
};
/**
* Serializes the message to binary data (in protobuf wire format).
* @return {!Uint8Array}
*/
proto.ServerEstablishedMessage.prototype.serializeBinary = function() {
var writer = new jspb.BinaryWriter();
this.serializeBinaryToWriter(writer);
return writer.getResultBuffer();
};
/**
* Serializes the message to binary data (in protobuf wire format),
* writing to the given BinaryWriter.
* @param {!jspb.BinaryWriter} writer
*/
proto.ServerEstablishedMessage.prototype.serializeBinaryToWriter = function (writer) {
var f = undefined;
f = this.getId();
if (f !== 0) {
writer.writeUint64(
1,
f
);
}
};
/**
* Creates a deep clone of this proto. No data is shared with the original.
* @return {!proto.ServerEstablishedMessage} The clone.
*/
proto.ServerEstablishedMessage.prototype.cloneMessage = function() {
return /** @type {!proto.ServerEstablishedMessage} */ (jspb.Message.cloneMessage(this));
};
/**
* optional uint64 id = 1;
* @return {number}
*/
proto.ServerEstablishedMessage.prototype.getId = function() {
return /** @type {number} */ (jspb.Message.getFieldProto3(this, 1, 0));
};
/** @param {number} value */
proto.ServerEstablishedMessage.prototype.setId = function(value) {
jspb.Message.setField(this, 1, value);
};
/**
* Generated by JsPbCodeGenerator.
* @param {Array=} opt_data Optional initial data array, typically from a
* server response, or constructed directly in Javascript. The array is used
* in place and becomes part of the constructed object. It is not cloned.
* If no data is provided, the constructed object will be empty, but still
* valid.
* @extends {jspb.Message}
* @constructor
*/
proto.ServerCloseMessage = function(opt_data) {
jspb.Message.initialize(this, opt_data, 0, -1, null, null);
};
goog.inherits(proto.ServerCloseMessage, jspb.Message);
if (goog.DEBUG && !COMPILED) {
proto.ServerCloseMessage.displayName = 'proto.ServerCloseMessage';
}
if (jspb.Message.GENERATE_TO_OBJECT) {
/**
* Creates an object representation of this proto suitable for use in Soy templates.
* Field names that are reserved in JavaScript and will be renamed to pb_name.
* To access a reserved field use, foo.pb_<name>, eg, foo.pb_default.
* For the list of reserved names please see:
* com.google.apps.jspb.JsClassTemplate.JS_RESERVED_WORDS.
* @param {boolean=} opt_includeInstance Whether to include the JSPB instance
* for transitional soy proto support: http://goto/soy-param-migration
* @return {!Object}
*/
proto.ServerCloseMessage.prototype.toObject = function(opt_includeInstance) {
return proto.ServerCloseMessage.toObject(opt_includeInstance, this);
};
/**
* Static version of the {@see toObject} method.
* @param {boolean|undefined} includeInstance Whether to include the JSPB
* instance for transitional soy proto support:
* http://goto/soy-param-migration
* @param {!proto.ServerCloseMessage} msg The msg instance to transform.
* @return {!Object}
*/
proto.ServerCloseMessage.toObject = function(includeInstance, msg) {
var f, obj = {
id: msg.getId(),
reason: msg.getReason()
};
if (includeInstance) {
obj.$jspbMessageInstance = msg;
}
return obj;
};
}
/**
* Deserializes binary data (in protobuf wire format).
* @param {jspb.ByteSource} bytes The bytes to deserialize.
* @return {!proto.ServerCloseMessage}
*/
proto.ServerCloseMessage.deserializeBinary = function(bytes) {
var reader = new jspb.BinaryReader(bytes);
var msg = new proto.ServerCloseMessage;
return proto.ServerCloseMessage.deserializeBinaryFromReader(msg, reader);
};
/**
* Deserializes binary data (in protobuf wire format) from the
* given reader into the given message object.
* @param {!proto.ServerCloseMessage} msg The message object to deserialize into.
* @param {!jspb.BinaryReader} reader The BinaryReader to use.
* @return {!proto.ServerCloseMessage}
*/
proto.ServerCloseMessage.deserializeBinaryFromReader = function(msg, reader) {
while (reader.nextField()) {
if (reader.isEndGroup()) {
break;
}
var field = reader.getFieldNumber();
switch (field) {
case 1:
var value = /** @type {number} */ (reader.readUint64());
msg.setId(value);
break;
case 2:
var value = /** @type {string} */ (reader.readString());
msg.setReason(value);
break;
default:
reader.skipField();
break;
}
}
return msg;
};
/**
* Class method variant: serializes the given message to binary data
* (in protobuf wire format), writing to the given BinaryWriter.
* @param {!proto.ServerCloseMessage} message
* @param {!jspb.BinaryWriter} writer
*/
proto.ServerCloseMessage.serializeBinaryToWriter = function(message, writer) {
message.serializeBinaryToWriter(writer);
};
/**
* Serializes the message to binary data (in protobuf wire format).
* @return {!Uint8Array}
*/
proto.ServerCloseMessage.prototype.serializeBinary = function() {
var writer = new jspb.BinaryWriter();
this.serializeBinaryToWriter(writer);
return writer.getResultBuffer();
};
/**
* Serializes the message to binary data (in protobuf wire format),
* writing to the given BinaryWriter.
* @param {!jspb.BinaryWriter} writer
*/
proto.ServerCloseMessage.prototype.serializeBinaryToWriter = function (writer) {
var f = undefined;
f = this.getId();
if (f !== 0) {
writer.writeUint64(
1,
f
);
}
f = this.getReason();
if (f.length > 0) {
writer.writeString(
2,
f
);
}
};
/**
* Creates a deep clone of this proto. No data is shared with the original.
* @return {!proto.ServerCloseMessage} The clone.
*/
proto.ServerCloseMessage.prototype.cloneMessage = function() {
return /** @type {!proto.ServerCloseMessage} */ (jspb.Message.cloneMessage(this));
};
/**
* optional uint64 id = 1;
* @return {number}
*/
proto.ServerCloseMessage.prototype.getId = function() {
return /** @type {number} */ (jspb.Message.getFieldProto3(this, 1, 0));
};
/** @param {number} value */
proto.ServerCloseMessage.prototype.setId = function(value) {
jspb.Message.setField(this, 1, value);
};
/**
* optional string reason = 2;
* @return {string}
*/
proto.ServerCloseMessage.prototype.getReason = function() {
return /** @type {string} */ (jspb.Message.getFieldProto3(this, 2, ""));
};
/** @param {string} value */
proto.ServerCloseMessage.prototype.setReason = function(value) {
jspb.Message.setField(this, 2, value);
};
/**
* Generated by JsPbCodeGenerator.
* @param {Array=} opt_data Optional initial data array, typically from a
* server response, or constructed directly in Javascript. The array is used
* in place and becomes part of the constructed object. It is not cloned.
* If no data is provided, the constructed object will be empty, but still
* valid.
* @extends {jspb.Message}
* @constructor
*/
proto.ServerConnectionEstablishedMessage = function(opt_data) {
jspb.Message.initialize(this, opt_data, 0, -1, null, null);
};
goog.inherits(proto.ServerConnectionEstablishedMessage, jspb.Message);
if (goog.DEBUG && !COMPILED) {
proto.ServerConnectionEstablishedMessage.displayName = 'proto.ServerConnectionEstablishedMessage';
}
if (jspb.Message.GENERATE_TO_OBJECT) {
/**
* Creates an object representation of this proto suitable for use in Soy templates.
* Field names that are reserved in JavaScript and will be renamed to pb_name.
* To access a reserved field use, foo.pb_<name>, eg, foo.pb_default.
* For the list of reserved names please see:
* com.google.apps.jspb.JsClassTemplate.JS_RESERVED_WORDS.
* @param {boolean=} opt_includeInstance Whether to include the JSPB instance
* for transitional soy proto support: http://goto/soy-param-migration
* @return {!Object}
*/
proto.ServerConnectionEstablishedMessage.prototype.toObject = function(opt_includeInstance) {
return proto.ServerConnectionEstablishedMessage.toObject(opt_includeInstance, this);
};
/**
* Static version of the {@see toObject} method.
* @param {boolean|undefined} includeInstance Whether to include the JSPB
* instance for transitional soy proto support:
* http://goto/soy-param-migration
* @param {!proto.ServerConnectionEstablishedMessage} msg The msg instance to transform.
* @return {!Object}
*/
proto.ServerConnectionEstablishedMessage.toObject = function(includeInstance, msg) {
var f, obj = {
serverId: msg.getServerId(),
connectionId: msg.getConnectionId()
};
if (includeInstance) {
obj.$jspbMessageInstance = msg;
}
return obj;
};
}
/**
* Deserializes binary data (in protobuf wire format).
* @param {jspb.ByteSource} bytes The bytes to deserialize.
* @return {!proto.ServerConnectionEstablishedMessage}
*/
proto.ServerConnectionEstablishedMessage.deserializeBinary = function(bytes) {
var reader = new jspb.BinaryReader(bytes);
var msg = new proto.ServerConnectionEstablishedMessage;
return proto.ServerConnectionEstablishedMessage.deserializeBinaryFromReader(msg, reader);
};
/**
* Deserializes binary data (in protobuf wire format) from the
* given reader into the given message object.
* @param {!proto.ServerConnectionEstablishedMessage} msg The message object to deserialize into.
* @param {!jspb.BinaryReader} reader The BinaryReader to use.
* @return {!proto.ServerConnectionEstablishedMessage}
*/
proto.ServerConnectionEstablishedMessage.deserializeBinaryFromReader = function(msg, reader) {
while (reader.nextField()) {
if (reader.isEndGroup()) {
break;
}
var field = reader.getFieldNumber();
switch (field) {
case 1:
var value = /** @type {number} */ (reader.readUint64());
msg.setServerId(value);
break;
case 2:
var value = /** @type {number} */ (reader.readUint64());
msg.setConnectionId(value);
break;
default:
reader.skipField();
break;
}
}
return msg;
};
/**
* Class method variant: serializes the given message to binary data
* (in protobuf wire format), writing to the given BinaryWriter.
* @param {!proto.ServerConnectionEstablishedMessage} message
* @param {!jspb.BinaryWriter} writer
*/
proto.ServerConnectionEstablishedMessage.serializeBinaryToWriter = function(message, writer) {
message.serializeBinaryToWriter(writer);
};
/**
* Serializes the message to binary data (in protobuf wire format).
* @return {!Uint8Array}
*/
proto.ServerConnectionEstablishedMessage.prototype.serializeBinary = function() {
var writer = new jspb.BinaryWriter();
this.serializeBinaryToWriter(writer);
return writer.getResultBuffer();
};
/**
* Serializes the message to binary data (in protobuf wire format),
* writing to the given BinaryWriter.
* @param {!jspb.BinaryWriter} writer
*/
proto.ServerConnectionEstablishedMessage.prototype.serializeBinaryToWriter = function (writer) {
var f = undefined;
f = this.getServerId();
if (f !== 0) {
writer.writeUint64(
1,
f
);
}
f = this.getConnectionId();
if (f !== 0) {
writer.writeUint64(
2,
f
);
}
};
/**
* Creates a deep clone of this proto. No data is shared with the original.
* @return {!proto.ServerConnectionEstablishedMessage} The clone.
*/
proto.ServerConnectionEstablishedMessage.prototype.cloneMessage = function() {
return /** @type {!proto.ServerConnectionEstablishedMessage} */ (jspb.Message.cloneMessage(this));
};
/**
* optional uint64 server_id = 1;
* @return {number}
*/
proto.ServerConnectionEstablishedMessage.prototype.getServerId = function() {
return /** @type {number} */ (jspb.Message.getFieldProto3(this, 1, 0));
};
/** @param {number} value */
proto.ServerConnectionEstablishedMessage.prototype.setServerId = function(value) {
jspb.Message.setField(this, 1, value);
};
/**
* optional uint64 connection_id = 2;
* @return {number}
*/
proto.ServerConnectionEstablishedMessage.prototype.getConnectionId = function() {
return /** @type {number} */ (jspb.Message.getFieldProto3(this, 2, 0));
};
/** @param {number} value */
proto.ServerConnectionEstablishedMessage.prototype.setConnectionId = function(value) {
jspb.Message.setField(this, 2, value);
};
goog.object.extend(exports, proto);

View File

@ -198,4 +198,39 @@ describe("createConnection", () => {
});
});
});
});
describe("createServer", () => {
const client = createClient();
const tmpPath = path.join(os.tmpdir(), Math.random().toString());
it("should connect to server", (done) => {
const s = client.createServer(() => {
s.close();
});
s.on("close", () => {
done();
});
s.listen(tmpPath);
});
it("should connect to server and get socket connection", (done) => {
const s = client.createServer();
s.listen(tmpPath, () => {
net.createConnection(tmpPath, () => {
checks++;
s.close();
});
});
let checks = 0;
s.on("connection", (con) => {
expect(checks).toEqual(1);
con.end();
checks++;
});
s.on("close", () => {
expect(checks).toEqual(2);
done();
});
});
});