ObjFW  Diff

Differences From Artifact [08aed9e1e3]:

To Artifact [4cd95b929d]:


65
66
67
68
69
70
71
72

73
74
75
76
77
78
79
65
66
67
68
69
70
71

72
73
74
75
76
77
78
79







-
+







	@try {
		if (self.class == [OFDatagramSocket class]) {
			[self doesNotRecognizeSelector: _cmd];
			abort();
		}

		_socket = INVALID_SOCKET;
		_blocking = true;
		_canBlock = true;
	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}
87
88
89
90
91
92
93
94

95
96

97
98
99

100
101
102
103
104
105
106
107
108

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
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
87
88
89
90
91
92
93

94
95

96
97
98

99
100
101
102
103
104
105
106
107

108
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
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







-
+

-
+


-
+








-
+








-
+

-
+






-
+





-
+

-
+








-
+



-
+













-
+







}

- (id)copy
{
	return [self retain];
}

- (bool)isBlocking
- (bool)canBlock
{
	return _blocking;
	return _canBlock;
}

- (void)setBlocking: (bool)enable
- (void)setCanBlock: (bool)canBlock
{
#if defined(HAVE_FCNTL)
	int flags = fcntl(_socket, F_GETFL, 0);

	if (flags == -1)
		@throw [OFSetOptionFailedException exceptionWithObject: self
								 errNo: errno];

	if (enable)
	if (canBlock)
		flags &= ~O_NONBLOCK;
	else
		flags |= O_NONBLOCK;

	if (fcntl(_socket, F_SETFL, flags) == -1)
		@throw [OFSetOptionFailedException exceptionWithObject: self
								 errNo: errno];

	_blocking = enable;
	_canBlock = canBlock;
#elif defined(OF_WINDOWS)
	u_long v = enable;
	u_long v = canBlock;

	if (ioctlsocket(_socket, FIONBIO, &v) == SOCKET_ERROR)
		@throw [OFSetOptionFailedException
		    exceptionWithObject: self
				  errNo: of_socket_errno()];

	_blocking = enable;
	_canBlock = canBlock;
#else
	OF_UNRECOGNIZED_SELECTOR
#endif
}

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

	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;
	_canSendToBroadcastAddresses = allowed;
#endif
}

- (bool)isBroadcastAllowed
- (bool)canSendToBroadcastAddresses
{
#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;
	return _canSendToBroadcastAddresses;
#endif
}

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