private void PipelineReceive(SocketToken token) { var fromCursor = 0; /* * read data from receiveBuffer by moving fromCursor. */ while (true) { var currentCommand = token.currentCommands[pipelineIndex]; var result = DisquuunAPI.ScanBuffer(currentCommand, token.receiveBuffer, fromCursor, token.readableDataLength, socketId); if (result.isDone) { token.AsyncCallback(currentCommand, result.data); // deque as read done. pipelineIndex++; if (token.currentCommands.Length == pipelineIndex) { // pipelining is over. switch (token.socketState) { case SocketState.BUSY: { token.socketState = SocketState.RECEIVED; break; } case SocketState.SENDED: { token.socketState = SocketState.OPENED; SocketReloaded(this); break; } default: { break; } } return; } // commands are still remained. // got all data is just consumed. get rest from outside. if (fromCursor == token.readableDataLength) { StartContinueReceiving(token, 0); return; } // rest pipeline commands and received data is exists in buffer. fromCursor = result.cursor; continue; } /* * reading is not completed. the fragment of command exists. */ var fragmentDataLength = token.readableDataLength - fromCursor; // move fragment data to head of buffer. Buffer.BlockCopy(token.receiveBuffer, fromCursor, token.receiveBuffer, 0, fragmentDataLength); StartContinueReceiving(token, fragmentDataLength); break; } }
protected override void OnTcpDisConn(SocketToken token) { }
public NetConnectionToken(SocketToken sToken) { this.Token = sToken; Verification = true; ConnectionTime = DateTime.Now;//兼容低版本语法 }
void INetMessageHandler.OnTcpDisConn(SocketToken token) { OnTcpDisConn(token); }
void INetMessageHandler.OnTcpMessage(SocketToken token, INetMessage message) { OnTcpMessage(token, message); }
protected abstract void OnTcpDisConn(SocketToken token);
protected abstract void OnTcpMessage(SocketToken token, INetMessage message);
public void SendTcpMessage(SocketToken token, INetMessage message) { tcp.SendAsync(token, NetMessageToBufferSegment(message)); }