X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/79da30927621c8ab01ff9e9a834331b922e7fbd1..b635e17fef75d05881f5b5db85ec5f21d1cb3750:/src/mac/carbon/gsocket.c diff --git a/src/mac/carbon/gsocket.c b/src/mac/carbon/gsocket.c index 5411425556..9e3ba3079a 100644 --- a/src/mac/carbon/gsocket.c +++ b/src/mac/carbon/gsocket.c @@ -15,6 +15,7 @@ #ifndef __GSOCKET_STANDALONE__ #include "wx/setup.h" +#include "wx/platform.h" #endif #if wxUSE_SOCKETS || defined(__GSOCKET_STANDALONE__) @@ -29,12 +30,13 @@ #define TRUE 1 #endif #else + #include #define OTUNIXERRORS 1 #include #include #include #endif -#if TARGET_CARBON +#if TARGET_CARBON && !defined(OTAssert) #define OTAssert( str , cond ) /* does not exists in Carbon */ #endif @@ -84,7 +86,8 @@ extern pascal void OTDebugStr(const char* str); #include #endif InetSvcRef gInetSvcRef = 0 ; - +int gOTInited = 0 ; +OTNotifyUPP gOTNotifierUPP = NULL ; OSStatus DoNegotiateIPReuseAddrOption(EndpointRef ep, Boolean enableReuseIPMode); @@ -183,7 +186,7 @@ static void SetDefaultEndpointModes(EndpointRef ep , void *data ) junk = OTSetBlocking(ep); OTAssert("SetDefaultEndpointModes: Could not set blocking", junk == noErr); */ - junk = OTInstallNotifier(ep, OTInetEventHandler, data); + junk = OTInstallNotifier(ep, gOTNotifierUPP, data); OTAssert("SetDefaultEndpointModes: Could not install notifier", junk == noErr); /* junk = OTUseSyncIdleEvents(ep, true); @@ -193,6 +196,11 @@ static void SetDefaultEndpointModes(EndpointRef ep , void *data ) /* Global initialisers */ +void GSocket_SetGUIFunctions(struct GSocketGUIFunctionsTable *table) +{ + // do nothing, wxMac doesn't have wxBase-GUI separation yet +} + int GSocket_Init() { return TRUE; @@ -211,6 +219,7 @@ int GSocket_Verify_Inited() return TRUE ; InitOpenTransportInContext(kInitOTForApplicationMask, &clientcontext); + gOTInited = 1 ; gInetSvcRef = OTOpenInternetServicesInContext(kDefaultInternetServicesPath, NULL, &err, clientcontext); #else @@ -218,6 +227,7 @@ int GSocket_Verify_Inited() return TRUE ; InitOpenTransport() ; + gOTInited = 1 ; gInetSvcRef = OTOpenInternetServices(kDefaultInternetServicesPath, NULL, &err); #endif if ( gInetSvcRef == NULL || err != kOTNoError ) @@ -225,18 +235,24 @@ int GSocket_Verify_Inited() OTAssert("Could not open Inet Services", err == noErr); return FALSE ; } + gOTNotifierUPP = NewOTNotifyUPP( OTInetEventHandler ) ; return TRUE ; } void GSocket_Cleanup() { - if ( gInetSvcRef != NULL ) - OTCloseProvider( gInetSvcRef ); -#if TARGET_CARBON - CloseOpenTransportInContext( NULL ) ; -#else - CloseOpenTransport() ; -#endif + if ( gOTInited != 0 ) + { + if ( gInetSvcRef != NULL ) + OTCloseProvider( gInetSvcRef ); + #if TARGET_CARBON + CloseOpenTransportInContext( NULL ) ; + #else + CloseOpenTransport() ; + #endif + if ( gOTNotifierUPP ) + DisposeOTNotifyUPP( gOTNotifierUPP ) ; + } } /* Constructors / Destructors for GSocket */ @@ -267,7 +283,7 @@ GSocket *GSocket_new() socket->m_server = FALSE; socket->m_stream = TRUE; socket->m_non_blocking = FALSE; - socket->m_timeout = 10*1000; + socket->m_timeout = 1*1000; /* 10 sec * 1000 millisec */ socket->m_takesEvents = TRUE ; socket->m_mac_events = wxMacGetNotifierTable() ; @@ -466,9 +482,6 @@ GAddress *GSocket_GetPeer(GSocket *socket) */ GSocketError GSocket_SetServer(GSocket *sck) { - int type; - int arg = 1; - assert(sck != NULL); /* must not be in use */ @@ -538,9 +551,6 @@ GSocketError GSocket_SetServer(GSocket *sck) GSocket *GSocket_WaitConnection(GSocket *socket) { GSocket *connection = NULL ; - GSocketError err; - - int arg = 1; assert(socket != NULL); @@ -633,8 +643,6 @@ GSocket *GSocket_WaitConnection(GSocket *socket) */ GSocketError GSocket_SetNonOriented(GSocket *sck) { - int arg = 1; - assert(sck != NULL); if (sck->m_endpoint != kOTInvalidEndpointRef ) @@ -719,12 +727,9 @@ GSocketError GSocket_SetNonOriented(GSocket *sck) */ GSocketError GSocket_Connect(GSocket *sck, GSocketStream stream) { - int ret; - int arg = 1; InetAddress addr ; TEndpointInfo info; - OTFlags flags = 0; - OSStatus err = kOTNoError; + OSStatus err = kOTNoError; TCall peer ; assert(sck != NULL); @@ -925,7 +930,6 @@ int GSocket_Write(GSocket *socket, const char *buffer, int size) */ GSocketEventFlags GSocket_Select(GSocket *socket, GSocketEventFlags flags) { - OTResult state ; assert(socket != NULL); wxMacProcessNotifierEvents() ; /* @@ -1072,7 +1076,7 @@ int _GSocket_Recv_Stream(GSocket *socket, char *buffer, int size) OTByteCount sz = 0 ; OTCountDataBytes( socket->m_endpoint , &sz ) ; - if ( size > sz ) + if ( size > (int)sz ) size = sz ; res = OTRcv( socket->m_endpoint , buffer , size , &flags ) ; if ( res < 0 ) @@ -1320,8 +1324,6 @@ GSocketError GAddress_INET_SetAnyAddress(GAddress *address) GSocketError GAddress_INET_SetHostAddress(GAddress *address, unsigned long hostaddr) { - struct in_addr *addr; - assert(address != NULL); CHECK_ADDRESS(address, INET, GSOCK_INVADDR); @@ -1347,8 +1349,7 @@ service_entry gServices[] = GSocketError GAddress_INET_SetPortName(GAddress *address, const char *port, const char *protocol) { - InetAddress *addr; - int i ; + size_t i ; assert(address != NULL); CHECK_ADDRESS(address, INET, GSOCK_INVADDR); @@ -1382,8 +1383,6 @@ GSocketError GAddress_INET_SetPortName(GAddress *address, const char *port, GSocketError GAddress_INET_SetPort(GAddress *address, unsigned short port) { - InetAddress *addr; - assert(address != NULL); CHECK_ADDRESS(address, INET, GSOCK_INVADDR); address->m_port = port ; @@ -1473,7 +1472,7 @@ GSocketError _GSocket_Input_Timeout(GSocket *socket) { OTResult state ; OTByteCount sz = 0 ; - state = OTGetEndpointState(socket->m_endpoint); + state = OTGetEndpointState(socket->m_endpoint); OTCountDataBytes( socket->m_endpoint , &sz ) ; if ( state == T_INCON || sz > 0 ) @@ -1643,10 +1642,12 @@ void _GSocket_Internal_Proc(unsigned long e , void* d ) /* Hack added for Mac OS X */ GSocketError GAddress_UNIX_GetPath(GAddress *addr, char *path, size_t buf) { + return GSOCK_INVADDR; } GSocketError GAddress_UNIX_SetPath(GAddress *addr, const char *path) { + return GSOCK_INVADDR; } #endif /* wxUSE_SOCKETS || defined(__GSOCKET_STANDALONE__) */