︙ | | | ︙ | |
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
@synthesize delegate = _delegate;
+ (void)initialize
{
if (self != [OFDatagramSocket class])
return;
if (!OFSocketInit())
@throw [OFInitializationFailedException
exceptionWithClass: self];
}
+ (instancetype)socket
{
return [[[self alloc] init] autorelease];
|
|
|
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
@synthesize delegate = _delegate;
+ (void)initialize
{
if (self != [OFDatagramSocket class])
return;
if (!_OFSocketInit())
@throw [OFInitializationFailedException
exceptionWithClass: self];
}
+ (instancetype)socket
{
return [[[self alloc] init] autorelease];
|
︙ | | | ︙ | |
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
171
172
173
174
175
176
177
178
179
|
_canBlock = canBlock;
#elif defined(OF_WINDOWS)
u_long v = !canBlock;
if (ioctlsocket(_socket, FIONBIO, &v) == SOCKET_ERROR)
@throw [OFSetOptionFailedException
exceptionWithObject: self
errNo: OFSocketErrNo()];
_canBlock = canBlock;
#else
OF_UNRECOGNIZED_SELECTOR
#endif
}
- (void)setCanSendToBroadcastAddresses: (bool)canSendToBroadcastAddresses
{
int v = canSendToBroadcastAddresses;
if (setsockopt(_socket, SOL_SOCKET, SO_BROADCAST,
(char *)&v, (socklen_t)sizeof(v)) != 0)
@throw [OFSetOptionFailedException
exceptionWithObject: self
errNo: OFSocketErrNo()];
#ifdef OF_WII
_canSendToBroadcastAddresses = canSendToBroadcastAddresses;
#endif
}
- (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: OFSocketErrNo()];
return v;
#else
return _canSendToBroadcastAddresses;
#endif
}
|
|
|
|
|
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
171
172
173
174
175
176
177
178
179
|
_canBlock = canBlock;
#elif defined(OF_WINDOWS)
u_long v = !canBlock;
if (ioctlsocket(_socket, FIONBIO, &v) == SOCKET_ERROR)
@throw [OFSetOptionFailedException
exceptionWithObject: self
errNo: _OFSocketErrNo()];
_canBlock = canBlock;
#else
OF_UNRECOGNIZED_SELECTOR
#endif
}
- (void)setCanSendToBroadcastAddresses: (bool)canSendToBroadcastAddresses
{
int v = canSendToBroadcastAddresses;
if (setsockopt(_socket, SOL_SOCKET, SO_BROADCAST,
(char *)&v, (socklen_t)sizeof(v)) != 0)
@throw [OFSetOptionFailedException
exceptionWithObject: self
errNo: _OFSocketErrNo()];
#ifdef OF_WII
_canSendToBroadcastAddresses = canSendToBroadcastAddresses;
#endif
}
- (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: _OFSocketErrNo()];
return v;
#else
return _canSendToBroadcastAddresses;
#endif
}
|
︙ | | | ︙ | |
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
|
#ifndef OF_WINDOWS
if ((ret = recvfrom(_socket, buffer, length, 0,
(sender != NULL ? (struct sockaddr *)&sender->sockaddr : NULL),
(sender != NULL ? &sender->length : NULL))) < 0)
@throw [OFReadFailedException
exceptionWithObject: self
requestedLength: length
errNo: OFSocketErrNo()];
#else
if (length > INT_MAX)
@throw [OFOutOfRangeException exception];
if ((ret = recvfrom(_socket, buffer, (int)length, 0,
(sender != NULL ? (struct sockaddr *)&sender->sockaddr : NULL),
(sender != NULL ? &sender->length : NULL))) < 0)
@throw [OFReadFailedException
exceptionWithObject: self
requestedLength: length
errNo: OFSocketErrNo()];
#endif
if (sender != NULL) {
struct sockaddr *sa = (struct sockaddr *)&sender->sockaddr;
if (sender->length >= (socklen_t)sizeof(sa->sa_family)) {
switch (sa->sa_family) {
|
|
|
|
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
|
#ifndef OF_WINDOWS
if ((ret = recvfrom(_socket, buffer, length, 0,
(sender != NULL ? (struct sockaddr *)&sender->sockaddr : NULL),
(sender != NULL ? &sender->length : NULL))) < 0)
@throw [OFReadFailedException
exceptionWithObject: self
requestedLength: length
errNo: _OFSocketErrNo()];
#else
if (length > INT_MAX)
@throw [OFOutOfRangeException exception];
if ((ret = recvfrom(_socket, buffer, (int)length, 0,
(sender != NULL ? (struct sockaddr *)&sender->sockaddr : NULL),
(sender != NULL ? &sender->length : NULL))) < 0)
@throw [OFReadFailedException
exceptionWithObject: self
requestedLength: length
errNo: _OFSocketErrNo()];
#endif
if (sender != NULL) {
struct sockaddr *sa = (struct sockaddr *)&sender->sockaddr;
if (sender->length >= (socklen_t)sizeof(sa->sa_family)) {
switch (sa->sa_family) {
|
︙ | | | ︙ | |
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
|
if ((bytesWritten = sendto(_socket, (void *)buffer, length, 0,
(struct sockaddr *)&receiver->sockaddr, receiver->length)) < 0)
@throw [OFWriteFailedException
exceptionWithObject: self
requestedLength: length
bytesWritten: 0
errNo: OFSocketErrNo()];
#else
int bytesWritten;
if (length > INT_MAX)
@throw [OFOutOfRangeException exception];
if ((bytesWritten = sendto(_socket, buffer, (int)length, 0,
(struct sockaddr *)&receiver->sockaddr, receiver->length)) < 0)
@throw [OFWriteFailedException
exceptionWithObject: self
requestedLength: length
bytesWritten: 0
errNo: OFSocketErrNo()];
#endif
if ((size_t)bytesWritten != length)
@throw [OFWriteFailedException exceptionWithObject: self
requestedLength: length
bytesWritten: bytesWritten
errNo: 0];
|
|
|
|
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
|
if ((bytesWritten = sendto(_socket, (void *)buffer, length, 0,
(struct sockaddr *)&receiver->sockaddr, receiver->length)) < 0)
@throw [OFWriteFailedException
exceptionWithObject: self
requestedLength: length
bytesWritten: 0
errNo: _OFSocketErrNo()];
#else
int bytesWritten;
if (length > INT_MAX)
@throw [OFOutOfRangeException exception];
if ((bytesWritten = sendto(_socket, buffer, (int)length, 0,
(struct sockaddr *)&receiver->sockaddr, receiver->length)) < 0)
@throw [OFWriteFailedException
exceptionWithObject: self
requestedLength: length
bytesWritten: 0
errNo: _OFSocketErrNo()];
#endif
if ((size_t)bytesWritten != length)
@throw [OFWriteFailedException exceptionWithObject: self
requestedLength: length
bytesWritten: bytesWritten
errNo: 0];
|
︙ | | | ︙ | |