Git Product home page Git Product logo

Comments (1)

SwingFrog avatar SwingFrog commented on May 18, 2024

首先感谢您对summer的关注。
在summer中sctx (sessionContext) 是与连接绑定的,只要链路还在,sctx就不销毁,也就是说链路仅对应一个sctx。可能您说的是http情况,http协议下每次请求进来都是一个新的链路,也就是每次都会新建个sctx,但返回完会立马销毁。
对于sctx里面的waitWriteQueue这个问题,当链路可写时,会把waitWriteQueue里面的数据包依次写出。

push和响应都是调用以下代码,当链路可写时且队列为空则立刻写出,否则添加到队列中。

		if (sctx.getWaitWriteQueueSize() == 0 && ctx.channel().isWritable()) {
			ctx.writeAndFlush(response);
		} else {
			sctx.getWaitWriteQueue().add(response);
		}

下面这个是ServerStringHandler里面的代码,当触发可写事件时将队列中的数据包逐个写出。

	public void channelWritabilityChanged(ChannelHandlerContext ctx) throws Exception {
		super.channelWritabilityChanged(ctx);
		SessionContext sctx = serverContext.getSessionContextGroup().getSessionByChannel(ctx);
		while (ctx.channel().isActive() && ctx.channel().isWritable() && sctx.getWaitWriteQueueSize() > 0) {
			ctx.writeAndFlush(sctx.getWaitWriteQueue().poll());
		}
	}

from summer.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.