2 Copyright (C) 2000-2003 SKYRIX Software AG
4 This file is part of OGo
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
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.
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
23 #import <Foundation/Foundation.h>
24 #import <NGExtensions/NGExtensions.h>
25 #import <NGExtensions/NSException+misc.h>
26 #include "NGSocketExceptions.h"
28 @implementation NGSocketException
31 return [self initWithReason:@"a socket exception occured" socket:nil];
33 - (id)initWithReason:(NSString *)_reason {
34 return [self initWithReason:_reason socket:nil];
37 - (id)initWithReason:(NSString *)_reason socket:(id<NGSocket>)_socket {
38 self = [super initWithName:NSStringFromClass([self class])
42 self->socket = [_socket retain];
48 [self->socket release];
52 - (id<NGSocket>)socket {
56 @end /* NGSocketException */
58 @implementation NGCouldNotResolveHostNameException
61 return [self initWithHostName:@"<noname>" reason:nil];
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"]
71 self->hostName = [_name copy];
77 [self->hostName release];
83 - (NSString *)hostName {
84 return self->hostName;
87 @end /* NGCouldNotResolveHostNameException */
89 @implementation NGDidNotFindServiceException
92 return [self initWithServiceName:nil];
94 - (id)initWithServiceName:(NSString *)_service {
95 self = [super initWithReason:
96 [NSString stringWithFormat:@"did not find service %@", _service]
99 self->serviceName = [_service copy];
105 [self->serviceName release];
109 - (NSString *)serviceName {
110 return self->serviceName;
113 @end /* NGDidNotFindServiceException */
115 @implementation NGInvalidSocketDomainException
117 - (id)initWithReason:(NSString *)_reason
118 socket:(id<NGSocket>)_socket
119 domain:(id<NGSocketDomain>)_domain {
121 if ((self = [super initWithReason:_reason socket:nil])) {
122 self->domain = [_domain retain];
128 [self->domain release];
132 - (id<NGSocketDomain>)domain {
136 @end /* NGInvalidSocketDomainException */
138 @implementation NGCouldNotCreateSocketException
141 return [self initWithReason:@"Could not create socket" domain:nil];
143 - (id)initWithReason:(NSString *)_reason domain:(id<NGSocketDomain>)_domain {
144 if ((self = [super initWithReason:_reason socket:nil])) {
145 self->domain = [_domain retain];
151 [self->domain release];
155 - (id<NGSocketDomain>)domain {
159 @end /* NGCouldNotCreateSocketException */
161 // ******************** bind ***********************
163 @implementation NGSocketBindException
164 @end /* NGSocketBindException */
166 @implementation NGSocketAlreadyBoundException
169 return [self initWithReason:@"Socket is already bound"];
172 @end /* NGSocketAlreadyBoundException */
174 @implementation NGCouldNotBindSocketException
177 return [self initWithReason:@"could not bind socket" socket:nil address:nil];
180 - (id)initWithReason:(NSString *)_reason
181 socket:(id<NGSocket>)_socket
182 address:(id<NGSocketAddress>)_address {
184 if ((self = [super initWithReason:_reason socket:_socket])) {
185 self->address = [_address retain];
191 [self->address release];
195 - (id<NGSocketAddress>)address {
196 return self->address;
199 @end /* NGCouldNotBindSocketException */
201 // ******************** connect ********************
203 @implementation NGSocketConnectException
204 @end /* NGSocketConnectException */
206 @implementation NGSocketNotConnectedException
209 return [self initWithReason:@"Socket is not connected"];
212 @end /* NGSocketNotConnectedException */
214 @implementation NGSocketAlreadyConnectedException
217 return [self initWithReason:@"Socket is already connected"];
220 @end /* NGSocketAlreadyConnectedException */
222 @implementation NGCouldNotConnectException
225 return [self initWithReason:@"could not connect socket" socket:nil address:nil];
228 - (id)initWithReason:(NSString *)_reason
229 socket:(id<NGActiveSocket>)_socket
230 address:(id<NGSocketAddress>)_address {
232 if ((self = [super initWithReason:_reason socket:_socket])) {
233 self->address = [_address retain];
239 [self->address release];
243 - (id<NGSocketAddress>)address {
244 return self->address;
247 @end /* NGCouldNotConnectException */
249 // ******************** listen ********************
251 @implementation NGSocketIsAlreadyListeningException
254 return [self initWithReason:@"Socket is already listening"];
257 @end /* NGSocketIsAlreadyListeningException */
259 @implementation NGCouldNotListenException
260 @end /* NGCouldNotListenException */
262 // ******************** accept ********************
264 @implementation NGCouldNotAcceptException
265 @end /* NGCouldNotAcceptException */
267 // ******************** options ********************
269 @implementation NGSocketOptionException
272 return [self initWithReason:@"Could not get/set socket option" option:-1 level:-1];
274 - (id)initWithReason:(NSString *)_reason option:(int)_option level:(int)_level {
275 if ((self = [super initWithReason:_reason])) {
289 @end /* NGSocketOptionException */
291 @implementation NGCouldNotSetSocketOptionException
292 @end /* NGCouldNotSetSocketOptionException */
294 @implementation NGCouldNotGetSocketOptionException
295 @end /* NGCouldNotGetSocketOptionException */
297 // ******************** socket closed **************
299 @implementation NGSocketShutdownException
302 return [self initWithStream:nil reason:@"the socket was shutdown"];
304 - (id)initWithReason:(NSString *)_reason {
305 return [self initWithStream:nil reason:_reason];
307 - (id)initWithReason:(NSString *)_reason socket:(id<NGActiveSocket>)_socket {
308 return [self initWithStream:_socket reason:_reason];
311 - (id)initWithSocket:(id<NGActiveSocket>)_socket {
312 return [self initWithStream:_socket reason:@"the socket was shutdown"];
317 - (id<NGActiveSocket>)socket {
318 return [self->streamPointer nonretainedObjectValue];
321 @end /* NGSocketShutdownException */
323 @implementation NGSocketShutdownDuringReadException
326 @implementation NGSocketShutdownDuringWriteException
329 @implementation NGSocketTimedOutException
332 @implementation NGSocketConnectionResetException