Ejemplo n.º 1
0
Archivo: gsocket.c Proyecto: EdgarTx/wx
int GSocket_Verify_Inited()
{
    OSStatus err ;
#if TARGET_CARBON
    // Marc Newsam: added the clientcontext variable
    //              however, documentation is unclear how this works
    OTClientContextPtr clientcontext;

    if ( gInetSvcRef )
      return TRUE ;

    InitOpenTransportInContext(kInitOTForApplicationMask, &clientcontext);
    gOTInited = 1 ;
    gInetSvcRef = OTOpenInternetServicesInContext(kDefaultInternetServicesPath,
						NULL, &err, clientcontext);
#else	
    if ( gInetSvcRef )
      return TRUE ;

    InitOpenTransport() ;
    gOTInited = 1 ;
    gInetSvcRef = OTOpenInternetServices(kDefaultInternetServicesPath, NULL, &err);
#endif
    if ( gInetSvcRef == NULL ||  err != kOTNoError )
    {
	OTAssert("Could not open Inet Services", err == noErr);
	return FALSE ;
    }
    gOTNotifierUPP = NewOTNotifyUPP( OTInetEventHandler ) ;
    return TRUE ;
}
Ejemplo n.º 2
0
static Boolean
OpenInetServices(SvcInfo *svcInfo)
{
  OSStatus result;

  svcInfo->done=false;
  if (!svcnotifyproc) svcnotifyproc=NewOTNotifyUPP(&SvcNotifyProc);
#ifdef __CARBON__
  
  result=OTAsyncOpenInternetServicesInContext(kDefaultInternetServicesPath, 0,
					      svcnotifyproc, svcInfo, NULL);
#else
  result=OTAsyncOpenInternetServices(kDefaultInternetServicesPath, 0,
				     svcnotifyproc, svcInfo);
#endif
  if (!result) {
    do {
      MacIdle();
    } while (!svcInfo->done);
    result=svcInfo->result;
  }
  if (result) return(false);
  svcInfo->ref=(InetSvcRef)svcInfo->cookie;
  return(true);
}
Ejemplo n.º 3
0
OSStatus ot_DNRInit(void)
{
	OSStatus theError = kOTNoError;

	// First, check to see if we've already initialized.  If so, then just return...
	if( gDNRep != kOTInvalidProviderRef){
		return (kOTNoError);
	}

	// Next, check to see if any OT service has been used yet
	if (!gOTInited){
		theError = ot_OpenDriver();
	}

	// Get the internet services reference for DNS
	if( theError == kOTNoError){
#if TARGET_API_MAC_CARBON
		gDNRep = OTOpenInternetServicesInContext( kDefaultInternetServicesPath, 0, &theError, NULL);
#else
		gDNRep = OTOpenInternetServices( kDefaultInternetServicesPath, 0, &theError);
#endif
	}

	/* We have to choose to be synchronous or async, sync is simpler but
	 *	I think that async could be done in the future
	 */
	if( theError == kOTNoError){
		theError = OTSetSynchronous( gDNRep);
	}

	// Give OT a pointer to a notifier function that handles async events
	if( theError == kOTNoError){
		gDNRYieldNotifyUPP = NewOTNotifyUPP(DNRYieldNotifier);
		theError = OTInstallNotifier(gDNRep, gDNRYieldNotifyUPP, nil);
	}

	/* If we get idle events, then implementing a multi-threaded app shouldn't
	 *	be any big deal
	 */
	if( theError == kOTNoError){
		theError = OTUseSyncIdleEvents(gDNRep, true);
	}
	return( theError);
}
Ejemplo n.º 4
0
void *otudp_new(Symbol *s, short argc, Atom *argv) {
	OTUDP *x;
	OSStatus err;
	InetHost host;
	
	// These variables will be filled with the args we parse
	int writer;
	char *inetHostName = 0;
	InetPort port = 0;
	InetPort receivePort = 0;
	long nbufs = DEFAULT_NUM_BUFFERS;
	long bufsize = DEFAULT_BUFFER_SIZE;

		
	if (ParseArgs(argc, argv, &writer, &inetHostName, &port, &receivePort, &nbufs, &bufsize) == 0) {
		error("¥ OTUDP usage: \"otudp read <port> [bufsize <nbytes>] [nbufs <n>]\" or "
				   "\"otudp write <hostname> <port> [bufsize <nbytes>] [nbufs <n>]\"");
		return 0;
	}
	
	if (writer) {
		if (LookUpInetHost(inetHostName, &host) == 0) {
			error("otudp: Couldn't make sense of Internet host \"%s\"", inetHostName);
			return 0;
		}
	}
	
	x = newobject(otudp_class);
/*	x->o_a5 = (long) LMGetCurrentA5(); */
	x->o_writer = writer;
	x->o_inetHostName = inetHostName;
	x->o_inetPort = port;
	x->o_inetHost = host;
	x->o_receiveInetPort = receivePort;
	x->o_desiredNewHostName = 0;
	x->o_desiredNewPort = 0;

	x->o_ready = 0;
	x->o_errorreporting = 1;
	x->o_ever_dropped_a_packet = 0;
	x->o_num_dropped_packets = 0;
	x->o_outlet = outlet_new(x,0L);
	x->o_clock = clock_new(x, (method) otudp_output);
	InitPBFIFO(&(x->pendingBuffers));
	
	x->o_complained_about_old_msgs = 0;
	
	OTClearLock(&(x->o_readlock));
	x->o_semaphoreTest = x->o_semaphoreTestFailureCount = 0;
	
	/* Allocate packet buffers */
	x->bufsize = bufsize;
	x->nbufs = nbufs;
	if (nbufs == 0) {
		x->allBuffers = x->freeBuffers = 0; 
	} else {
		x->allBuffers = InitPackets(bufsize, nbufs);
		if (x->allBuffers == 0) {
			error("¥ OTUDP: Out of memory (Couldn't allocate buffers to store incoming packets)");
			return 0;
		}

		x->freeBuffers = x->allBuffers;
	}
	
	x->o_udp_ep = 0; 	// Indicates endpoint hasn't been created yet.
	err = OTAsyncOpenEndpointInContext(OTCreateConfiguration(kUDPName), 0, &(x->epinfo), 
									   NewOTNotifyUPP(OTUDPNotifier), x, OTContext);
	if (err != noErr) {
		error("¥ otudp: Error %d from OTAsyncOpenEndpoint. This is bad.", err);
		return 0;
	}
	// This didn't actually make the endpoint; my notifier should get the T_OPENCOMPLETE
	// event after the endpoint is opened.
	
	/* Create a Qelem that will let us change the host at non-interrupt, non-defered-task-time level */
	x->UnbindQelem = qelem_new(x, (method)unbind_from_qelem);

	return (x);
}