mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-31 00:30:53 +00:00
more mingw32 updates
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@21951 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
8f93eac56a
commit
9d64352859
10 changed files with 955 additions and 297 deletions
|
@ -49,7 +49,6 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#if !defined(__MINGW32__)
|
||||
#ifdef HAVE_UNISTD_H
|
||||
#include <unistd.h> /* for gethostname() */
|
||||
#endif
|
||||
|
@ -90,7 +89,6 @@
|
|||
#if defined(__svr4__)
|
||||
#include <sys/stropts.h>
|
||||
#endif
|
||||
#endif /* !__MINGW32__ */
|
||||
|
||||
/*
|
||||
* Largest chunk of data possible in DO
|
||||
|
@ -192,9 +190,6 @@ newDataWithEncodedPort(NSMessagePort *port)
|
|||
return data;
|
||||
}
|
||||
|
||||
|
||||
#if !defined(__MINGW32__)
|
||||
|
||||
/* Older systems (Solaris) compatibility */
|
||||
#ifndef AF_LOCAL
|
||||
#define AF_LOCAL AF_UNIX
|
||||
|
@ -1962,290 +1957,3 @@ static unsigned wordAlign;
|
|||
|
||||
@end
|
||||
|
||||
#else
|
||||
|
||||
@implementation NSMessagePort
|
||||
|
||||
static NSRecursiveLock *messagePortLock = nil;
|
||||
|
||||
/*
|
||||
* Maps port name to NSMessagePort objects.
|
||||
*/
|
||||
static NSMapTable *messagePortMap = 0;
|
||||
static Class messagePortClass;
|
||||
|
||||
typedef struct {
|
||||
NSString *_name;
|
||||
NSRecursiveLock *_lock;
|
||||
HANDLE *_handle;
|
||||
} internal;
|
||||
#define myName(P) ((internal*)(P)->_internal)->_name
|
||||
#define myLock(P) ((internal*)(P)->_internal)->_lock
|
||||
#define myHandle(P) ((internal*)(P)->_internal)->_handle
|
||||
|
||||
#if NEED_WORD_ALIGNMENT
|
||||
static unsigned wordAlign;
|
||||
#endif
|
||||
|
||||
+ (void) initialize
|
||||
{
|
||||
if (self == [NSMessagePort class])
|
||||
{
|
||||
#if NEED_WORD_ALIGNMENT
|
||||
wordAlign = objc_alignof_type(@encode(gsu32));
|
||||
#endif
|
||||
messagePortClass = self;
|
||||
messagePortMap = NSCreateMapTable(NSNonRetainedObjectMapKeyCallBacks,
|
||||
NSNonOwnedPointerMapValueCallBacks, 0);
|
||||
|
||||
messagePortLock = [GSLazyRecursiveLock new];
|
||||
}
|
||||
}
|
||||
|
||||
+ (id) new
|
||||
{
|
||||
static int unique_index = 0;
|
||||
unsigned char path[BUFSIZ];
|
||||
|
||||
M_LOCK(messagePortLock);
|
||||
sprintf(path, "\\\\.\\mailslot\\NSMessagePort\\%i.%i",
|
||||
[[NSProcessInfo processInfo] processIdentifier], unique_index++);
|
||||
M_UNLOCK(messagePortLock);
|
||||
|
||||
return RETAIN([self _portWithName: path listener: YES]);
|
||||
}
|
||||
|
||||
/*
|
||||
* This is the preferred initialisation method for NSMessagePort
|
||||
*
|
||||
* 'mailslotName' is the name of the mailslot to use.
|
||||
*/
|
||||
+ (NSMessagePort*) _portWithName: (const unsigned char*)mailslotName
|
||||
listener: (BOOL)shouldListen
|
||||
{
|
||||
NSMessagePort *port = nil;
|
||||
|
||||
M_LOCK(messagePortLock);
|
||||
|
||||
/*
|
||||
* First try to find a pre-existing port.
|
||||
*/
|
||||
port = (NSMessagePort*)NSMapGet(messagePortMap, mailslotName);
|
||||
|
||||
if (port == nil)
|
||||
{
|
||||
port = (NSMessagePort*)NSAllocateObject(self, 0, NSDefaultMallocZone());
|
||||
myName(port) = [[NSString alloc] initWithUTF8String: mailslotName];
|
||||
myHandle(port) = INVALID_HANDLE_VALUE;
|
||||
myLock(port) = [GSLazyRecursiveLock new];
|
||||
port->_is_valid = YES;
|
||||
|
||||
if (shouldListen == YES)
|
||||
{
|
||||
myHandle(port) = CreateMailslot([myName(port) UTF8String], 0, 0, 0);
|
||||
if (myHandle(port) == INVALID_HANDLE_VALUE)
|
||||
{
|
||||
NSLog(@"unable to create mailslot - %s", GSLastErrorStr(errno));
|
||||
DESTROY(port);
|
||||
}
|
||||
else
|
||||
{
|
||||
/*
|
||||
* Make sure we have the map table for this port.
|
||||
*/
|
||||
NSMapInsert(messagePortMap, (void*)myName(port), (void*)port);
|
||||
NSDebugMLLog(@"NSMessagePort", @"Created listening port: %@",
|
||||
port);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/*
|
||||
* Make sure we have the map table for this port.
|
||||
*/
|
||||
NSMapInsert(messagePortMap, (void*)myName(port), (void*)port);
|
||||
NSDebugMLLog(@"NSMessagePort", @"Created speaking port: %@", port);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
RETAIN(port);
|
||||
NSDebugMLLog(@"NSMessagePort", @"Using pre-existing port: %@", port);
|
||||
}
|
||||
IF_NO_GC(AUTORELEASE(port));
|
||||
|
||||
M_UNLOCK(messagePortLock);
|
||||
return port;
|
||||
}
|
||||
|
||||
- (id) copyWithZone: (NSZone*)zone
|
||||
{
|
||||
return RETAIN(self);
|
||||
}
|
||||
|
||||
- (void) dealloc
|
||||
{
|
||||
[self gcFinalize];
|
||||
DESTROY(myName(self));
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
- (NSString*) description
|
||||
{
|
||||
NSString *desc;
|
||||
|
||||
desc = [NSString stringWithFormat: @"<NSMessagePort %p with name %@>",
|
||||
self, myName(self)];
|
||||
return desc;
|
||||
}
|
||||
|
||||
- (void) gcFinalize
|
||||
{
|
||||
NSDebugMLLog(@"NSMessagePort", @"NSMessagePort 0x%x finalized", self);
|
||||
[self invalidate];
|
||||
}
|
||||
|
||||
- (id) conversation: (NSPort*)recvPort
|
||||
{
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (void) handlePortMessage: (NSPortMessage*)m
|
||||
{
|
||||
id d = [self delegate];
|
||||
|
||||
if (d == nil)
|
||||
{
|
||||
NSDebugMLLog(@"NSMessagePort",
|
||||
@"No delegate to handle incoming message", 0);
|
||||
return;
|
||||
}
|
||||
if ([d respondsToSelector: @selector(handlePortMessage:)] == NO)
|
||||
{
|
||||
NSDebugMLLog(@"NSMessagePort", @"delegate doesn't handle messages", 0);
|
||||
return;
|
||||
}
|
||||
[d handlePortMessage: m];
|
||||
}
|
||||
|
||||
- (unsigned) hash
|
||||
{
|
||||
return [myName(self) hash];
|
||||
}
|
||||
|
||||
- (id) init
|
||||
{
|
||||
RELEASE(self);
|
||||
self = [messagePortClass new];
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void) invalidate
|
||||
{
|
||||
if ([self isValid] == YES)
|
||||
{
|
||||
M_LOCK(myLock(self));
|
||||
if ([self isValid] == YES)
|
||||
{
|
||||
M_LOCK(messagePortLock);
|
||||
if (myHandle(self) != INVALID_HANDLE_VALUE)
|
||||
{
|
||||
(void) CloseHandle(myHandle(self));
|
||||
myHandle(self) = INVALID_HANDLE_VALUE;
|
||||
}
|
||||
NSMapRemove(messagePortMap, (void*)myName(self));
|
||||
M_UNLOCK(messagePortLock);
|
||||
|
||||
[[NSMessagePortNameServer sharedInstance] removePort: self];
|
||||
[super invalidate];
|
||||
}
|
||||
M_UNLOCK(myLock(self));
|
||||
}
|
||||
}
|
||||
|
||||
- (BOOL) isEqual: (id)anObject
|
||||
{
|
||||
if (anObject == self)
|
||||
{
|
||||
return YES;
|
||||
}
|
||||
if ([anObject class] == [self class])
|
||||
{
|
||||
NSMessagePort *o = (NSMessagePort*)anObject;
|
||||
|
||||
return [myName(o) isEqual: myName(self)];
|
||||
}
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (void) receivedEvent: (void*)data
|
||||
type: (RunLoopEventType)type
|
||||
extra: (void*)extra
|
||||
forMode: (NSString*)mode
|
||||
{
|
||||
HANDLE h = (HANDLE)(gsaddr)extra;
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* This returns the amount of space that a port coder should reserve at the
|
||||
* start of its encoded data so that the NSMessagePort can insert header info
|
||||
* into the data.
|
||||
* The idea is that a message consisting of a single data item with space at
|
||||
* the start can be written directly without having to copy data to another
|
||||
* buffer etc.
|
||||
*/
|
||||
- (unsigned int) reservedSpaceLength
|
||||
{
|
||||
return sizeof(GSPortItemHeader) + sizeof(GSPortMsgHeader);
|
||||
}
|
||||
|
||||
- (BOOL) sendBeforeDate: (NSDate*)when
|
||||
msgid: (int)msgId
|
||||
components: (NSMutableArray*)components
|
||||
from: (NSPort*)receivingPort
|
||||
reserved: (unsigned)length
|
||||
{
|
||||
BOOL sent = NO;
|
||||
unsigned rl;
|
||||
|
||||
if ([self isValid] == NO)
|
||||
{
|
||||
return NO;
|
||||
}
|
||||
if ([components count] == 0)
|
||||
{
|
||||
NSLog(@"empty components sent");
|
||||
return NO;
|
||||
}
|
||||
/*
|
||||
* If the reserved length in the first data object is wrong - we have to
|
||||
* fail, unless it's zero, in which case we can insert a data object for
|
||||
* the header.
|
||||
*/
|
||||
rl = [self reservedSpaceLength];
|
||||
if (length != 0 && length != rl)
|
||||
{
|
||||
NSLog(@"bad reserved length - %u", length);
|
||||
return NO;
|
||||
}
|
||||
if ([receivingPort isKindOfClass: messagePortClass] == NO)
|
||||
{
|
||||
NSLog(@"woah there - receiving port is not the correct type");
|
||||
return NO;
|
||||
}
|
||||
|
||||
return sent;
|
||||
}
|
||||
|
||||
- (NSDate*) timedOutEvent: (void*)data
|
||||
type: (RunLoopEventType)type
|
||||
forMode: (NSString*)mode
|
||||
{
|
||||
return nil;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
#endif /* __MINGW32__ */
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue