OpenTransport MacOS X 10.3.9: OTLook not returning events
OpenTransport MacOS X 10.3.9: OTLook not returning events
- Subject: OpenTransport MacOS X 10.3.9: OTLook not returning events
- From: Peter Paulus <email@hidden>
- Date: Wed, 1 Jun 2005 16:36:19 +0200
Hello all,
In a plugin I use OpenTransport under MacOSX 10.3.9. My original code
has been used in MacOS 9.2 with OpenTransport 2.6. It seemed to work
fine then.
I'm using the synchronous, nonblocking mechanisme. This means that I'm
polling with OTLook for events. run calls handleEvent mostly 1 time,
sometime 2 times with T_DATA. After fillQueue() has determined how many
bytes have arrived (OTCountDataBytes()) , it reads them (OTRcv()). On
subsequent passes through run handleEvent is never called again.
In fillQueue(), just after OTRcv(), kOTNoDataErr is never reached.
Calling YieldToAnyThread() in the loop does not help. Since I am a
plugin, the EventLoop is not available for me.
How can I get OTLook to report pending events?
With kind regards,
Below is the outline of my source.
// TCPSocket class
pascal void TCPSocket::YieldingNotifier(void* context, OTEventCode
event, OTResult result, void* cookie)
{
TCPSocket* socket = (TCPSocket*) context;
switch(event)
{
case kOTSyncIdleEvent:
{
YieldToAnyThread();
break;
}
default:
{
}
}
}
void TCPSocket::handleEvent(OTEventCode event, OTResult result, void*
cookie)
{
switch(event)
{
case T_DATA:
{
fillQueue();
break;
}
case ...:
{
...
break;
}
}
}
void TCPSocket::fillQueue()
{
unsigned long availableOctets = 0;
error = this->endpoint->CountDataBytes(&availableOctets);
switch(error)
{
case kOTNoError:
{
if (availableOctets > 0)
{
char *buffer = new char[availableOctets];
if (buffer)
{
OTFlags flags;
consumedOctest = this->endpoint->Rcv(buffer,
availableOctets, &flags);
switch(consumedOctets)
{
case kOTNoDataErr: // deliberate fallthrough
case kOTLookErr:
{
run();
break;
}
default:
{
if (consumedOctets > 0)
{
// append buffer to deque
Fragment* fragment = new Fragment(buffer,
consumedOctets);
fragments.push_back(fragment);
}
}
}
}
}
break;
}
case ...:
{
...
break;
}
}
}
void TCPSocket::run()
{
OTEventCode event = this->endpoint->Look();
if (event == 0)
{
// no action
}
if (event > 0)
{
handleEvent(event, kOTNoError, NULL);
}
if (event < 0)
{
std::cout << "error: " << event "\n";
}
}
void TCPSocket::bind(...)
{
this->endpoint =
OTOpenEndpointInContext(OTCloneConfiguration(this->config),
kNilOptions, &this->info, &this->error, this->context);
this->endpoint->setSynchronous();
this->endpoint->setNonBlocking();
this->endpoint->InstallNotifier((OTNotifyUPP) YieldingNotifier, this);
this->endpoint->UseSyncIdleEvents();
this->endpoint->Bind(...);
}
// Here is how it's used:
TCPSocket clientSocket;
clientSocket.bind(...); // ok
clientSocket.connect(...); // ok
clientSocket.send("GET / HTTP/1.1\r\nHost: localhost\r\n\r\n"); // ok
for(unsigned long i = 0; i < 10000000; i++)
{
clientSocket.run();
// YieldToAnyThread();
}
unsigned long octets = clientSocket.octetsAvailable();
clientSocket.read(buffer, octets);
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Macnetworkprog mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden