#include <cstdlib>
#ifdef CCXX_NAMESPACES
using namespace std;
using namespace ost;
#endif
{
protected:
public:
};
{
private:
void run(void);
void final(void);
public:
static volatile int count;
};
{
cout << "accepting from: " << ia.getHostname() << ":" << port << endl;;
return true;
}
volatile int myTCPSession::count = 0;
Mutex myTCPSession::mutex;
myTCPSession::myTCPSession(
TCPSocket &server) :
{
cout << "creating session client object" << endl;
mutex.enterMutex();
++count;
mutex.leaveMutex();
}
void myTCPSession::run(void)
{
*tcp() <<
"welcome to " << addr.
getHostname() <<
" from socket " << (int)so << endl;
mutex.enterMutex();
*tcp() << "called from thread " << count << endl;
mutex.leaveMutex();
sleep(5000);
*tcp() << "ending session" << endl;
}
void myTCPSession::final(void)
{
}
int main()
{
myTCPSession *tcp;
addr = "255.255.255.255";
cout <<
"testing addr: " << addr.
getHostname() <<
":" << 4096 << endl;
addr = "127.0.0.1";
cout << "binding for: " << addr.getHostname() << ":" << 4096 << endl;
try {
myTCPSocket server(addr);
cout << "before create" << endl;
tcp = new myTCPSession(server);
cout << "after create" << endl;
tcp->detach();
}
}
cerr <<
"socket error " << saddr.
getHostname() <<
":" << port <<
" = " << err << endl;
if(err == Socket::errBindingFailed) {
cerr << "bind failed; port busy" << endl;
::exit(-1);
}
else
cerr << "client socket failed" << endl;
}
cout << "timeout after 30 seconds inactivity, exiting" << endl;
return 0;
}