On 2009-05-06, at 21:01, Patrick Schlangen wrote:
I implemented this using TServerEventHandler:
* there's a static map that holds client addrs: map<unsigned long,
string>
* client addresses are added to a map in MyHandler::clientBegin(),
pthread_self() is the key in address map
That sounds like a great idea. But how do you get the client's IP in
clientBegin()?
I tried to cast the input or output parameter to a TSocket and call
getPeerAddress() but it returns an empty string only.
This should work, more or less. I omited checks for nulls, locking, etc.
TBufferedTransport *tbuf = dynamic_cast<TBufferedTransport *>(input-
>getTransport().get());
TSocket *sock = dynamic_cast<TSocket *>(tbuf-
>getUnderlyingTransport().get());
addrs[pthread_self()] = sock->getPeerAddress();