protected override void OnSend(int nErrorCode) { if (nErrorCode != 0) { OnError(nErrorCode); return; } base.OnSend(0); lock (sendLocker_) { do { IsBusy = false; if (connState_ == ConnectionStateEnum.CS_DISCONNECTED) { break; } else { connState_ = ConnectionStateEnum.CS_CONNECTED; } if (currentPacket_is_controlpacket_) { // queue up for control packet MuleApplication.Instance.UploadBandwidthThrottler.QueueForSendingControlPacket(this, HasSent); } } while (false); } }
public static bool HasSentHeader(this ConnectionStateEnum state) { return(state == ConnectionStateEnum.HDR_SENT || state == ConnectionStateEnum.HDR_EXCH || state == ConnectionStateEnum.OPEN_PIPE || state == ConnectionStateEnum.OC_PIPE); }
private void callStateListener(ConnectionStateEnum oldState, ConnectionStateEnum newState) { if (oldState == newState) { OnLogging(XmlBlasterLogLevel.WARN, "XmlBlasterAccess", "Same states in transition: " + newState); return; } I_ConnectionStateListener l = this.connectionStateListener; if (l != null) { try { if (newState == ConnectionStateEnum.ALIVE) { l.reachedAlive(oldState, this); } else if (newState == ConnectionStateEnum.POLLING) { l.reachedPolling(oldState, this); } else if (newState == ConnectionStateEnum.DEAD) { l.reachedDead(oldState, this); } } catch (Exception e) { OnLogging(XmlBlasterLogLevel.WARN, "" + newState, "User code failed: " + e.ToString()); } } }
public void UpdateView(bool available, ConnectionStateEnum callState, string status, string error, string incomingCall, bool privacy, bool dnd, bool content, bool pip, bool auto) { if (InvokeRequired) { Invoke(new UpdateViewDelegate(UpdateView), available, callState, status, error, incomingCall, privacy, dnd, content, pip, auto); return; } SetAvailableStatus(available); if (available) { baCallState.Image = callState == ConnectionStateEnum.Connected ? global::Hosts.Plugins.VDCTerminal.Properties.Resources.Phone_off : global::Hosts.Plugins.VDCTerminal.Properties.Resources.Phone; baCallState.Enabled = callState == ConnectionStateEnum.Connected ? true : false; alStatusDesc.Text = status + (error == string.Empty ? string.Empty : "/" + error); if (alStatusDesc.Text.Trim() == "/") alStatusDesc.Text = string.Empty; UpdateIncomingCallText(incomingCall); baIncomingCancel.Enabled = string.IsNullOrEmpty(incomingCall) ? false : true; baIncomingAnswer.Enabled = string.IsNullOrEmpty(incomingCall) ? false : true; SetButtonState(baPrivacy, privacy); SetButtonState(baDND, dnd); SetButtonState(baContent, content); SetButtonState(baPIP, pip); SetButtonState(baAuto, auto); } }
public static bool IsExpectingProtocolHeader(this ConnectionStateEnum state) { return(state == ConnectionStateEnum.START || state == ConnectionStateEnum.HDR_SENT || state == ConnectionStateEnum.OPEN_PIPE || state == ConnectionStateEnum.OC_PIPE); }
public static void SetImplementation(ConnectionStateEnum state, Type type) { if (!type.IsSubclassOf(typeof(MpConnectionState))) { return; } connectionImpls[(int)state] = type; foreach (var method in type.GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly)) { var attr = method.GetAttribute <PacketHandlerAttribute>(); if (attr == null) { continue; } if (method.GetParameters().Length != 1 || method.GetParameters()[0].ParameterType != typeof(ByteReader)) { continue; } bool fragment = method.GetAttribute <IsFragmentedAttribute>() != null; packetHandlers[(int)state, (int)attr.packet] = new PacketHandlerInfo(method, fragment); } }
private void AfterSuccessLogin(InitialAppDataResponseData data = null) { m_state = ConnectionStateEnum.Connected; m_NTconnection.ProcessEventArgs(new ConnectionStatusEventArgs(m_NTconnection, ErrorCode.NoError, "", ConnectionStatus.Connected, ConnectionStatus.Connected)); if (m_firstConnect) { m_firstConnect = false; m_NTconnection.AccountItems = new AccountItem[] { AccountItem.CashValue, AccountItem.RealizedProfitLoss }; m_NTconnection.Actions = new OrderAction[] { OrderAction.Buy, OrderAction.BuyToCover, OrderAction.Sell, OrderAction.SellShort }; m_NTconnection.Currencies = new NinjaTrader.Cbi.Currency[] { NinjaTrader.Cbi.Currency.Unknown, NinjaTrader.Cbi.Currency.UsDollar }; m_NTconnection.Exchanges = new Exchange[] { Exchange.Default }; m_NTconnection.Features = new Feature[] { Feature.SynchronousInstrumentLookup, Feature.MarketData, Feature.Order, Feature.OrderChange }; m_NTconnection.InstrumentTypes = new[] { InstrumentType.Currency, InstrumentType.Stock, InstrumentType.Index, InstrumentType.Future }; m_NTconnection.MarketDataTypes = new MarketDataType[] { MarketDataType.Ask, MarketDataType.Bid, MarketDataType.DailyHigh, MarketDataType.DailyLow, MarketDataType.Last, MarketDataType.Opening }; m_NTconnection.MarketPositions = new MarketPosition[] { MarketPosition.Flat, MarketPosition.Long, MarketPosition.Short }; m_NTconnection.OrderStates = new OrderState[] { OrderState.Cancelled, OrderState.Filled, OrderState.Working }; m_NTconnection.OrderTypes = new OrderType[] { OrderType.Limit, OrderType.Market }; m_NTconnection.TimeInForces = new TimeInForce[] { TimeInForce.Gtc }; } // After we reported about the login update the accounts if (m_userInfo.Accounts.Count > 0 && !string.IsNullOrEmpty(m_userInfo.Accounts[0].GUID)) { m_NTconnection.ProcessEventArgs(new AccountEventArgs(m_NTconnection, ErrorCode.NoError, "", m_userInfo.Accounts[0].GUID, Mode.Live)); UpdateAccountStatus(m_userInfo.Accounts[0]); } UpdatePositionsUpdate(data.Positions, data.Orders); UpdateMarketData(data.Quotes, data.Assets); }
private void ChangeConnectionState(ConnectionStateEnum state) { this.Dispatcher.Invoke(() => { ((MainWindowModel)this.DataContext).ConnectionState = state; ((MainWindowModel)this.DataContext).SetPropertyChanged("ConnectionState"); }); }
public static bool CanSendFrames(this ConnectionStateEnum state) { return(state == ConnectionStateEnum.OPENED || state == ConnectionStateEnum.HDR_EXCH || state == ConnectionStateEnum.OPEN_PIPE || state == ConnectionStateEnum.OPEN_RCVD || state == ConnectionStateEnum.OPEN_SENT || state == ConnectionStateEnum.CLOSED_RCVD); }
private void Shutdown() { this.isDead = true; ConnectionStateEnum oldState = this.currentState; StopPinging(); StopPolling(); this.currentState = ConnectionStateEnum.DEAD; callStateListener(oldState, ConnectionStateEnum.DEAD); }
public static bool CanReceiveFrames(this ConnectionStateEnum state) { return(state == ConnectionStateEnum.OPENED || state == ConnectionStateEnum.HDR_EXCH || state == ConnectionStateEnum.OPEN_PIPE || state == ConnectionStateEnum.OC_PIPE || state == ConnectionStateEnum.OPEN_RCVD || state == ConnectionStateEnum.OPEN_SENT || state == ConnectionStateEnum.CLOSE_PIPE || state == ConnectionStateEnum.CLOSE_SENT); }
/// <summary> /// Set the status of our ICCP link /// </summary> /// <param name="Good">Whether the link is good</param> /// <param name="SDIS">Whether the link is active</param> public void SetStatus(bool Good, bool SDIS) { if (!Good) { this.ConnectionState = ConnectionStateEnum.Unknown; } else if (!SDIS) { this.ConnectionState = ConnectionStateEnum.Bad; } else { this.ConnectionState = ConnectionStateEnum.Good; } }
public static void ConnectToServer(this SqlConnection connection) { sqlConnection = new SqlConnection(connectionStringNew); try { sqlConnection.Open(); sqlConnection.StateChange += Connection_StateChange; ConnectionState = ConnectionStateEnum.CONNECTED; } catch (Exception er) { ConnectionState = ConnectionStateEnum.FAIL; Console.WriteLine(er.Message); } }
public void reachedDead(ConnectionStateEnum oldStateBeneath, I_XmlBlasterAccess connection) { ConnectionStateEnum oldState = this.currentState; if (this.xbPoller.IsConfiguredToWork()) // We know better than the layer below { this.currentState = ConnectionStateEnum.POLLING; callStateListener(oldState, this.currentState); StopPinging(); StartPolling(); return; } this.currentState = ConnectionStateEnum.DEAD; callStateListener(oldState, this.currentState); StopPinging(); StopPolling(); }
public EMSocketImpl() : base() { DataReceived += OnDataReceived; PacketReceived += OnPacketReceived; connState_ = ConnectionStateEnum.CS_NOTCONNECTED; TimeOut = MuleConstants.CONNECTION_TIMEOUT; // default timeout for ed2k sockets // Download (pseudo) rate control downloadLimit_ = 0; enableDownloadLimit_ = false; pendingOnReceive_ = false; // Download partial header pendingHeaderSize_ = 0; // Download partial packet pendingPacket_ = null; pendingPacketSize_ = 0; // Upload control sendbuffer_ = null; sendblen_ = 0; sent_ = 0; //bLinkedPackets_ = false; currentPacket_is_controlpacket_ = false; currentPackageIsFromPartFile_ = false; numberOfSentBytesCompleteFile_ = 0; numberOfSentBytesPartFile_ = 0; numberOfSentBytesControlPacket_ = 0; lastCalledSend_ = MpdUtilities.GetTickCount(); lastSent_ = MpdUtilities.GetTickCount() - 1000; accelerateUpload_ = false; actualPayloadSize_ = 0; actualPayloadSizeSent_ = 0; hasSent_ = false; useBigSendBuffer_ = false; }
protected override void OnClose(int nErrorCode) { // need to be locked here to know that the other methods // won't be in the middle of things lock (sendLocker_) { connState_ = ConnectionStateEnum.CS_DISCONNECTED; } // now that we know no other method will keep adding to the queue // we can remove ourself from the queue //TODO:MuleApplication.Instance.RemoveFromAllQueues(this); RemoveAllLayers(); // deadlake PROXYSUPPORT ClearQueues(); base.OnClose(nErrorCode); // deadlake changed socket to PROXYSUPPORT ( AsyncSocketEx ) }
public PXAdapter(Connection connection) { m_state = ConnectionStateEnum.Disconnected; m_NTconnection = connection; m_pxConnector = new Connector(); m_supportesAssets = new Dictionary <string, Asset>(); m_subscriptions = new Dictionary <string, Data.MarketData>(); m_symbolExchangeCodeMap = new Dictionary <string, string>(); m_lastQuotes = new Dictionary <string, Quote>(); m_positions = new List <pxNetAdapter.Model.Trading.Position>(); m_ntOrderPxOrder = new Dictionary <string, string>(); m_pxConnector.OnConnect += m_pxConnector_OnConnect; m_pxConnector.OnDisconnect += m_pxConnector_OnDisconnect; m_pxConnector.OnReconnect += m_pxConnector_OnReconnect; m_pxConnector.OnMessage += m_pxConnector_OnMessage; }
private bool StartPinging() { this.CheckValid(); //if (this.connectReturnQos == null) return false; //if (this.disconnectCalled) return false; if (this.pingIntervalMillis < 1L) { return(false); } bool started = this.xbPinger.Start(); if (started) { ConnectionStateEnum oldState = this.currentState; this.currentState = ConnectionStateEnum.ALIVE; callStateListener(oldState, this.currentState); } return(started); }
private static void Connection_StateChange(object sender, System.Data.StateChangeEventArgs e) { switch (e.CurrentState) { case System.Data.ConnectionState.Open: ConnectionState = ConnectionStateEnum.CONNECTED; break; case System.Data.ConnectionState.Closed: ConnectionState = ConnectionStateEnum.DISCONNECTED; break; case System.Data.ConnectionState.Broken: ConnectionState = ConnectionStateEnum.BROKEN; break; default: break; } }
public void reachedPolling(ConnectionStateEnum oldStateBeneath, I_XmlBlasterAccess connection) { ConnectionStateEnum oldState = this.currentState; this.currentState = ConnectionStateEnum.POLLING; I_ConnectionStateListener l = this.connectionStateListener; if (l != null) { try { l.reachedPolling(oldState, connection); } catch (Exception e) { OnLogging(XmlBlasterLogLevel.WARN, "reachedPolling", "User code failed: " + e.ToString()); } } StopPinging(); StartPolling(); }
private bool StartPolling() { if (!this.IsValid()) { return(false); } //if (this.disconnectCalled) return false; if (this.pollIntervalMillis < 1L) { return(false); } bool started = this.xbPoller.Start(); if (started) { ConnectionStateEnum oldState = this.currentState; this.currentState = ConnectionStateEnum.POLLING; callStateListener(oldState, this.currentState); } return(started); }
private void OnConnectionStateChanged(ConnectionStateEnum state) { switch (state) { case ConnectionStateEnum.Connected: { if (this.DeleteAllCallsOnConnect) { ///////////////////////////////////////////////////////////// /// Cleanup any existing calls on this appID... /// CallDispatcher <T> .Instance.GetCalls(); List <String> resourceids = CallDispatcher <T> .Instance.Calls.Select(x => x.ResourceID).ToList(); foreach (String resourceid in resourceids) { CallDispatcher <T> .Instance.DeleteCall(resourceid); } } } break; } } /* OnConnectionStateChanged() */
protected override void OnReceive(int nErrorCode) { // Check for an error code if (nErrorCode != 0) { OnError(nErrorCode); return; } // Check current connection state if (connState_ == ConnectionStateEnum.CS_DISCONNECTED) { return; } else { connState_ = ConnectionStateEnum.CS_CONNECTED; } // CPU load improvement if (EnableDownloadLimit && DownloadLimit == 0) { pendingOnReceive_ = true; //Receive(GlobalReadBuffer + pendingHeaderSize, 0); return; } // Remark: an overflow can not occur here uint readMax = GLOBAL_READ_BUFFER_SIZE - pendingHeaderSize_; if (EnableDownloadLimit && readMax > DownloadLimit) { readMax = DownloadLimit; } // We attempt to read up to 2 megs at a time (minus whatever is in our internal read buffer) int ret = Receive(GlobalReadBuffer, Convert.ToInt32(pendingHeaderSize_), Convert.ToInt32(readMax)); if (ret == SOCKET_ERROR || connState_ == ConnectionStateEnum.CS_DISCONNECTED) { return; } // Bandwidth control if (EnableDownloadLimit) { // Update limit downloadLimit_ -= Convert.ToUInt32(RealReceivedBytes); } // CPU load improvement // Detect if the socket's buffer is empty (or the size did match...) pendingOnReceive_ = fullReceive_; if (ret == 0) { return; } // Copy back the partial header into the global read buffer for processing if (pendingHeaderSize_ > 0) { Array.Copy(pendingHeader_, GlobalReadBuffer, pendingHeaderSize_); ret += Convert.ToInt32(pendingHeaderSize_); pendingHeaderSize_ = 0; } if (IsRawDataMode) { DataReceived(new DataReceivedArgument(GlobalReadBuffer, Convert.ToUInt32(ret))); return; } byte[] rptr = GlobalReadBuffer; // floating index initialized with begin of buffer int buffer_end = ret; int offset = 0; // Loop, processing packets until we run out of them while ((buffer_end - offset >= MuleConstants.PACKET_HEADER_SIZE) || ((pendingPacket_ != null) && (buffer_end - offset > 0))) { // Two possibilities here: // // 1. There is no pending incoming packet // 2. There is already a partial pending incoming packet // // It's important to remember that emule exchange two kinds of packet // - The control packet // - The data packet for the transport of the block // // The biggest part of the traffic is done with the data packets. // The default size of one block is 10240 bytes (or less if compressed), but the // maximal size for one packet on the network is 1300 bytes. It's the reason // why most of the Blocks are splitted before to be sent. // // Conclusion: When the download limit is disabled, this method can be at least // called 8 times (10240/1300) by the lower layer before a splitted packet is // rebuild and transferred to the above layer for processing. // // The purpose of this algorithm is to limit the amount of data exchanged between buffers if (pendingPacket_ == null) { pendingPacket_ = MuleApplication.Instance.NetworkObjectManager.CreatePacket(GlobalReadBuffer, offset); // Create new packet container. offset += 6; // Only the header is initialized so far // Bugfix We still need to check for a valid protocol // Remark: the default eMule v0.26b had removed this test...... switch (pendingPacket_.Protocol) { case MuleConstants.PROTOCOL_EDONKEYPROT: case MuleConstants.PROTOCOL_PACKEDPROT: case MuleConstants.PROTOCOL_EMULEPROT: break; default: pendingPacket_ = null; OnError(Convert.ToInt32(EMSocketErrorCodeEnum.ERR_WRONGHEADER)); return; } // Security: Check for buffer overflow (2MB) if (pendingPacket_.Size > GLOBAL_READ_BUFFER_SIZE) { pendingPacket_ = null; OnError(Convert.ToInt32(EMSocketErrorCodeEnum.ERR_TOOBIG)); return; } // Init data buffer pendingPacket_.Buffer = new byte[pendingPacket_.Size + 1]; pendingPacketSize_ = 0; } // Bytes ready to be copied into packet's internal buffer Debug.Assert(offset <= buffer_end); uint toCopy = ((pendingPacket_.Size - pendingPacketSize_) < (uint)(buffer_end - offset)) ? (pendingPacket_.Size - pendingPacketSize_) : (uint)(buffer_end - offset); // Copy Bytes from Global buffer to packet's internal buffer Array.Copy(rptr, offset, pendingPacket_.Buffer, (int)pendingPacketSize_, toCopy); pendingPacketSize_ += toCopy; offset += Convert.ToInt32(toCopy); // Check if packet is complet Debug.Assert(pendingPacket_.Size >= pendingPacketSize_); if (pendingPacket_.Size == pendingPacketSize_) { // Process packet bool bPacketResult = PacketReceived(new PacketReceivedArgument(pendingPacket_)); pendingPacket_ = null; pendingPacketSize_ = 0; if (!bPacketResult) { return; } } } // Finally, if there is any data left over, save it for next time Debug.Assert(offset <= buffer_end); Debug.Assert(buffer_end - offset < MuleConstants.PACKET_HEADER_SIZE); if (offset != buffer_end) { // Keep the partial head pendingHeaderSize_ = Convert.ToUInt32(buffer_end - offset); Array.Copy(rptr, offset, pendingHeader_, 0, pendingHeaderSize_); } }
void m_pxConnector_OnReconnect(object sender, GenericEventArgs <int> args) { m_NTconnection.ProcessEventArgs(new ConnectionStatusEventArgs(m_NTconnection, ErrorCode.NoError, "Disconnected from ParagonEX, reconnecting...", ConnectionStatus.Connecting, ConnectionStatus.Connecting)); m_state = ConnectionStateEnum.Connecting; }
public void reachedDead(ConnectionStateEnum oldState, I_XmlBlasterAccess connection) { Console.WriteLine("reachedDead() ..."); }
void m_pxConnector_OnDisconnect(object sender, EventArgs e) { m_state = ConnectionStateEnum.Disconnected; m_NTconnection.ProcessEventArgs(new ConnectionStatusEventArgs(m_NTconnection, ErrorCode.Panic, "Disconnected from ParagonEX, can\'t reconnect", ConnectionStatus.Disconnected, ConnectionStatus.Disconnected)); }
public ConnectionStateContext(ConnectionStateEnum state) { Value = state; }
public static bool ShouldIgnoreReceivedData(this ConnectionStateEnum state) { return(state == ConnectionStateEnum.END || state == ConnectionStateEnum.CLOSED_RCVD); }