1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
-
+
-
+
-
-
+
+
-
+
-
+
-
+
-
+
-
+
-
+
+
+
+
+
+
-
+
-
-
-
-
-
+
+
+
+
-
-
|
/*
* Copyright (c) 2008-2022 Jonathan Schleifer <js@nil.im>
* Copyright (c) 2008-2023 Jonathan Schleifer <js@nil.im>
*
* All rights reserved.
*
* This file is part of ObjFW. It may be distributed under the terms of the
* Q Public License 1.0, which can be found in the file LICENSE.QPL included in
* the packaging of this file.
*
* Alternatively, it may be distributed under the terms of the GNU General
* Public License, either version 2 or 3, which can be found in the file
* LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
* file.
*/
#include "config.h"
#import "OFAlreadyConnectedException.h"
#import "OFAlreadyOpenException.h"
#import "OFString.h"
@implementation OFAlreadyConnectedException
@synthesize socket = _socket;
@implementation OFAlreadyOpenException
@synthesize object = _object;
+ (instancetype)exceptionWithSocket: (id)sock
+ (instancetype)exceptionWithObject: (id)object
{
return [[[self alloc] initWithSocket: sock] autorelease];
return [[[self alloc] initWithObject: object] autorelease];
}
- (instancetype)init
+ (instancetype)exception
{
return [self initWithSocket: nil];
OF_UNRECOGNIZED_SELECTOR
}
- (instancetype)initWithSocket: (id)sock
- (instancetype)initWithObject: (id)object
{
self = [super init];
_socket = [sock retain];
_object = [object retain];
return self;
}
- (instancetype)init
{
OF_INVALID_INIT_METHOD
}
- (void)dealloc
{
[_socket release];
[_object release];
[super dealloc];
}
- (OFString *)description
{
if (_socket)
return [OFString stringWithFormat:
@"The socket of type %@ is already connected or bound and "
@"thus can't be connected or bound again!",
[_socket class]];
return [OFString stringWithFormat:
@"An object of type %@ is already open and thus cannot be opened "
@"again!",
[_object class]];
else
return @"A connection has already been established!";
}
@end
|