Skip to content

Commit

Permalink
fix: better naming
Browse files Browse the repository at this point in the history
  • Loading branch information
MarioArnt authored and grs committed Mar 10, 2023
1 parent 8bcb3af commit ee8c088
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 27 deletions.
14 changes: 7 additions & 7 deletions lib/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,12 @@ function get_socket_id(socket) {
return socket.localAddress + ':' + socket.localPort + ' -> ' + socket.remoteAddress + ':' + socket.remotePort;
}

function session_per_connection(conn, buffer_size) {
function session_per_connection(conn, session_buffer_size) {
var ssn = null;
return {
'get_session' : function () {
if (!ssn) {
ssn = conn.create_session(buffer_size);
ssn = conn.create_session(session_buffer_size);
ssn.observers.on('session_close', function () { ssn = null; });
ssn.begin();
}
Expand Down Expand Up @@ -208,7 +208,7 @@ var Connection = function (options, container) {
&& options.servername === undefined && options.host !== undefined) {
this.options.servername = options.host;
}
this.buffer_size = options.buffer_size;
this.session_buffer_size = options.session_buffer_size;
} else {
this.options = get_default_connect_config();
}
Expand All @@ -233,7 +233,7 @@ var Connection = function (options, container) {
this.remote = {};
this.local.open = frames.open(connection_fields(this.options));
this.local.close = frames.close({});
this.session_policy = session_per_connection(this, this.buffer_size);
this.session_policy = session_per_connection(this, this.session_buffer_size);
this.amqp_transport = new Transport(this.options.id, AMQP_PROTOCOL_ID, frames.TYPE_AMQP, this);
this.sasl_transport = undefined;
this.transport = this.amqp_transport;
Expand Down Expand Up @@ -682,10 +682,10 @@ Connection.prototype.is_closed = function () {
return this.state.is_closed();
};

Connection.prototype.create_session = function (buffer_size) {
Connection.prototype.create_session = function (session_buffer_size) {
var i = 0;
while (this.local_channel_map[i]) i++;
var session = new Session(this, i, buffer_size);
var session = new Session(this, i, session_buffer_size);
this.local_channel_map[i] = session;
return session;
};
Expand Down Expand Up @@ -791,7 +791,7 @@ Connection.prototype.on_begin = function (frame) {
var session;
if (frame.performative.remote_channel === null || frame.performative.remote_channel === undefined) {
//peer initiated
session = this.create_session(this.buffer_size);
session = this.create_session(this.session_buffer_size);
session.local.begin.remote_channel = frame.channel;
} else {
session = this.local_channel_map[frame.performative.remote_channel];
Expand Down
36 changes: 18 additions & 18 deletions lib/session.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,25 +116,25 @@ function write_dispositions(deliveries) {
}
}

function validate_buffer_size(buffer_size) {
if (buffer_size && Number.isInteger(Number(buffer_size))) {
return Number(buffer_size);
function validate_buffer_size(session_buffer_size) {
if (session_buffer_size && Number.isInteger(Number(session_buffer_size))) {
return Number(session_buffer_size);
}
return DEFAULT_BUFFER_SIZE;
}

function get_buffer_size(buffer_size, type) {
if (!buffer_size) {
function get_buffer_size(session_buffer_size, type) {
if (!session_buffer_size) {
return DEFAULT_BUFFER_SIZE;
}
if (typeof buffer_size === 'number') {
return validate_buffer_size(buffer_size);
if (typeof session_buffer_size === 'number') {
return validate_buffer_size(session_buffer_size);
}
return validate_buffer_size(buffer_size[type]);
return validate_buffer_size(session_buffer_size[type]);
}

var Outgoing = function (connection, buffer_size) {
this.deliveries = new CircularBuffer(get_buffer_size(buffer_size, 'outgoing'));
var Outgoing = function (connection, session_buffer_size) {
this.deliveries = new CircularBuffer(get_buffer_size(session_buffer_size, 'outgoing'));
this.updated = [];
this.pending_dispositions = [];
this.next_delivery_id = 0;
Expand Down Expand Up @@ -303,8 +303,8 @@ Outgoing.prototype.process = function() {
this.deliveries.pop_if(function (d) { return d.settled && d.remote_settled; });
};

var Incoming = function (buffer_size) {
this.deliveries = new CircularBuffer(get_buffer_size(buffer_size, 'incoming'));
var Incoming = function (session_buffer_size) {
this.deliveries = new CircularBuffer(get_buffer_size(session_buffer_size, 'incoming'));
this.updated = [];
this.next_transfer_id = 0;
this.next_delivery_id = undefined;
Expand Down Expand Up @@ -434,11 +434,11 @@ Incoming.prototype.on_disposition = function (fields) {
}
};

var Session = function (connection, local_channel, buffer_size) {
var Session = function (connection, local_channel, session_buffer_size) {
this.connection = connection;
this.buffer_size = buffer_size;
this.outgoing = new Outgoing(connection, buffer_size);
this.incoming = new Incoming(buffer_size);
this.session_buffer_size = session_buffer_size;
this.outgoing = new Outgoing(connection, session_buffer_size);
this.incoming = new Incoming(session_buffer_size);
this.state = new EndpointState();
this.local = {'channel': local_channel, 'handles':{}};
this.local.begin = frames.begin({next_outgoing_id:this.outgoing.next_transfer_id,incoming_window:this.incoming.window,outgoing_window:this.outgoing.window});
Expand All @@ -464,8 +464,8 @@ Session.prototype._disconnect = function() {

Session.prototype._reconnect = function() {
this.state.reconnect();
this.outgoing = new Outgoing(this.connection, this.buffer_size);
this.incoming = new Incoming(this.buffer_size);
this.outgoing = new Outgoing(this.connection, this.session_buffer_size);
this.incoming = new Incoming(this.session_buffer_size);
this.remote = {'handles':{}};
for (var l in this.links) {
this.links[l]._reconnect();
Expand Down
4 changes: 2 additions & 2 deletions typings/connection.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,10 @@ interface CommonConnectionOptions extends EndpointOptions {
max_frame_size?: number;

/**
* @property {number} [buffer_size] The connection sessions outgoing and incoming CircularBuffer size.
* @property {number} [session_buffer_size] The connection sessions outgoing and incoming CircularBuffer size.
* Default: 2048
*/
buffer_size?: number | { incoming?: number, outgoing?: number };
session_buffer_size?: number | { incoming?: number, outgoing?: number };
/**
* @property {number} [idle_time_out] The maximum period in milliseconds between activity
* (frames) on the connection that is desired from the peer. The open frame carries the
Expand Down

0 comments on commit ee8c088

Please sign in to comment.