2 Copyright (C) 2000-2005 SKYRIX Software AG
4 This file is part of SOPE.
6 SOPE is free software; you can redistribute it and/or modify it under
7 the terms of the GNU Lesser General Public License as published by the
8 Free Software Foundation; either version 2, or (at your option) any
11 SOPE is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
14 License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with SOPE; see the file COPYING. If not, write to the
18 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
24 #include "NGLocalSocketDomain.h"
25 #include "NGLocalSocketAddress.h"
28 #if defined(__APPLE__) || defined(__FreeBSD__)
29 # include <sys/types.h>
30 # include <sys/socket.h>
37 @implementation NGLocalSocketDomain
39 static NGLocalSocketDomain *domain = nil;
42 BOOL isInitialized = NO;
45 [NGSocket initialize];
46 domain = [[NGLocalSocketDomain alloc] init];
56 - (id<NGSocketAddress>)addressWithRepresentation:(void *)_data
57 size:(unsigned int)_size
59 NGLocalSocketAddress *address = nil;
61 address = [[NGLocalSocketAddress alloc] initWithDomain:self
62 internalRepresentation:_data
64 return AUTORELEASE(address);
67 - (BOOL)prepareAddress:(id<NGSocketAddress>)_address
68 forBindWithSocket:(id<NGSocket>)_socket
70 if ([_socket conformsToProtocol:@protocol(NGPassiveSocket)]) {
71 NSString *path = [(NGLocalSocketAddress *)_address path];
74 [[NSFileManager defaultManager] removeFileAtPath:path handler:nil];
78 - (BOOL)cleanupAddress:(id<NGSocketAddress>)_address
79 afterCloseOfSocket:(id<NGSocket>)_socket
81 if ([_socket conformsToProtocol:@protocol(NGPassiveSocket)]) {
83 NSString *path = [(NGLocalSocketAddress *)_address path];
86 [[NSFileManager defaultManager] removeFileAtPath:path handler:nil];
96 - (int)addressRepresentationSize { // maximum size
97 return sizeof(struct sockaddr_un);
106 - (id)copyWithZone:(NSZone *)_zone {
107 /* domains are immutable, just return self on copy .. */
108 return [self retain];
113 - (void)encodeWithCoder:(NSCoder *)_encoder {
115 - (id)initWithCoder:(NSCoder *)_decoder {
116 [self release]; self = nil;
117 return [domain retain]; /* replace with singleton */
120 - (id)awakeAfterUsingCoder:(NSCoder *)_decoder {
121 if (self != domain) {
122 [self release]; self = nil;
123 return [domain retain]; /* replace with singleton */
131 - (NSString *)description {
132 return [NSString stringWithFormat:
133 @"<UnixDomain: self=0x%08X>", (unsigned)self];
136 @end /* NGLocalSocketDomain */