ObjFW  Check-in [310fd74f89]

Overview
Comment:OFDatagramSocket: Add broadcastAllowed property
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 310fd74f895a9a0e5f31e02adefbc2b94b3eb5496542efce50266d0149c686b0
User & Date: js on 2020-05-03 12:14:25
Other Links: manifest | tags
Context
2020-05-03
19:36
Add OFSPXStreamSocket check-in: 0ded796f1a user: js tags: trunk
12:14
OFDatagramSocket: Add broadcastAllowed property check-in: 310fd74f89 user: js tags: trunk
2020-05-02
19:13
Update buildsys check-in: 64f22ba97e user: js tags: trunk
Changes

Modified src/OFDatagramSocket.h from [a18e14bea6] to [c9598f3c24].

109
110
111
112
113
114
115



116
117
118
119
120
121
122
123
124
125
126





127
128
129
130
131
132
133
 *	    was called to create one "instance" for every thread!
 */
@interface OFDatagramSocket: OFObject <OFCopying, OFReadyForReadingObserving,
    OFReadyForWritingObserving>
{
	of_socket_t _socket;
	bool _blocking;



	id <OFDatagramSocketDelegate> _Nullable _delegate;
	OF_RESERVE_IVARS(4)
}

/*!
 * @brief Whether the socket is in blocking mode.
 *
 * By default, a socket is in blocking mode.
 */
@property (nonatomic, getter=isBlocking) bool blocking;






/*!
 * @brief The delegate for asynchronous operations on the socket.
 *
 * @note The delegate is retained for as long as asynchronous operations are
 *	 still ongoing.
 */
@property OF_NULLABLE_PROPERTY (assign, nonatomic)







>
>
>











>
>
>
>
>







109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
 *	    was called to create one "instance" for every thread!
 */
@interface OFDatagramSocket: OFObject <OFCopying, OFReadyForReadingObserving,
    OFReadyForWritingObserving>
{
	of_socket_t _socket;
	bool _blocking;
#ifdef OF_WII
	bool _broadcastAllowed;
#endif
	id <OFDatagramSocketDelegate> _Nullable _delegate;
	OF_RESERVE_IVARS(4)
}

/*!
 * @brief Whether the socket is in blocking mode.
 *
 * By default, a socket is in blocking mode.
 */
@property (nonatomic, getter=isBlocking) bool blocking;

/*!
 * @brief Whether the socket is allowed to send to broadcast addresses.
 */
@property (nonatomic, getter=isBroadcastAllowed) bool broadcastAllowed;

/*!
 * @brief The delegate for asynchronous operations on the socket.
 *
 * @note The delegate is retained for as long as asynchronous operations are
 *	 still ongoing.
 */
@property OF_NULLABLE_PROPERTY (assign, nonatomic)

Modified src/OFDatagramSocket.m from [047e480ca4] to [08aed9e1e3].

24
25
26
27
28
29
30

31
32
33
34

35
36
37
38
39
40
41
#endif

#import "OFDatagramSocket.h"
#import "OFData.h"
#import "OFRunLoop+Private.h"
#import "OFRunLoop.h"


#import "OFInitializationFailedException.h"
#import "OFNotOpenException.h"
#import "OFOutOfRangeException.h"
#import "OFReadFailedException.h"

#import "OFSetOptionFailedException.h"
#import "OFWriteFailedException.h"

#import "socket.h"
#import "socket_helpers.h"

@implementation OFDatagramSocket







>




>







24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#endif

#import "OFDatagramSocket.h"
#import "OFData.h"
#import "OFRunLoop+Private.h"
#import "OFRunLoop.h"

#import "OFGetOptionFailedException.h"
#import "OFInitializationFailedException.h"
#import "OFNotOpenException.h"
#import "OFOutOfRangeException.h"
#import "OFReadFailedException.h"
#import "OFSetOptionFailedException.h"
#import "OFSetOptionFailedException.h"
#import "OFWriteFailedException.h"

#import "socket.h"
#import "socket_helpers.h"

@implementation OFDatagramSocket
122
123
124
125
126
127
128

































129
130
131
132
133
134
135
				  errNo: of_socket_errno()];

	_blocking = enable;
#else
	OF_UNRECOGNIZED_SELECTOR
#endif
}


































