Page Faults in OSX using Open Transport
Page Faults in OSX using Open Transport
- Subject: Page Faults in OSX using Open Transport
- From: Andrew Bush <email@hidden>
- Date: Sun, 13 Oct 2002 21:35:06 +1300
Hi all,
Ive got some OT code that appears to be causing a *large* number of page
faults in osx, <g> im not entirely clear what page faults mean, but the
high number appears to be related to a slow down and eventual pizza Im
seeing in my application after it has run for about 5-7 hours.
The application uses a large number of sockets, and renews the sockets
overtime as some are retired and new ones created.
At any 1 time I probably have about 200 or so open connections.
If anyone could give me some insight to a possible cause I would be very
grateful.
They appear to be occuring as the socket classes are created and the
endpoints connected, here is the initialise code I use:
Boolean
InitialiseTCPEndpoint(TCPEndpointData *data)
{
// Create an endpoint
//
// This is done so that we can pool endpoints that can be connected to
// incoming hosts in server applications. Doing it here (when the
object
// is created) allows connections to be serviced more quickly.
OSStatus err;
// Lookup default local address
InetInterfaceInfo ifInfo;
err = OTInetGetInterfaceInfo(&ifInfo, 0);
if( err != kOTNoError ) {
DEBUGMSG(" OTInetGetInterfaceInfo failed - %i\n", err);
TCPEndpoint_PostErrorEvent(data->instance, err);
return false;
}
data->localAddr.fHost = ifInfo.fAddress;
// Build local address string
char ipBuffer[32];
OTInetHostToString(data->localAddr.fHost, ipBuffer);
data->localAddress = REALBuildString( ipBuffer, strlen(ipBuffer) );
// Create endpoint
#if !CARBON
err = OTAsyncOpenEndpoint(
OTCreateConfiguration(kTCPName),
0,
NULL,
Notifier,
(void*) data
);
#else
err = OTAsyncOpenEndpointInContext(
OTCreateConfiguration(kTCPName),
0,
NULL,
NewOTNotifyUPP(Notifier),
(void*) data,
gOTContext
);
#endif
if( err != kOTNoError )
{
DEBUGMSG(" OTAsyncOpenEndpoint failed - %i\n", err);
TCPEndpoint_PostErrorEvent(data->instance, err);
return false;
}
return true;
}
and here is the connect code for the endpoint:
Boolean
TCPEndpoint_Connect(REALobject instance)
{
ClassData(TCPEndpointClass, instance, TCPEndpointData, data);
OSStatus err = kOTNoError;
#if DEMO
if(gExpired) {
return false;
}
#endif
// Do we have a correctly intialised endpoint?
// Or, are we already in the process of tearing down the connection?
if( !(data->state & kTCPEndpoint_Open) ||
(data->state & kTCPEndpoint_Disposing)
)
{
return false;
}
// Checkup on target address
if( data->addressObj == nil ) {
DEBUGMSG(" No address\n");
TCPEndpoint_PostErrorEvent(instance, kSSBadAddressError);
return false;
}
// Close current connection
if(data->state & kTCPEndpoint_Connected) {
TCPEndpoint_Disconnect(instance);
}
// Lookup remote address
if(not ResolveAddress( (char*) data->addressObj->CString(),
&data->host )) {
DEBUGMSG(" ResolveAddress failed\n");
TCPEndpoint_PostErrorEvent(instance, kSSBadAddressError);
return false;
}
// Lookup local address
if(data->useLocalAddress == true) {
OTInitInetAddress(&data->localAddr, data->localPort, 0);
if(data->localAddress != nil) {
err = OTInetStringToHost((char*)data->localAddress->CString(),
&data->localAddr.fHost);
if( err != kOTNoError ) {
DEBUGMSG(" OTInetStringToHost failed - %i\n", err);
TCPEndpoint_PostErrorEvent(instance, err);
return false;
}
}else{
// Get default interface info
InetInterfaceInfo ifInfo;
err = OTInetGetInterfaceInfo(&ifInfo, 0);
if( err != kOTNoError ) {
DEBUGMSG(" OTGetInterfaceInfo failed - %i\n", err);
TCPEndpoint_PostErrorEvent(instance, err);
return false;
}
data->localAddr.fHost = ifInfo.fAddress;
}
}else{
OTInitInetAddress(&data->localAddr, 0, 0);
}
// Set bind request
data->localBind.addr.maxlen = sizeof(InetAddress);
data->localBind.addr.len = sizeof(InetAddress);
data->localBind.addr.buf = (UInt8*) &data->localAddr;
data->localBind.qlen = 0;
// Configure endpoint for bind
err = OTSetBlocking(data->ep);
if( err != kOTNoError ) {
DEBUGMSG(" OTSetBlocking failed - %i\n", err);
TCPEndpoint_PostErrorEvent(instance, err);
return false;
}
// Perform bind
err = OTBind(data->ep, &data->localBind, &data->localBind);
if( err != kOTNoError )
{
DEBUGMSG(" OTBind failed\n");
TCPEndpoint_Disconnect(instance);
TCPEndpoint_PostErrorEvent(instance, (int) err);
return false;
}
// Setup our target address
OTInitInetAddress(&data->remoteAddr, data->port, data->host);
OTMemzero(&data->remoteCall, sizeof(TCall));
data->remoteCall.addr.maxlen = sizeof(InetAddress);
data->remoteCall.addr.len = sizeof(InetAddress);
data->remoteCall.addr.buf = (UInt8*) &data->remoteAddr;
// Attach input buffer to remote call
data->remoteCall.udata.maxlen = data->inBuffer->GetBufferCapacity();
data->remoteCall.udata.len = 0;
data->remoteCall.udata.buf = (UInt8*) data->inBuffer->GetData();
// Configure endpoint for asynchronous operations
err = OTSetAsynchronous(data->ep);
if( err != kOTNoError ) {
DEBUGMSG(" OTSetAsync failed - %i\n", err);
TCPEndpoint_PostErrorEvent(instance, err);
TCPEndpoint_Disconnect(instance);
return false;
}
// Configure endpoint for data exchange
err = OTSetNonBlocking(data->ep);
if( err != kOTNoError ) {
DEBUGMSG(" OTSetNonBlocking failed - %i\n", err);
TCPEndpoint_PostErrorEvent(instance, err);
TCPEndpoint_Disconnect(instance);
return false;
}
// Attempt a connection
err = OTConnect(data->ep, &data->remoteCall, &data->remoteCall);
if( (err != kOTNoError) &&
(err != kOTNoDataErr))
{
DEBUGMSG(" OTConnect failed - %i\n", err);
TCPEndpoint_Disconnect(instance);
TCPEndpoint_PostErrorEvent(instance, (int) err);
return false;
}
return true;
}
./..and finally the code for resolving addresses:
Boolean
ResolveAddress(char* address, InetHost *host)
{
DEBUGMSG("ResolveAddress\n");
OTResult err = kOTNoError;
static InetSvcRef inetSvc = NULL; // Used to resolve domain names
InetHostInfo hostInfo; // Holds info returned by OTInternetServices
if(inetSvc == nil) {
#if !CARBON
inetSvc = OTOpenInternetServices(kDefaultInternetServicesPath,
NULL, &err);
#else
inetSvc =
OTOpenInternetServicesInContext(kDefaultInternetServicesPath, NULL, &err,
gOTContext);
#endif
}
if( inetSvc == nil || err != kOTNoError ||
address == nil || host == nil )
{
DEBUGMSG(" OpenInternetServices failed\n");
*host = 0;
return false;
}
err = OTInetStringToAddress(inetSvc, address, &hostInfo);
if( err != kOTNoError ) {
DEBUGMSG(" OTInetStringToAddress failed\n");
*host = 0;
return false;
}
*host = hostInfo.addrs[0];
return true;
}
thanks for any insight..
Yours cheerfully,
Andrew Bush
The word for a society where everyone is pulling together is 'Tyranny', in
a free country everyone tends to pull in different directions.
_______________________________________________
macnetworkprog mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/macnetworkprog
Do not post admin requests to the list. They will be ignored.