exec
は、開いているファイル記述子を継承しません。
1つの可能な解決策:サブプロセスを親プロセスに接続させます。親プロセスは接続を受け入れ、すべてのデータを直接トラフィックジェネレータに渡し、応答を適切なサブプロセスに返します。
編集:
別の解決策同時に複数のアップグレードを処理するために、あなたのアップグレード手順を書き換えることです。これは、execを使うよりも簡単かもしれません。
主な問題は、トラフィックマネージャから受信したデータがどのプロセスまたはアップグレード接続を対象としているかを判断する方法が必要なことです。これは、上記の方法を使用する場合でも、複数のアップグレードを一度に処理できるようにアップグレードプロセスを書き直す場合にも当てはまります。
トラフィックマネージャから着信データをルーティングする方法がない場合は、やりたいことは難しいでしょう。
このコードは非常に単純化されています。エラーチェックはなく、ソケットの終了を処理しません。
ソケットの操作はtry {}ブロックで囲む必要があります。ソケットエラーはいつでも発生する可能性があるためです。
また、接続では、(バイナリデータを送信する場合)エンコーディングが正しく設定されている必要があります。
# First, the server (the main process) must create the
# server socket and associate it with a connection handler.
# A read handler is set up to handle the incoming data.
proc readHandler {sock} {
global tmsock
if {[gets $sock data] >= 0} {
puts $tmsock $data
}
}
proc connectHandler {sock addr port} {
global socks
# save the socket the connection came in on.
# the array index should not be the port, but rather some
# data which can be used to route incoming messages from the
# traffic manager.
set socks($port) $sock
fconfigure $sock -buffering line -blocking false
fileevent $sock readable [list ::readHandler $sock]
}
socket -server ::connectHandler $myport
# The server also needs an event handler for data
# from the traffic manager.
proc tmReadHandler {} {
global tmsock
global socks
if {[gets $tmsock data] >= 0} {
# have to determine which process the data is for
set port unknown?
set sock $socks($port)
puts $sock $data
}
}
fileevent $tmsock readable [list ::tmReadHandler]
ありがとうブラッド。私はTCLの初心者ですので、オンラインでその方法を確認します。あなたは頭の上からそれをする方法を知っていますか?すべてのポインタ? – user322541