CIRCNetwork.onDoConnect Member

Syntax

object.onDoConnect(e);

Arguments

ArgumentSummary
e

Returns

Remarks

See Also

Source Code

function net_doconnect(e)
{
const NS_ERROR_OFFLINE = 0x804b0010;
var c;
// Clear the timer, if there is one.
if ("reconnectTimer" in this)
{
clearTimeout(this.reconnectTimer);
delete this.reconnectTimer;
}
var ev;
if (this.state == NET_CANCELLING)
{
if ("primServ" in this && this.primServ.connection)
this.primServ.connection.disconnect();
else
this.state = NET_OFFLINE;
ev = new CEvent ("network", "error", this, "onError");
ev.server = this;
ev.debug = "Connect sequence was cancelled.";
ev.errorCode = JSIRC_ERR_CANCELLED;
this.eventPump.addEvent(ev);
return false;
}
if ("primServ" in this && this.primServ.isConnected)
return true;
this.connectAttempt++;
this.connectCandidate++;
this.state = NET_CONNECTING; /* connection is considered "made" when server
* sends a 001 message (see server.on001) */
var host = this.nextHost++;
if (host >= this.serverList.length)
{
this.nextHost = 1;
host = 0;
}
if (this.serverList[host].isSecure || !this.requireSecurity)
{
ev = new CEvent ("network", "startconnect", this, "onStartConnect");
ev.debug = "Connecting to " + this.serverList[host].unicodeName + ":" +
this.serverList[host].port + ", attempt " + this.connectAttempt +
" of " + this.MAX_CONNECT_ATTEMPTS + "...";
ev.host = this.serverList[host].hostname;
ev.port = this.serverList[host].port;
ev.server = this.serverList[host];
ev.connectAttempt = this.connectAttempt;
ev.reconnectDelayMs = this.getReconnectDelayMs();
this.eventPump.addEvent (ev);
try
{
if (!this.serverList[host].connect(null))
{
/* connect failed, try again */
this.delayedConnect();
}
}
catch(ex)
{
this.state = NET_OFFLINE;
ev = new CEvent("network", "error", this, "onError");
ev.server = this;
ev.debug = "Exception opening socket: " + ex;
ev.errorCode = JSIRC_ERR_NO_SOCKET;
if ((typeof ex == "object") && (ex.result == NS_ERROR_OFFLINE))
ev.errorCode = JSIRC_ERR_OFFLINE;
if ((typeof ex == "string") && (ex == JSIRC_ERR_PAC_LOADING))
{
ev.errorCode = JSIRC_ERR_PAC_LOADING;
ev.retryDelay = CIRCNetwork.prototype.PAC_RECONNECT_DELAY;
/* PAC loading is not a problem with any specific server. We'll
* retry the connection in 5 seconds.
*/
this.nextHost--;
this.state = NET_WAITING;
setTimeout(function(n) { n.immediateConnect() },
ev.retryDelay, this);
}
this.eventPump.addEvent(ev);
}
}
else
{
/* Server doesn't use SSL as requested, try next one.
* In the meantime, correct the connection attempt counter */
this.connectAttempt--;
this.immediateConnect();
}
return true;
}