]> err.no Git - sope/blob - sope-core/NGStreams/NGSocketExceptions.m
added a new mkdirs like method to NSFileManager
[sope] / sope-core / NGStreams / NGSocketExceptions.m
1 /*
2   Copyright (C) 2000-2003 SKYRIX Software AG
3
4   This file is part of OGo
5
6   OGo 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
9   later version.
10
11   OGo 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.
15
16   You should have received a copy of the GNU Lesser General Public
17   License along with OGo; see the file COPYING.  If not, write to the
18   Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
19   02111-1307, USA.
20 */
21 // $Id$
22
23 #import <Foundation/Foundation.h>
24 #import <NGExtensions/NGExtensions.h>
25 #import <NGExtensions/NSException+misc.h>
26 #include "NGSocketExceptions.h"
27
28 @implementation NGSocketException
29
30 - (id)init {
31   return [self initWithReason:@"a socket exception occured" socket:nil];
32 }
33 - (id)initWithReason:(NSString *)_reason {
34   return [self initWithReason:_reason socket:nil];
35 }
36
37 - (id)initWithReason:(NSString *)_reason socket:(id<NGSocket>)_socket {
38   self = [super initWithName:NSStringFromClass([self class])
39                 reason:_reason
40                 userInfo:nil];
41   if (self) {
42     self->socket = [_socket retain];
43   }
44   return self;
45 }
46
47 - (void)dealloc {
48   [self->socket release];
49   [super dealloc];
50 }
51
52 - (id<NGSocket>)socket {
53   return self->socket;
54 }
55
56 @end /* NGSocketException */
57
58 @implementation NGCouldNotResolveHostNameException
59
60 - (id)init {
61   return [self initWithHostName:@"<noname>" reason:nil];
62 }
63
64 - (id)initWithHostName:(NSString *)_name reason:(NSString *)_reason {
65   self = [super initWithReason:
66                   [NSString stringWithFormat:
67                               @"Could not resolve host %@: %@",
68                             _name, _reason ? _reason : @"error"]
69                 socket:nil];
70   if (self) {
71     self->hostName = [_name copy];
72   }
73   return self;
74 }
75
76 - (void)dealloc {
77   [self->hostName  release];
78   [super dealloc];
79 }
80
81 /* accessors */
82
83 - (NSString *)hostName {
84   return self->hostName;
85 }
86
87 @end /* NGCouldNotResolveHostNameException */
88
89 @implementation NGDidNotFindServiceException
90
91 - (id)init {
92   return [self initWithServiceName:nil];
93 }
94 - (id)initWithServiceName:(NSString *)_service {
95   self = [super initWithReason:
96                   [NSString stringWithFormat:@"did not find service %@", _service]
97                 socket:nil];
98   if (self) {
99     self->serviceName = [_service copy];
100   }
101   return self;
102 }
103
104 - (void)dealloc {
105   [self->serviceName release];
106   [super dealloc];
107 }
108
109 - (NSString *)serviceName {
110   return self->serviceName;
111 }
112
113 @end /* NGDidNotFindServiceException */
114
115 @implementation NGInvalidSocketDomainException
116
117 - (id)initWithReason:(NSString *)_reason
118   socket:(id<NGSocket>)_socket
119   domain:(id<NGSocketDomain>)_domain {
120
121   if ((self = [super initWithReason:_reason socket:nil])) {
122     self->domain = [_domain retain];
123   }
124   return self;
125 }
126
127 - (void)dealloc {
128   [self->domain release];
129   [super dealloc];
130 }
131
132 - (id<NGSocketDomain>)domain {
133   return self->domain;
134 }
135
136 @end /* NGInvalidSocketDomainException */
137
138 @implementation NGCouldNotCreateSocketException
139
140 - (id)init {
141   return [self initWithReason:@"Could not create socket" domain:nil];
142 }
143 - (id)initWithReason:(NSString *)_reason domain:(id<NGSocketDomain>)_domain {
144   if ((self = [super initWithReason:_reason socket:nil])) {
145     self->domain = [_domain retain];
146   }
147   return self;
148 }
149
150 - (void)dealloc {
151   [self->domain release];
152   [super dealloc];
153 }
154
155 - (id<NGSocketDomain>)domain {
156   return self->domain;
157 }
158
159 @end /* NGCouldNotCreateSocketException */
160
161 // ******************** bind ***********************
162
163 @implementation NGSocketBindException
164 @end /* NGSocketBindException */
165
166 @implementation NGSocketAlreadyBoundException
167
168 - (id)init {
169   return [self initWithReason:@"Socket is already bound"];
170 }
171
172 @end /* NGSocketAlreadyBoundException */
173
174 @implementation NGCouldNotBindSocketException
175
176 - (id)init {
177   return [self initWithReason:@"could not bind socket" socket:nil address:nil];
178 }
179
180 - (id)initWithReason:(NSString *)_reason
181   socket:(id<NGSocket>)_socket
182   address:(id<NGSocketAddress>)_address {
183
184   if ((self = [super initWithReason:_reason socket:_socket])) {
185     self->address = [_address retain];
186   }
187   return self;
188 }
189
190 - (void)dealloc {
191   [self->address release];
192   [super dealloc];
193 }
194
195 - (id<NGSocketAddress>)address {
196   return self->address;
197 }
198
199 @end /* NGCouldNotBindSocketException */
200
201 // ******************** connect ********************
202
203 @implementation NGSocketConnectException
204 @end /* NGSocketConnectException */
205
206 @implementation NGSocketNotConnectedException
207
208 - (id)init {
209   return [self initWithReason:@"Socket is not connected"];
210 }
211
212 @end /* NGSocketNotConnectedException */
213
214 @implementation NGSocketAlreadyConnectedException
215
216 - (id)init {
217   return [self initWithReason:@"Socket is already connected"];
218 }
219
220 @end /* NGSocketAlreadyConnectedException */
221
222 @implementation NGCouldNotConnectException
223
224 - (id)init {
225   return [self initWithReason:@"could not connect socket" socket:nil address:nil];
226 }
227
228 - (id)initWithReason:(NSString *)_reason
229   socket:(id<NGActiveSocket>)_socket
230   address:(id<NGSocketAddress>)_address {
231
232   if ((self = [super initWithReason:_reason socket:_socket])) {
233     self->address = [_address retain];
234   }
235   return self;
236 }
237
238 - (void)dealloc {
239   [self->address release];
240   [super dealloc];
241 }
242
243 - (id<NGSocketAddress>)address {
244   return self->address;
245 }
246
247 @end /* NGCouldNotConnectException */
248
249 // ******************** listen ********************
250
251 @implementation NGSocketIsAlreadyListeningException
252
253 - (id)init {
254   return [self initWithReason:@"Socket is already listening"];
255 }
256
257 @end /* NGSocketIsAlreadyListeningException */
258
259 @implementation NGCouldNotListenException
260 @end /* NGCouldNotListenException */
261
262 // ******************** accept ********************
263
264 @implementation NGCouldNotAcceptException
265 @end /* NGCouldNotAcceptException */
266
267 // ******************** options ********************
268
269 @implementation NGSocketOptionException
270
271 - (id)init {
272   return [self initWithReason:@"Could not get/set socket option" option:-1 level:-1];
273 }
274 - (id)initWithReason:(NSString *)_reason option:(int)_option level:(int)_level {
275   if ((self = [super initWithReason:_reason])) {
276     option = _option;
277     level  = _level;
278   }
279   return self;
280 }
281
282 - (int)option {
283   return option;
284 }
285 - (int)level {
286   return level;
287 }
288
289 @end /* NGSocketOptionException */
290
291 @implementation NGCouldNotSetSocketOptionException
292 @end /* NGCouldNotSetSocketOptionException */
293
294 @implementation NGCouldNotGetSocketOptionException
295 @end /* NGCouldNotGetSocketOptionException */
296
297 // ******************** socket closed **************
298
299 @implementation NGSocketShutdownException
300
301 - (id)init {
302   return [self initWithStream:nil reason:@"the socket was shutdown"];
303 }
304 - (id)initWithReason:(NSString *)_reason {
305   return [self initWithStream:nil reason:_reason];
306 }
307 - (id)initWithReason:(NSString *)_reason socket:(id<NGActiveSocket>)_socket {
308   return [self initWithStream:_socket reason:_reason];
309 }
310
311 - (id)initWithSocket:(id<NGActiveSocket>)_socket {
312   return [self initWithStream:_socket reason:@"the socket was shutdown"];
313 }
314
315 /* accessors */
316
317 - (id<NGActiveSocket>)socket {
318   return [self->streamPointer nonretainedObjectValue];
319 }
320
321 @end /* NGSocketShutdownException */
322
323 @implementation NGSocketShutdownDuringReadException
324 @end
325
326 @implementation NGSocketShutdownDuringWriteException
327 @end
328
329 @implementation NGSocketTimedOutException
330 @end
331
332 @implementation NGSocketConnectionResetException
333 @end