- (size_t)receiveIntoBuffer: (void *)buffer
		     length: (size_t)length
		     sender: (of_socket_address_t *)sender
{
	ssize_t ret;








>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
				  errNo: of_socket_errno()];

	_blocking = enable;
#else
	OF_UNRECOGNIZED_SELECTOR
#endif
}

- (void)setBroadcastAllowed: (bool)allowed
{
	int v = allowed;

	if (setsockopt(_socket, SOL_SOCKET, SO_BROADCAST,
	    (char *)&v, (socklen_t)sizeof(v)) != 0)
		@throw [OFSetOptionFailedException
		    exceptionWithObject: self
				  errNo: of_socket_errno()];

#ifdef OF_WII
	_broadcastAllowed = allowed;
#endif
}

- (bool)isBroadcastAllowed
{
#ifndef OF_WII
	int v;
	socklen_t len = sizeof(v);

	if (getsockopt(_socket, SOL_SOCKET, SO_BROADCAST,
	    (char *)&v, &len) != 0 || len != sizeof(v))
		@throw [OFGetOptionFailedException
		    exceptionWithObject: self
				  errNo: of_socket_errno()];

	return v;
#else
	return _broadcastAllowed;
#endif
}

- (size_t)receiveIntoBuffer: (void *)buffer
		     length: (size_t)length
		     sender: (of_socket_address_t *)sender
{
	ssize_t ret;

Modified src/OFTCPSocket.m from [aa9ac8bab1] to [48edda05b6].

947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
{
	int v;
	socklen_t len = sizeof(v);

	if (getsockopt(_socket, SOL_SOCKET, SO_KEEPALIVE,
	    (char *)&v, &len) != 0 || len != sizeof(v))
		@throw [OFGetOptionFailedException
		    exceptionWithStream: self
				  errNo: of_socket_errno()];

	return v;
}
#endif

#ifndef OF_WII







|







947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
{
	int v;
	socklen_t len = sizeof(v);

	if (getsockopt(_socket, SOL_SOCKET, SO_KEEPALIVE,
	    (char *)&v, &len) != 0 || len != sizeof(v))
		@throw [OFGetOptionFailedException
		    exceptionWithObject: self
				  errNo: of_socket_errno()];

	return v;
}
#endif

#ifndef OF_WII
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
{
	int v;
	socklen_t len = sizeof(v);

	if (getsockopt(_socket, IPPROTO_TCP, TCP_NODELAY,
	    (char *)&v, &len) != 0 || len != sizeof(v))
		@throw [OFGetOptionFailedException
		    exceptionWithStream: self
				  errNo: of_socket_errno()];

	return v;
}
#endif

- (void)close







|







974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
{
	int v;
	socklen_t len = sizeof(v);

	if (getsockopt(_socket, IPPROTO_TCP, TCP_NODELAY,
	    (char *)&v, &len) != 0 || len != sizeof(v))
		@throw [OFGetOptionFailedException
		    exceptionWithObject: self
				  errNo: of_socket_errno()];

	return v;
}
#endif

- (void)close

Modified src/exceptions/OFGetOptionFailedException.h from [4a4969db85] to [70541d2ad1].

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
63
64
65
66
67
68
69
70
71
 * file.
 */

#import "OFException.h"

OF_ASSUME_NONNULL_BEGIN

@class OFStream;

/*!
 * @class OFGetOptionFailedException \
 *	  OFGetOptionFailedException.h ObjFW/OFGetOptionFailedException.h
 *
 * @brief An exception indicating that getting an option for a stream failed.
 */
@interface OFGetOptionFailedException: OFException
{
	OFStream *_stream;
	int _errNo;
}

/*!
 * @brief The stream for which the option could not be retrieved.
 */
@property (readonly, nonatomic) OFStream *stream;

/*!
 * @brief The errno of the error that occurred.
 */
@property (readonly, nonatomic) int errNo;

+ (instancetype)exception OF_UNAVAILABLE;

/*!
 * @brief Creates a new, autoreleased get option failed exception.
 *
 * @param stream The stream for which the option could not be gotten
 * @param errNo The errno of the error that occurred
 * @return A new, autoreleased get option failed exception
 */
+ (instancetype)exceptionWithStream: (OFStream *)stream
			      errNo: (int)errNo;

- (instancetype)init OF_UNAVAILABLE;

/*!
 * @brief Initializes an already allocated get option failed exception.
 *
 * @param stream The stream for which the option could not be gotten
 * @param errNo The errno of the error that occurred
 * @return An initialized get option failed exception
 */
- (instancetype)initWithStream: (OFStream *)stream
			 errNo: (int)errNo OF_DESIGNATED_INITIALIZER;
@end

OF_ASSUME_NONNULL_END







<
<




|



|




|

|











|



|







|



|




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
63
64
65
66
67
68
69
 * file.
 */

#import "OFException.h"

OF_ASSUME_NONNULL_BEGIN



/*!
 * @class OFGetOptionFailedException \
 *	  OFGetOptionFailedException.h ObjFW/OFGetOptionFailedException.h
 *
 * @brief An exception indicating that getting an option for an object failed.
 */
@interface OFGetOptionFailedException: OFException
{
	id _object;
	int _errNo;
}

/*!
 * @brief The object for which the option could not be retrieved.
 */
@property (readonly, nonatomic) id object;

/*!
 * @brief The errno of the error that occurred.
 */
@property (readonly, nonatomic) int errNo;

+ (instancetype)exception OF_UNAVAILABLE;

/*!
 * @brief Creates a new, autoreleased get option failed exception.
 *
 * @param object The object for which the option could not be retrieved
 * @param errNo The errno of the error that occurred
 * @return A new, autoreleased get option failed exception
 */
+ (instancetype)exceptionWithObject: (id)object
			      errNo: (int)errNo;

- (instancetype)init OF_UNAVAILABLE;

/*!
 * @brief Initializes an already allocated get option failed exception.
 *
 * @param object The object for which the option could not be retrieved
 * @param errNo The errno of the error that occurred
 * @return An initialized get option failed exception
 */
- (instancetype)initWithObject: (id)object
			 errNo: (int)errNo OF_DESIGNATED_INITIALIZER;
@end

OF_ASSUME_NONNULL_END

Modified src/exceptions/OFGetOptionFailedException.m from [2c7cb59f5d] to [a2104983ac].

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
63
64
65
66
67
68
 * file.
 */

#include "config.h"

#import "OFGetOptionFailedException.h"
#import "OFString.h"
#import "OFStream.h"

@implementation OFGetOptionFailedException
@synthesize stream = _stream, errNo = _errNo;

+ (instancetype)exception
{
	OF_UNRECOGNIZED_SELECTOR
}

+ (instancetype)exceptionWithStream: (OFStream *)stream
			      errNo: (int)errNo
{
	return [[[self alloc] initWithStream: stream
				       errNo: errNo] autorelease];
}

- (instancetype)init
{
	OF_INVALID_INIT_METHOD
}

- (instancetype)initWithStream: (OFStream *)stream
			 errNo: (int)errNo
{
	self = [super init];

	_stream = [stream retain];
	_errNo = errNo;

	return self;
}

- (void)dealloc
{
	[_stream release];

	[super dealloc];
}

- (OFString *)description
{
	return [OFString stringWithFormat:
	    @"Getting an option in a stream of type %@ failed: %@",
	    _stream.class, of_strerror(_errNo)];
}
@end







<


|






|


|








|




|







|







|
|


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
63
64
65
66
67
 * file.
 */

#include "config.h"

#import "OFGetOptionFailedException.h"
#import "OFString.h"


@implementation OFGetOptionFailedException
@synthesize object = _object, errNo = _errNo;

+ (instancetype)exception
{
	OF_UNRECOGNIZED_SELECTOR
}

+ (instancetype)exceptionWithObject: (id)object
			      errNo: (int)errNo
{
	return [[[self alloc] initWithObject: object
				       errNo: errNo] autorelease];
}

- (instancetype)init
{
	OF_INVALID_INIT_METHOD
}

- (instancetype)initWithObject: (id)object
			 errNo: (int)errNo
{
	self = [super init];

	_object = [object retain];
	_errNo = errNo;

	return self;
}

- (void)dealloc
{
	[_object release];

	[super dealloc];
}

- (OFString *)description
{
	return [OFString stringWithFormat:
	    @"Getting an option in an object of type %@ failed: %@",
	    [_object class], of_strerror(_errNo)];
}
@end