在 Thrift 处理函数中获取对等地址
我正在 ruby 中实现一个小型 thrift (0.6.0) 服务器,以充当另一个协议的代理角色,该协议与单个服务器有多个连接(多个客户端)。我希望能够在服务器端保留每个客户端的数据,并在处理程序函数的多次调用中跟踪“会话”参数。
我目前使用 Thrift::NonblockingServer ,因为 SimpleServer 似乎不允许并发连接。
我知道如何使用 TCPSocket::peeraddr
但 Thrift::NonblockingServer::IOManager::Worker::run
创建一个临时 MemoryBufferTransport
它读取帧并将其作为输入/输出协议传递到处理器,因此似乎信息不是从那里传递下来的。
有没有一种干净的方法来做到这一点? 我正在考虑重新定义上面提到的 Thrift::NonblockingServer::IOManager::Worker::run
以在附加参数中包含 fd 或其他 ID 来处理或增强原型实例但由于我还必须担心生成的 ruby 代码的一层(class Processor
中的 process_*
方法),它看起来有点重。
我想知道以前是否有人做过类似的事情。
谢谢!
ps 这与 这个 C++ thrift 问题类似的问题
I am implementing a small thrift (0.6.0) server in ruby to play a role of proxy to another protocol with several connections (multiple clients) to a single server. I want to be able and keep per-client data on the server side and track "session" parameters across multiple invocations of handler functions.
I currently use Thrift::NonblockingServer
as SimpleServer
does not seem to allow concurrent connections.
I know how to use TCPSocket::peeraddr
but Thrift::NonblockingServer::IOManager::Worker::run
creates a temporary MemoryBufferTransport
with the frame it read and passes that as the input/output protocol down to the processor so it seems that the info is not passed down from there.
Is there a clean way to do this?
I was thinking of re-defining the above mentioned Thrift::NonblockingServer::IOManager::Worker::run
to also include the fd, or other ID at an additional parameter to process or augment the proto instances but as I also have to worry about one layer of generated ruby code (process_*
methods in class Processor
) it seems a little heavy.
I wonder if someone did anything like this before.
Thanks!
p.s. this is similar problem to this C++ thrift question
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
以下是我如何更改
Thrift::NonblockingServer::IOManager::Worker::run
以支持此操作。一些警告:
$connections
应该是@@connections
ConnEntry
或 diff 类?)。首先,在某个中央模块:
然后在处理程序中的任何位置您都可以访问
Thread.current[:connEntry].addr_info
用于连接特定数据或在Thread.current[:connEntry].attr
哈希中存储有关连接的任何内容。Here is how I went about changing
Thrift::NonblockingServer::IOManager::Worker::run
to support this.Few caveats:
$connections
be@@connections
inConnEntry
or a diff class?).Thread.current
hash for thread-local storage has a namespace pollution issueFirst, at some central module:
Then at any point in the handler you can access
Thread.current[:connEntry].addr_info
for connection specific data or store anything regarding the connection in theThread.current[:connEntry].attr
hash.