📄 rudpsocket.cs
字号:
Interlocked.Exchange<RUDPReceiveIAsyncResult>(ref asyncResult, this._asyncResultReceive);
if (asyncResult != null)
{
Interlocked.Exchange<RUDPReceiveIAsyncResult>(ref this._asyncResultReceive, null);
this.OnEndReceive(error, null, false, asyncResult);
}
}
internal void OnEndAccept(RUDPSocket acceptedSocket)
{
RUDPAcceptIAsyncResult result = null;
Interlocked.Exchange<RUDPAcceptIAsyncResult>(ref result, this._asyncResultAccept);
if (result != null)
{
Interlocked.Exchange<RUDPAcceptIAsyncResult>(ref this._asyncResultAccept, null);
result.AcceptedSocket = acceptedSocket;
result.ForceAsyncCall = true;
result.SetAsCompleted(RUDPSocketError.Success, false);
}
}
internal void OnEndConnect(RUDPSocketError error)
{
RUDPConnectIAsyncResult result = null;
Interlocked.Exchange<RUDPConnectIAsyncResult>(ref result, this._asyncResultConnect);
if (result != null)
{
Interlocked.Exchange<RUDPConnectIAsyncResult>(ref this._asyncResultConnect, null);
result.Connected = error == RUDPSocketError.Success;
result.SetAsCompleted(error, false);
}
}
internal void OnEndFastRetransmit()
{
this._controlWindow.OnEndFastRetransmit();
this._fastRetransmitStartPacketId = -1;
this._fastRetransmitEndPacketId = -1;
this.ResumeTransmission();
}
internal void OnEndReceive(RUDPSocketError error, RUDPIngoingPacket packet, bool forceAsyncCall, RUDPReceiveIAsyncResult asyncResult)
{
asyncResult.Packet = packet;
asyncResult.ForceAsyncCall = forceAsyncCall;
asyncResult.SetAsCompleted(error, false);
}
internal void OnEndSend(RUDPSocketError error, RUDPSendIAsyncResult asyncResult)
{
if (asyncResult != null)
{
asyncResult.SetAsCompleted(error, false);
}
}
private void PauseTransmission()
{
this._controlWindow.PauseTransmission();
}
public byte[] Receive()
{
SocketError errorCode = 0;
IAsyncResult asyncResult = this.BeginReceive(out errorCode, null, null);
return this.EndReceive(asyncResult);
}
public byte[] Receive(out SocketError errorCode)
{
IAsyncResult asyncResult = this.BeginReceive(out errorCode, null, null);
return this.EndReceive(asyncResult);
}
internal void Reset(RUDPSocketStatus status)
{
this._status = status;
this._fastRetransmitStartPacketId = -1;
this._fastRetransmitEndPacketId = -1;
this._ougoingPacketId = -1;
this._sequence = 0;
this._lastSendTS = 0;
this._lastACKSendTS = -1;
this._lastBandwidthTS = 0;
this._bandwidthResponse01TS = 0;
this._bandwidth = 0;
this._outgoingPacketsLock.EnterWriteLock();
for (int i = 0; i < this._outgoingPackets.get_Count(); i++)
{
lock (this._outgoingPackets.get_Item(i))
{
this._outgoingPackets.get_Item(i).IsACKed = true;
}
}
this._outgoingPacketsLock.ExitWriteLock();
while (this._outgoingPackets.get_Count() > 0)
{
Thread.Sleep(1);
}
this._incomingPackets.Clear();
this._sackWindow = new SACKWindow();
this._pmtuDiscovery = new PMTUDiscovery(this);
this._controlWindow.Reset();
this._NATEndPointsHistory = new List<NATHistoryPoint>();
RUDPStack.UnregisterRUDPSocket(this);
}
private void ResumeTransmission()
{
this._controlWindow.ResumeTransmission();
}
public int Send(byte[] buffer, int offset, int size)
{
RUDPSocketError errorCode = RUDPSocketError.Success;
return this.Send(buffer, offset, size, out errorCode, true);
}
public int Send(byte[] buffer, int offset, int size, out RUDPSocketError errorCode)
{
return this.Send(buffer, offset, size, out errorCode, true);
}
public int Send(byte[] buffer, int offset, int size, out RUDPSocketError errorCode, bool reliable)
{
errorCode = RUDPStack.SendPayload(this, buffer, offset, size, reliable, null);
if (errorCode != RUDPSocketError.Success)
{
return -1;
}
return size;
}
internal void SetRTT(double rtt, double deltaRTT, double rto, long sto)
{
Thread.VolatileWrite(ref this._rtt, rtt);
Thread.VolatileWrite(ref this._deltaRtt, deltaRTT);
Thread.VolatileWrite(ref this._rto, rto);
Thread.VolatileWrite(ref this._sto, sto);
}
public void Shutdown()
{
this._physical.Shutdown(this);
}
internal void StartFastRetransmit(int startPacketId, int endPacketId)
{
if (startPacketId <= -1)
{
this.PauseTransmission();
this._fastRetransmitEndPacketId = endPacketId;
this._fastRetransmitStartPacketId = startPacketId;
}
}
public bool Connected
{
get
{
return (this._status == RUDPSocketStatus.Connected);
}
}
public double DeltaRTT
{
get
{
return Thread.VolatileRead(ref this._deltaRtt);
}
set
{
Thread.VolatileWrite(ref this._rto, value);
}
}
public int Handle
{
get
{
return this._handle;
}
}
public bool IsRendezVousMode
{
get
{
return this._isRendezVousMode;
}
set
{
this._isRendezVousMode = value;
}
}
public IPEndPoint LocalEndPoint
{
get
{
return (this._physical._socket.LocalEndPoint as IPEndPoint);
}
}
public int MTU
{
get
{
return this._mtu;
}
set
{
this._mtu = value;
}
}
public RUDPSocketNetworkInformation NetworkInformation
{
get
{
return this._networkInformation;
}
}
public int ReceiveBufferSize
{
get
{
return this._receiveSize;
}
set
{
this._receiveSize = value;
}
}
public IPEndPoint RemoteEndPoint
{
get
{
return this._remoteEndPoint;
}
}
public double RTO
{
get
{
return Thread.VolatileRead(ref this._rto);
}
set
{
Thread.VolatileWrite(ref this._rto, value);
}
}
public double RTT
{
get
{
return Thread.VolatileRead(ref this._rtt);
}
set
{
Thread.VolatileWrite(ref this._rto, value);
}
}
public int SendBufferSize
{
get
{
return this._sendSize;
}
set
{
this._sendSize = value;
}
}
public long STO
{
get
{
return Thread.VolatileRead(ref this._sto);
}
set
{
Thread.VolatileWrite(ref this._rto, (double) value);
}
}
public bool UsePMTUDiscovery
{
get
{
return this._usePMTUDiscovery;
}
set
{
this._usePMTUDiscovery = value;
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -