CIRCDCCFileTransfer.onDataAvailable Member

Syntax

object.onDataAvailable(e);

Arguments

ArgumentSummary
e

Returns

Remarks

See Also

Source Code

function dfile_dataavailable(e)
{
e.type = "rawdata";
e.destMethod = "onRawData";
try
{
if (this.state.dir == DCC_DIR_SENDING)
{
while (e.data.length >= 4)
{
var word = e.data.substr(0, 4);
e.data = e.data.substr(4, e.data.length - 4);
var pos = word.charCodeAt(0) * 0x01000000
+ word.charCodeAt(1) * 0x00010000
+ word.charCodeAt(2) * 0x00000100
+ word.charCodeAt(3) * 0x00000001;
this.ackPosition = pos;
}
while (this.position <= this.ackPosition + this.parent.maxUnAcked)
{
var d;
if (this.position + this.parent.sendChunk > this.size)
d = this.filestream.readBytes(this.size - this.position);
else
d = this.filestream.readBytes(this.parent.sendChunk);
this.position += d.length;
this.connection.sendData(d);
if (this.position >= this.size)
{
this.dispose();
break;
}
}
}
else if (this.state.dir == DCC_DIR_GETTING)
{
this.filestream.writeBytes(e.data, e.data.length);
// Send back ack data.
this.position += e.data.length;
var bytes = new Array();
for (var i = 0; i < 4; i++)
bytes.push(Math.floor(this.position / Math.pow(256, i)) & 255);
this.connection.sendData(String.fromCharCode(bytes[3], bytes[2],
bytes[1], bytes[0]));
if (this.size && (this.position >= this.size))
this.disconnect();
}
this.eventPump.addEvent(new CEvent("dcc-file", "progress",
this, "onProgress"));
}
catch(ex)
{
this.disconnect();
}
return true;
}