private void Close() { if (logPool.IsDebugEnabled) { logPool.Debug("Socket Closed."); } if (this.socketListener != null) { this.socketListener.onClosed(); } this.socketListener = null; this.interruptionHandler = null; this.set(CLOSED); //we'll be closed soon anyway }
private async void errorAsync(IChannel ch) { if (logPool.IsDebugEnabled) { logPool.Debug("Socket error."); } if (this.socketListener != null) { this.socketListener.onBroken(); } this.socketListener = null; this.interruptionHandler = null; this.set(CLOSED); //we'll be closed soon anyway closeChannel(ch); }
private void reuse(IChannelHandlerContext ctx) { if (!keepalive) { closeChannel(ctx.Channel); } if (this.socketListener != null) { log.Debug("Reuse failed for " + ctx.Channel.Id); this.socketListener.onClosed(); } this.socketListener = null; this.interruptionHandler = null; this.keepalive = false; this.set(OPEN); }
/// <summary> /// Binds the request listener with the socket so that the opening/reading/closing events of the socket are notified to the listener. /// Returns false if the socket can't be bound. /// </summary> public virtual bool switchListener(Uri uri, NettyRequestListener socketListener, NettyInterruptionHandler interruptionHandler) { lock (this) { if (this.@is(OPEN)) { socketListener.onOpen(); } else if (this.@is(OCCUPIED) || this.@is(CLOSED)) { //should never happen! what do we do? XXX return(false); } //else if is init we'll get the onOpen later this.uri = uri; this.socketListener = socketListener; switchInterruptionHandler(interruptionHandler); this.lineAssembler = new LineAssembler(socketListener); return(true); } }
private async void bindAsync(Uri uri, NettyFullAddress target, com.lightstreamer.client.transport.providers.HttpProvider_HttpRequestListener httpListener, IFullHttpRequest httpRequest, NettyInterruptionHandler interruptionHandler) { if (log.IsDebugEnabled) { log.Debug("HTTP transport connection establishing (oid=" + objectId + "): " + format(uri, httpRequest)); log.Debug(" - target: " + format(target)); } try { IChannel channel_e = await httpPoolManager.acquire(target); log.Debug(" - acquired! " + channel_e.Id); // IChannel ch2 = channelFuture.Result; NettySocketHandler socketHandler2 = (NettySocketHandler)PipelineUtils.getChannelHandler(channel_e); if (socketHandler2 == null) { log.Debug("Socket Handler null."); } else { NettyRequestListener requestListener2 = new NettyRequestListener(httpListener, target, channel_e, httpPoolManager); bool listenerBound = socketHandler2.switchListener(uri, requestListener2, interruptionHandler); if (!listenerBound) { this.sessionThread.schedule(new Task(() => { bindAsync(uri, target, httpListener, httpRequest, interruptionHandler); }), 500); if (log.IsDebugEnabled) { log.Debug("Go Bind!"); } } else { // Thread.Sleep(400); Task snd_req = channel_e.WriteAndFlushAsync(httpRequest).ContinueWith((snd_req_task, fu2) => { log.Debug("Send Request Task status = " + snd_req_task.Status); if (snd_req_task.IsFaulted) { log.Error("HTTP write failed [" + channel_e.Id + "]: " + httpRequest.Uri + ", " + snd_req_task.Exception); channel_e.CloseAsync(); requestListener2.onBroken(); } }, this); if (log.IsDebugEnabled) { log.Debug("Go with the request " + channel_e.Active); } } } return; } catch (ConnectException ce) { log.Info("Connection error: " + ce.Message); if (log.IsDebugEnabled) { log.Debug("HTTP transport connection error (Couldn't get a socket, try again) (oid=" + objectId + "): " + format(uri, httpRequest)); log.Debug(" - " + ce.StackTrace); } } catch (ConnectTimeoutException cte) { log.Info("Timeout error: " + cte.Message); if (log.IsDebugEnabled) { log.Debug("HTTP transport timeout error (Couldn't get a socket, try again) (oid=" + objectId + "): " + format(uri, httpRequest)); log.Debug(" - " + cte.StackTrace); } } catch (Exception e) { log.Info("Error: " + e.Message); if (log.IsDebugEnabled) { log.Debug("HTTP transport error (Couldn't get a socket, try again) (oid=" + objectId + "): " + format(uri, httpRequest)); log.Debug(" - " + e.StackTrace); } } }