ObjFW  Check-in [d43eb177bc]

Overview
Comment:BOOL naming conventions.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: d43eb177bc56713a03a2cad4533cce90e584bd219a2f5bed2a66a7dd5620c870
User & Date: js on 2011-09-19 12:34:21
Other Links: manifest | tags
Context
2011-09-19
12:44
Nicer OFStreamObserver API. check-in: c279948fb8 user: js tags: trunk
12:34
BOOL naming conventions. check-in: d43eb177bc user: js tags: trunk
12:07
Improve OFStreamObserver. check-in: d3f6cf9293 user: js tags: trunk
Changes

Modified src/OFConstantString.m from [993ed1e2bc] to [5b58150777].

54
55
56
57
58
59
60
61
62
63
64
65
66
67
68

	ivars->cString = (char*)s;
	ivars->cStringLength = initialized;

	switch (of_string_check_utf8(ivars->cString, ivars->cStringLength,
	    &ivars->length)) {
	case 1:
		ivars->isUTF8 = YES;
		break;
	case -1:
		free(ivars);
		@throw [OFInvalidEncodingException newWithClass: isa];
	}

	s = ivars;







|







54
55
56
57
58
59
60
61
62
63
64
65
66
67
68

	ivars->cString = (char*)s;
	ivars->cStringLength = initialized;

	switch (of_string_check_utf8(ivars->cString, ivars->cStringLength,
	    &ivars->length)) {
	case 1:
		ivars->UTF8 = YES;
		break;
	case -1:
		free(ivars);
		@throw [OFInvalidEncodingException newWithClass: isa];
	}

	s = ivars;

Modified src/OFFile.h from [dda7fbe65f] to [d0c05fd8c7].

32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/**
 * \brief A class which provides functions to read, write and manipulate files.
 */
@interface OFFile: OFSeekableStream
{
	int  fileDescriptor;
	BOOL closable;
	BOOL isAtEndOfStream;
}

/**
 * \brief Creates a new OFFile with the specified path and mode.
 *
 * \param path The path to the file to open as a string
 * \param mode The mode in which the file should be opened as a string







|







32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/**
 * \brief A class which provides functions to read, write and manipulate files.
 */
@interface OFFile: OFSeekableStream
{
	int  fileDescriptor;
	BOOL closable;
	BOOL atEndOfStream;
}

/**
 * \brief Creates a new OFFile with the specified path and mode.
 *
 * \param path The path to the file to open as a string
 * \param mode The mode in which the file should be opened as a string

Modified src/OFFile.m from [281aa87c5c] to [689b4e3ed7].

611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
}

- (BOOL)_isAtEndOfStream
{
	if (fileDescriptor == -1)
		return YES;

	return isAtEndOfStream;
}

- (size_t)_readNBytes: (size_t)length
	   intoBuffer: (void*)buffer
{
	size_t ret;

	if (fileDescriptor == -1 || isAtEndOfStream)
		@throw [OFReadFailedException newWithClass: isa
						    stream: self
					   requestedLength: length];

	if ((ret = read(fileDescriptor, buffer, length)) == 0)
		isAtEndOfStream = YES;

	return ret;
}

- (void)_writeNBytes: (size_t)length
	  fromBuffer: (const void*)buffer
{
	if (fileDescriptor == -1 || isAtEndOfStream ||
	    write(fileDescriptor, buffer, length) < length)
		@throw [OFWriteFailedException newWithClass: isa
						     stream: self
					    requestedLength: length];
}

- (void)_seekToOffset: (off_t)offset







|







|





|







|







611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
}

- (BOOL)_isAtEndOfStream
{
	if (fileDescriptor == -1)
		return YES;

	return atEndOfStream;
}

- (size_t)_readNBytes: (size_t)length
	   intoBuffer: (void*)buffer
{
	size_t ret;

	if (fileDescriptor == -1 || atEndOfStream)
		@throw [OFReadFailedException newWithClass: isa
						    stream: self
					   requestedLength: length];

	if ((ret = read(fileDescriptor, buffer, length)) == 0)
		atEndOfStream = YES;

	return ret;
}

- (void)_writeNBytes: (size_t)length
	  fromBuffer: (const void*)buffer
{
	if (fileDescriptor == -1 || atEndOfStream ||
	    write(fileDescriptor, buffer, length) < length)
		@throw [OFWriteFailedException newWithClass: isa
						     stream: self
					    requestedLength: length];
}

- (void)_seekToOffset: (off_t)offset

Modified src/OFHash.h from [7ac882f338] to [364386ee07].

17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#import "OFObject.h"

/**
 * \brief A base class for classes providing hash functions.
 */
@interface OFHash: OFObject
{
	BOOL	 isCalculated;
}

#ifdef OF_HAVE_PROPERTIES
@property (readonly) BOOL isCalculated;
#endif

/**
 * \brief Returns the digest size of the hash, in bytes.
 *
 * \return The digest size of the hash, in bytes
 */







|



|







17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#import "OFObject.h"

/**
 * \brief A base class for classes providing hash functions.
 */
@interface OFHash: OFObject
{
	BOOL calculated;
}

#ifdef OF_HAVE_PROPERTIES
@property (readonly, getter=isCalculated) BOOL calculated;
#endif

/**
 * \brief Returns the digest size of the hash, in bytes.
 *
 * \return The digest size of the hash, in bytes
 */

Modified src/OFHash.m from [528220f4b7] to [4c0ad468a8].

44
45
46
47
48
49
50
51
52
53
{
	@throw [OFNotImplementedException newWithClass: isa
					      selector: _cmd];
}

- (BOOL)isCalculated
{
	return isCalculated;
}
@end







|


44
45
46
47
48
49
50
51
52
53
{
	@throw [OFNotImplementedException newWithClass: isa
					      selector: _cmd];
}

- (BOOL)isCalculated
{
	return calculated;
}
@end

Modified src/OFMD5Hash.m from [e8adf60118] to [c4ee6e4bc8].

150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
		  length: (size_t)length
{
	uint32_t t;

	if (length == 0)
		return;

	if (isCalculated)
		@throw [OFHashAlreadyCalculatedException newWithClass: isa
								 hash: self];

	/* Update bitcount */
	t = bits[0];
	if ((bits[0] = t + ((uint32_t)length << 3)) < t)
		/* Carry from low to high */







|







150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
		  length: (size_t)length
{
	uint32_t t;

	if (length == 0)
		return;

	if (calculated)
		@throw [OFHashAlreadyCalculatedException newWithClass: isa
								 hash: self];

	/* Update bitcount */
	t = bits[0];
	if ((bits[0] = t + ((uint32_t)length << 3)) < t)
		/* Carry from low to high */
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
}

- (uint8_t*)digest
{
	uint8_t	*p;
	size_t	count;

	if (isCalculated)
		return (uint8_t*)buffer;

	/* Compute number of bytes mod 64 */
	count = (bits[0] >> 3) & 0x3F;

	/*
	 * Set the first char of padding to 0x80. This is safe since there is







|







202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
}

- (uint8_t*)digest
{
	uint8_t	*p;
	size_t	count;

	if (calculated)
		return (uint8_t*)buffer;

	/* Compute number of bytes mod 64 */
	count = (bits[0] >> 3) & 0x3F;

	/*
	 * Set the first char of padding to 0x80. This is safe since there is
240
241
242
243
244
245
246
247
248
249
250
251
	/* Append length in bits and transform */
	in.u32[14] = bits[0];
	in.u32[15] = bits[1];

	md5_transform(buffer, in.u32);
	of_bswap32_vec_if_be(buffer, 4);

	isCalculated = YES;

	return (uint8_t*)buffer;
}
@end







|




240
241
242
243
244
245
246
247
248
249
250
251
	/* Append length in bits and transform */
	in.u32[14] = bits[0];
	in.u32[15] = bits[1];

	md5_transform(buffer, in.u32);
	of_bswap32_vec_if_be(buffer, 4);

	calculated = YES;

	return (uint8_t*)buffer;
}
@end

Modified src/OFMutableString.m from [2744e572a4] to [bc1cbfd1e0].

48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
{
	of_unichar_t c;
	of_unichar_t *unicodeString;
	size_t unicodeLen, newCStringLength, cLen;
	size_t i, j, d;
	char *newCString;

	if (!s->isUTF8) {
		assert(tableSize >= 1);

		uint8_t *p = (uint8_t*)s->cString + s->cStringLength;
		uint8_t t;

		while (--p >= (uint8_t*)s->cString)
			if ((t = table[0][*p]) != 0)







|







48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
{
	of_unichar_t c;
	of_unichar_t *unicodeString;
	size_t unicodeLen, newCStringLength, cLen;
	size_t i, j, d;
	char *newCString;

	if (!s->UTF8) {
		assert(tableSize >= 1);

		uint8_t *p = (uint8_t*)s->cString + s->cStringLength;
		uint8_t t;

		while (--p >= (uint8_t*)s->cString)
			if ((t = table[0][*p]) != 0)
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
	if (UTF8StringLength >= 3 && !memcmp(UTF8String, "\xEF\xBB\xBF", 3)) {
		UTF8String += 3;
		UTF8StringLength -= 3;
	}

	switch (of_string_check_utf8(UTF8String, UTF8StringLength, &length)) {
	case 1:
		s->isUTF8 = YES;
		break;
	case -1:
		@throw [OFInvalidEncodingException newWithClass: isa];
	}

	s->cString = [self resizeMemory: s->cString
				 toSize: s->cStringLength +







|







146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
	if (UTF8StringLength >= 3 && !memcmp(UTF8String, "\xEF\xBB\xBF", 3)) {
		UTF8String += 3;
		UTF8StringLength -= 3;
	}

	switch (of_string_check_utf8(UTF8String, UTF8StringLength, &length)) {
	case 1:
		s->UTF8 = YES;
		break;
	case -1:
		@throw [OFInvalidEncodingException newWithClass: isa];
	}

	s->cString = [self resizeMemory: s->cString
				 toSize: s->cStringLength +
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
	if (UTF8StringLength >= 3 && !memcmp(UTF8String, "\xEF\xBB\xBF", 3)) {
		UTF8String += 3;
		UTF8StringLength -= 3;
	}

	switch (of_string_check_utf8(UTF8String, UTF8StringLength, &length)) {
	case 1:
		s->isUTF8 = YES;
		break;
	case -1:
		@throw [OFInvalidEncodingException newWithClass: isa];
	}

	s->cString = [self resizeMemory: s->cString
				 toSize: s->cStringLength +







|







173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
	if (UTF8StringLength >= 3 && !memcmp(UTF8String, "\xEF\xBB\xBF", 3)) {
		UTF8String += 3;
		UTF8StringLength -= 3;
	}

	switch (of_string_check_utf8(UTF8String, UTF8StringLength, &length)) {
	case 1:
		s->UTF8 = YES;
		break;
	case -1:
		@throw [OFInvalidEncodingException newWithClass: isa];
	}

	s->cString = [self resizeMemory: s->cString
				 toSize: s->cStringLength +
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
	    UTF8StringLength);

	s->cStringLength += UTF8StringLength;
	s->length += string->s->length;

	s->cString[s->cStringLength] = 0;

	if (string->s->isUTF8)
		s->isUTF8 = YES;
}

- (void)appendFormat: (OFConstantString*)format, ...
{
	va_list arguments;

	va_start(arguments, format);







|
|







236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
	    UTF8StringLength);

	s->cStringLength += UTF8StringLength;
	s->length += string->s->length;

	s->cString[s->cStringLength] = 0;

	if (string->s->UTF8)
		s->UTF8 = YES;
}

- (void)appendFormat: (OFConstantString*)format, ...
{
	va_list arguments;

	va_start(arguments, format);
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
	for (i = 0, j = s->cStringLength - 1; i < s->cStringLength / 2;
	    i++, j--) {
		s->cString[i] ^= s->cString[j];
		s->cString[j] ^= s->cString[i];
		s->cString[i] ^= s->cString[j];
	}

	if (!s->isUTF8) {
		madvise(s->cString, s->cStringLength, MADV_NORMAL);
		return;
	}

	for (i = 0; i < s->cStringLength; i++) {
		/* ASCII */
		if (OF_LIKELY(!(s->cString[i] & 0x80)))







|







292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
	for (i = 0, j = s->cStringLength - 1; i < s->cStringLength / 2;
	    i++, j--) {
		s->cString[i] ^= s->cString[j];
		s->cString[j] ^= s->cString[i];
		s->cString[i] ^= s->cString[j];
	}

	if (!s->UTF8) {
		madvise(s->cString, s->cStringLength, MADV_NORMAL);
		return;
	}

	for (i = 0; i < s->cStringLength; i++) {
		/* ASCII */
		if (OF_LIKELY(!(s->cString[i] & 0x80)))
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
	     atIndex: (size_t)index
{
	size_t newCStringLength;

	if (index > s->length)
		@throw [OFOutOfRangeException newWithClass: isa];

	if (s->isUTF8)
		index = of_string_index_to_position(s->cString, index,
		    s->cStringLength);

	newCStringLength = s->cStringLength + [string UTF8StringLength];
	s->cString = [self resizeMemory: s->cString
				 toSize: newCStringLength + 1];








|







391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
	     atIndex: (size_t)index
{
	size_t newCStringLength;

	if (index > s->length)
		@throw [OFOutOfRangeException newWithClass: isa];

	if (s->UTF8)
		index = of_string_index_to_position(s->cString, index,
		    s->cStringLength);

	newCStringLength = s->cStringLength + [string UTF8StringLength];
	s->cString = [self resizeMemory: s->cString
				 toSize: newCStringLength + 1];

423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
						       selector: _cmd];

	if (end > s->length)
		@throw [OFOutOfRangeException newWithClass: isa];

	s->length -= end - start;

	if (s->isUTF8) {
		start = of_string_index_to_position(s->cString, start,
		    s->cStringLength);
		end = of_string_index_to_position(s->cString, end,
		    s->cStringLength);
	}

	memmove(s->cString + start, s->cString + end, s->cStringLength - end);







|







423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
						       selector: _cmd];

	if (end > s->length)
		@throw [OFOutOfRangeException newWithClass: isa];

	s->length -= end - start;

	if (s->UTF8) {
		start = of_string_index_to_position(s->cString, start,
		    s->cStringLength);
		end = of_string_index_to_position(s->cString, end,
		    s->cStringLength);
	}

	memmove(s->cString + start, s->cString + end, s->cStringLength - end);
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
						       selector: _cmd];

	if (end > s->length)
		@throw [OFOutOfRangeException newWithClass: isa];

	newLength = s->length - (end - start) + [replacement length];

	if (s->isUTF8) {
		start = of_string_index_to_position(s->cString, start,
		    s->cStringLength);
		end = of_string_index_to_position(s->cString, end,
		    s->cStringLength);
	}

	newCStringLength = s->cStringLength - (end - start) +







|







459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
						       selector: _cmd];

	if (end > s->length)
		@throw [OFOutOfRangeException newWithClass: isa];

	newLength = s->length - (end - start) + [replacement length];

	if (s->UTF8) {
		start = of_string_index_to_position(s->cString, start,
		    s->cStringLength);
		end = of_string_index_to_position(s->cString, end,
		    s->cStringLength);
	}

	newCStringLength = s->cStringLength - (end - start) +

Modified src/OFSHA1Hash.m from [595fab433e] to [d50a626d64].

159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199

- (void)updateWithBuffer: (const char*)buffer_
		  length: (size_t)length
{
	if (length == 0)
		return;

	if (isCalculated)
		@throw [OFHashAlreadyCalculatedException newWithClass: isa
								 hash: self];

	sha1_update(state, &count, buffer, buffer_, length);
}

- (uint8_t*)digest
{
	size_t i;
	char   finalcount[8];

	if (isCalculated)
		return digest;

	for (i = 0; i < 8; i++)
		/* Endian independent */
		finalcount[i] = (char)((count >> ((7 - (i & 7)) * 8)) & 255);
	sha1_update(state, &count, buffer, "\200", 1);

	while ((count & 504) != 448)
		sha1_update(state, &count, buffer, "\0", 1);
	/* Should cause a sha1_transform() */
	sha1_update(state, &count, buffer, finalcount, 8);

	for (i = 0; i < OF_SHA1_DIGEST_SIZE; i++)
		digest[i] = (char)((state[i >> 2] >>
		    ((3 - (i & 3)) * 8)) & 255);

	isCalculated = YES;

	return digest;
}
@end







|











|
















|




159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199

- (void)updateWithBuffer: (const char*)buffer_
		  length: (size_t)length
{
	if (length == 0)
		return;

	if (calculated)
		@throw [OFHashAlreadyCalculatedException newWithClass: isa
								 hash: self];

	sha1_update(state, &count, buffer, buffer_, length);
}

- (uint8_t*)digest
{
	size_t i;
	char   finalcount[8];

	if (calculated)
		return digest;

	for (i = 0; i < 8; i++)
		/* Endian independent */
		finalcount[i] = (char)((count >> ((7 - (i & 7)) * 8)) & 255);
	sha1_update(state, &count, buffer, "\200", 1);

	while ((count & 504) != 448)
		sha1_update(state, &count, buffer, "\0", 1);
	/* Should cause a sha1_transform() */
	sha1_update(state, &count, buffer, finalcount, 8);

	for (i = 0; i < OF_SHA1_DIGEST_SIZE; i++)
		digest[i] = (char)((state[i >> 2] >>
		    ((3 - (i & 3)) * 8)) & 255);

	calculated = YES;

	return digest;
}
@end

Modified src/OFStream.h from [cfff676663] to [d46e5522c2].

32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
 */
@interface OFStream: OFObject
{
	char   *cache;
	char   *writeBuffer;
	size_t cacheLength, writeBufferLength;
	BOOL   buffersWrites;
	BOOL   isBlocking;
}

#ifdef OF_HAVE_PROPERTIES
@property (assign, setter=setBlocking:) BOOL isBlocking;
#endif

/**
 * \brief Returns a boolean whether the end of the stream has been reached.
 *
 * \return A boolean whether the end of the stream has been reached
 */







|



|







32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
 */
@interface OFStream: OFObject
{
	char   *cache;
	char   *writeBuffer;
	size_t cacheLength, writeBufferLength;
	BOOL   buffersWrites;
	BOOL   blocking;
}

#ifdef OF_HAVE_PROPERTIES
@property (assign, getter=isBlocking) BOOL blocking;
#endif

/**
 * \brief Returns a boolean whether the end of the stream has been reached.
 *
 * \return A boolean whether the end of the stream has been reached
 */

Modified src/OFStream.m from [c69f9cbafe] to [69277f1386].

61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
						      selector: _cmd];
	}

	self = [super init];

	cache = NULL;
	writeBuffer = NULL;
	isBlocking = YES;

	return self;
}

- (BOOL)_isAtEndOfStream
{
	@throw [OFNotImplementedException newWithClass: isa







|







61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
						      selector: _cmd];
	}

	self = [super init];

	cache = NULL;
	writeBuffer = NULL;
	blocking = YES;

	return self;
}

- (BOOL)_isAtEndOfStream
{
	@throw [OFNotImplementedException newWithClass: isa
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
- (size_t)pendingBytes
{
	return cacheLength;
}

- (BOOL)isBlocking
{
	return isBlocking;
}

- (void)setBlocking: (BOOL)enable
{
#ifndef _WIN32
	int flags;

	isBlocking = enable;

	if ((flags = fcntl([self fileDescriptor], F_GETFL)) == -1)
		@throw [OFSetOptionFailedException newWithClass: isa
							 stream: self];

	if (enable)
		flags &= ~O_NONBLOCK;







|







|







1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
- (size_t)pendingBytes
{
	return cacheLength;
}

- (BOOL)isBlocking
{
	return blocking;
}

- (void)setBlocking: (BOOL)enable
{
#ifndef _WIN32
	int flags;

	blocking = enable;

	if ((flags = fcntl([self fileDescriptor], F_GETFL)) == -1)
		@throw [OFSetOptionFailedException newWithClass: isa
							 stream: self];

	if (enable)
		flags &= ~O_NONBLOCK;

Modified src/OFStreamSocket.h from [5c1c43e4cb] to [da1c953ac3].

25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41

/**
 * \brief A class which provides functions to create and use stream sockets.
 */
@interface OFStreamSocket: OFStream
{
	int  sock;
	BOOL isAtEndOfStream;
}

/**
 * \brief Returns a new, autoreleased OFTCPSocket.
 *
 * \return A new, autoreleased OFTCPSocket
 */
+ socket;
@end







|









25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41

/**
 * \brief A class which provides functions to create and use stream sockets.
 */
@interface OFStreamSocket: OFStream
{
	int  sock;
	BOOL atEndOfStream;
}

/**
 * \brief Returns a new, autoreleased OFTCPSocket.
 *
 * \return A new, autoreleased OFTCPSocket
 */
+ socket;
@end

Modified src/OFStreamSocket.m from [35ae964d9d] to [dffe75edba].

62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
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
+ socket
{
	return [[[self alloc] init] autorelease];
}

- (BOOL)_isAtEndOfStream
{
	return isAtEndOfStream;
}

- (size_t)_readNBytes: (size_t)length
	   intoBuffer: (void*)buffer
{
	ssize_t ret;

	if (sock == INVALID_SOCKET)
		@throw [OFNotConnectedException newWithClass: isa
						      socket: self];

	if (isAtEndOfStream) {
		OFReadFailedException *e;

		e = [OFReadFailedException newWithClass: isa
						 stream: self
					requestedLength: length];
#ifndef _WIN32
		e->errNo = ENOTCONN;
#else
		e->errNo = WSAENOTCONN;
#endif

		@throw e;
	}

	if ((ret = recv(sock, buffer, length, 0)) < 0)
		@throw [OFReadFailedException newWithClass: isa
						    stream: self
					   requestedLength: length];

	if (ret == 0)
		isAtEndOfStream = YES;

	return ret;
}

- (void)_writeNBytes: (size_t)length
	  fromBuffer: (const void*)buffer
{
	if (sock == INVALID_SOCKET)
		@throw [OFNotConnectedException newWithClass: isa
						      socket: self];

	if (isAtEndOfStream) {
		OFWriteFailedException *e;

		e = [OFWriteFailedException newWithClass: isa
						  stream: self
					 requestedLength: length];
#ifndef _WIN32
		e->errNo = ENOTCONN;







|











|




















|











|







62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
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
+ socket
{
	return [[[self alloc] init] autorelease];
}

- (BOOL)_isAtEndOfStream
{
	return atEndOfStream;
}

- (size_t)_readNBytes: (size_t)length
	   intoBuffer: (void*)buffer
{
	ssize_t ret;

	if (sock == INVALID_SOCKET)
		@throw [OFNotConnectedException newWithClass: isa
						      socket: self];

	if (atEndOfStream) {
		OFReadFailedException *e;

		e = [OFReadFailedException newWithClass: isa
						 stream: self
					requestedLength: length];
#ifndef _WIN32
		e->errNo = ENOTCONN;
#else
		e->errNo = WSAENOTCONN;
#endif

		@throw e;
	}

	if ((ret = recv(sock, buffer, length, 0)) < 0)
		@throw [OFReadFailedException newWithClass: isa
						    stream: self
					   requestedLength: length];

	if (ret == 0)
		atEndOfStream = YES;

	return ret;
}

- (void)_writeNBytes: (size_t)length
	  fromBuffer: (const void*)buffer
{
	if (sock == INVALID_SOCKET)
		@throw [OFNotConnectedException newWithClass: isa
						      socket: self];

	if (atEndOfStream) {
		OFWriteFailedException *e;

		e = [OFWriteFailedException newWithClass: isa
						  stream: self
					 requestedLength: length];
#ifndef _WIN32
		e->errNo = ENOTCONN;
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
					    requestedLength: length];
}

#ifdef _WIN32
- (void)setBlocking: (BOOL)enable
{
	u_long v = enable;
	isBlocking = enable;

	if (ioctlsocket(sock, FIONBIO, &v) == SOCKET_ERROR)
		@throw [OFSetOptionFailedException newWithClass: isa
							 stream: self];
}
#endif








|







132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
					    requestedLength: length];
}

#ifdef _WIN32
- (void)setBlocking: (BOOL)enable
{
	u_long v = enable;
	blocking = enable;

	if (ioctlsocket(sock, FIONBIO, &v) == SOCKET_ERROR)
		@throw [OFSetOptionFailedException newWithClass: isa
							 stream: self];
}
#endif

154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
	if (sock == INVALID_SOCKET)
		@throw [OFNotConnectedException newWithClass: isa
						      socket: self];

	close(sock);

	sock = INVALID_SOCKET;
	isAtEndOfStream = NO;
}

- (void)dealloc
{
	if (sock != INVALID_SOCKET)
		[self close];

	[super dealloc];
}
@end







|










154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
	if (sock == INVALID_SOCKET)
		@throw [OFNotConnectedException newWithClass: isa
						      socket: self];

	close(sock);

	sock = INVALID_SOCKET;
	atEndOfStream = NO;
}

- (void)dealloc
{
	if (sock != INVALID_SOCKET)
		[self close];

	[super dealloc];
}
@end

Modified src/OFString.h from [1581ec724e] to [dc6e0953b2].

83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
	 * for each constant string. We change the const char* to point to our
	 * struct on the first call to a constant string so we can have more
	 * than those two ivars.
	 */
	struct of_string_ivars {
		char   *cString;
		size_t cStringLength;
		BOOL   isUTF8;
		size_t length;
	} *restrict s;
	/*
	 * Unused in OFString, however, OFConstantString sets this to SIZE_MAX
	 * once it allocated and initialized the struct.
	 */
	size_t initialized;







|







83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
	 * for each constant string. We change the const char* to point to our
	 * struct on the first call to a constant string so we can have more
	 * than those two ivars.
	 */
	struct of_string_ivars {
		char   *cString;
		size_t cStringLength;
		BOOL   UTF8;
		size_t length;
	} *restrict s;
	/*
	 * Unused in OFString, however, OFConstantString sets this to SIZE_MAX
	 * once it allocated and initialized the struct.
	 */
	size_t initialized;

Modified src/OFString.m from [ba997373bf] to [1e80f1fdb6].

82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
	return OF_ORDERED_SAME;
}

int
of_string_check_utf8(const char *cString, size_t cStringLength, size_t *length)
{
	size_t i, tmpLength = cStringLength;
	int isUTF8 = 0;

	madvise((void*)cString, cStringLength, MADV_SEQUENTIAL);

	for (i = 0; i < cStringLength; i++) {
		/* No sign of UTF-8 here */
		if (OF_LIKELY(!(cString[i] & 0x80)))
			continue;

		isUTF8 = 1;

		/* We're missing a start byte here */
		if (OF_UNLIKELY(!(cString[i] & 0x40))) {
			madvise((void*)cString, cStringLength, MADV_NORMAL);
			return -1;
		}








|








|







82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
	return OF_ORDERED_SAME;
}

int
of_string_check_utf8(const char *cString, size_t cStringLength, size_t *length)
{
	size_t i, tmpLength = cStringLength;
	int UTF8 = 0;

	madvise((void*)cString, cStringLength, MADV_SEQUENTIAL);

	for (i = 0; i < cStringLength; i++) {
		/* No sign of UTF-8 here */
		if (OF_LIKELY(!(cString[i] & 0x80)))
			continue;

		UTF8 = 1;

		/* We're missing a start byte here */
		if (OF_UNLIKELY(!(cString[i] & 0x40))) {
			madvise((void*)cString, cStringLength, MADV_NORMAL);
			return -1;
		}

158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
	}

	madvise((void*)cString, cStringLength, MADV_NORMAL);

	if (length != NULL)
		*length = tmpLength;

	return isUTF8;
}

size_t
of_string_unicode_to_utf8(of_unichar_t character, char *buffer)
{
	size_t i = 0;








|







158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
	}

	madvise((void*)cString, cStringLength, MADV_NORMAL);

	if (length != NULL)
		*length = tmpLength;

	return UTF8;
}

size_t
of_string_unicode_to_utf8(of_unichar_t character, char *buffer)
{
	size_t i = 0;

496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
			switch (of_string_check_utf8(cString, cStringLength,
			    &s->length)) {
			case 1:
				if (encoding == OF_STRING_ENCODING_ASCII)
					@throw [OFInvalidEncodingException
					    newWithClass: isa];

				s->isUTF8 = YES;
				break;
			case -1:
				@throw [OFInvalidEncodingException
				    newWithClass: isa];
			}

			memcpy(s->cString, cString, cStringLength);







|







496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
			switch (of_string_check_utf8(cString, cStringLength,
			    &s->length)) {
			case 1:
				if (encoding == OF_STRING_ENCODING_ASCII)
					@throw [OFInvalidEncodingException
					    newWithClass: isa];

				s->UTF8 = YES;
				break;
			case -1:
				@throw [OFInvalidEncodingException
				    newWithClass: isa];
			}

			memcpy(s->cString, cString, cStringLength);
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
				size_t bytes;

				if (!(cString[i] & 0x80)) {
					s->cString[j++] = cString[i];
					continue;
				}

				s->isUTF8 = YES;
				bytes = of_string_unicode_to_utf8(
				    (uint8_t)cString[i], buffer);

				if (bytes == 0)
					@throw [OFInvalidEncodingException
					    newWithClass: isa];








|







522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
				size_t bytes;

				if (!(cString[i] & 0x80)) {
					s->cString[j++] = cString[i];
					continue;
				}

				s->UTF8 = YES;
				bytes = of_string_unicode_to_utf8(
				    (uint8_t)cString[i], buffer);

				if (bytes == 0)
					@throw [OFInvalidEncodingException
					    newWithClass: isa];

571
572
573
574
575
576
577
578
579
580
581
582
583
584
585

			character = table[(uint8_t)cString[i]];

			if (character == 0xFFFD)
				@throw [OFInvalidEncodingException
				    newWithClass: isa];

			s->isUTF8 = YES;
			characterBytes = of_string_unicode_to_utf8(character,
			    buffer);

			if (characterBytes == 0)
				@throw [OFInvalidEncodingException
				    newWithClass: isa];








|







571
572
573
574
575
576
577
578
579
580
581
582
583
584
585

			character = table[(uint8_t)cString[i]];

			if (character == 0xFFFD)
				@throw [OFInvalidEncodingException
				    newWithClass: isa];

			s->UTF8 = YES;
			characterBytes = of_string_unicode_to_utf8(character,
			    buffer);

			if (characterBytes == 0)
				@throw [OFInvalidEncodingException
				    newWithClass: isa];

609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
		memset(s, 0, sizeof(*s));

		/*
		 * We need one call to make sure it's initialized (in case it's
		 * a constant string).
		 */
		s->cStringLength = [string UTF8StringLength];
		s->isUTF8 = string->s->isUTF8;
		s->length = string->s->length;

		s->cString = [self allocMemoryWithSize: s->cStringLength + 1];
		memcpy(s->cString, string->s->cString, s->cStringLength + 1);
	} @catch (id e) {
		[self release];
		@throw e;







|







609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
		memset(s, 0, sizeof(*s));

		/*
		 * We need one call to make sure it's initialized (in case it's
		 * a constant string).
		 */
		s->cStringLength = [string UTF8StringLength];
		s->UTF8 = string->s->UTF8;
		s->length = string->s->length;

		s->cString = [self allocMemoryWithSize: s->cStringLength + 1];
		memcpy(s->cString, string->s->cString, s->cStringLength + 1);
	} @catch (id e) {
		[self release];
		@throw e;
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
			    buffer);

			switch (characterLen) {
			case 1:
				s->cString[j++] = buffer[0];
				break;
			case 2:
				s->isUTF8 = YES;
				s->cStringLength++;

				memcpy(s->cString + j, buffer, 2);
				j += 2;

				break;
			case 3:
				s->isUTF8 = YES;
				s->cStringLength += 2;

				memcpy(s->cString + j, buffer, 3);
				j += 3;

				break;
			case 4:
				s->isUTF8 = YES;
				s->cStringLength += 3;

				memcpy(s->cString + j, buffer, 4);
				j += 4;

				break;
			default:







|







|







|







683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
			    buffer);

			switch (characterLen) {
			case 1:
				s->cString[j++] = buffer[0];
				break;
			case 2:
				s->UTF8 = YES;
				s->cStringLength++;

				memcpy(s->cString + j, buffer, 2);
				j += 2;

				break;
			case 3:
				s->UTF8 = YES;
				s->cStringLength += 2;

				memcpy(s->cString + j, buffer, 3);
				j += 3;

				break;
			case 4:
				s->UTF8 = YES;
				s->cStringLength += 3;

				memcpy(s->cString + j, buffer, 4);
				j += 4;

				break;
			default:
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
			    character, buffer);

			switch (characterLen) {
			case 1:
				s->cString[j++] = buffer[0];
				break;
			case 2:
				s->isUTF8 = YES;
				s->cStringLength++;

				memcpy(s->cString + j, buffer, 2);
				j += 2;

				break;
			case 3:
				s->isUTF8 = YES;
				s->cStringLength += 2;

				memcpy(s->cString + j, buffer, 3);
				j += 3;

				break;
			case 4:
				s->isUTF8 = YES;
				s->cStringLength += 3;

				memcpy(s->cString + j, buffer, 4);
				j += 4;

				break;
			default:







|







|







|







816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
			    character, buffer);

			switch (characterLen) {
			case 1:
				s->cString[j++] = buffer[0];
				break;
			case 2:
				s->UTF8 = YES;
				s->cStringLength++;

				memcpy(s->cString + j, buffer, 2);
				j += 2;

				break;
			case 3:
				s->UTF8 = YES;
				s->cStringLength += 2;

				memcpy(s->cString + j, buffer, 3);
				j += 3;

				break;
			case 4:
				s->UTF8 = YES;
				s->cStringLength += 3;

				memcpy(s->cString + j, buffer, 4);
				j += 4;

				break;
			default:
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914

		s->cStringLength = cStringLength;

		@try {
			switch (of_string_check_utf8(s->cString,
			    cStringLength, &s->length)) {
			case 1:
				s->isUTF8 = YES;
				break;
			case -1:
				@throw [OFInvalidEncodingException
				    newWithClass: isa];
			}

			[self addMemoryToPool: s->cString];







|







900
901
902
903
904
905
906
907
908
909
910
911
912
913
914

		s->cStringLength = cStringLength;

		@try {
			switch (of_string_check_utf8(s->cString,
			    cStringLength, &s->length)) {
			case 1:
				s->UTF8 = YES;
				break;
			case -1:
				@throw [OFInvalidEncodingException
				    newWithClass: isa];
			}

			[self addMemoryToPool: s->cString];
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
		memset(s, 0, sizeof(*s));

		/*
		 * First needs to be a call to be sure it is initialized, in
		 * case it's a constant string.
		 */
		s->cStringLength = [firstComponent UTF8StringLength];
		s->isUTF8 = firstComponent->s->isUTF8;
		s->length = firstComponent->s->length;

		/* Calculate length and see if we need UTF-8 */
		va_copy(argumentsCopy, arguments);
		while ((component = va_arg(argumentsCopy, OFString*)) != nil) {
			/* First needs to be a call, see above */
			s->cStringLength += 1 + [component UTF8StringLength];
			s->length += 1 + component->s->length;

			if (component->s->isUTF8)
				s->isUTF8 = YES;
		}

		s->cString = [self allocMemoryWithSize: s->cStringLength + 1];

		cStringLength = [firstComponent UTF8StringLength];
		memcpy(s->cString, [firstComponent UTF8String], cStringLength);
		i = cStringLength;







|









|
|







950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
		memset(s, 0, sizeof(*s));

		/*
		 * First needs to be a call to be sure it is initialized, in
		 * case it's a constant string.
		 */
		s->cStringLength = [firstComponent UTF8StringLength];
		s->UTF8 = firstComponent->s->UTF8;
		s->length = firstComponent->s->length;

		/* Calculate length and see if we need UTF-8 */
		va_copy(argumentsCopy, arguments);
		while ((component = va_arg(argumentsCopy, OFString*)) != nil) {
			/* First needs to be a call, see above */
			s->cStringLength += 1 + [component UTF8StringLength];
			s->length += 1 + component->s->length;

			if (component->s->UTF8)
				s->UTF8 = YES;
		}

		s->cString = [self allocMemoryWithSize: s->cStringLength + 1];

		cStringLength = [firstComponent UTF8StringLength];
		memcpy(s->cString, [firstComponent UTF8String], cStringLength);
		i = cStringLength;
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153

- (const char*)cStringWithEncoding: (of_string_encoding_t)encoding
{
	switch (encoding) {
	case OF_STRING_ENCODING_UTF_8:
		return s->cString;
	case OF_STRING_ENCODING_ASCII:
		if (s->isUTF8)
			@throw [OFInvalidEncodingException newWithClass: isa];

		return s->cString;
	default:
		@throw [OFNotImplementedException newWithClass: isa
						      selector: _cmd];
	}







|







1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153

- (const char*)cStringWithEncoding: (of_string_encoding_t)encoding
{
	switch (encoding) {
	case OF_STRING_ENCODING_UTF_8:
		return s->cString;
	case OF_STRING_ENCODING_ASCII:
		if (s->UTF8)
			@throw [OFInvalidEncodingException newWithClass: isa];

		return s->cString;
	default:
		@throw [OFNotImplementedException newWithClass: isa
						      selector: _cmd];
	}
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179

- (size_t)cStringLengthWithEncoding: (of_string_encoding_t)encoding
{
	switch (encoding) {
	case OF_STRING_ENCODING_UTF_8:
		return s->cStringLength;
	case OF_STRING_ENCODING_ASCII:
		if (s->isUTF8)
			@throw [OFInvalidEncodingException newWithClass: isa];

		return s->cStringLength;
	default:
		@throw [OFNotImplementedException newWithClass: isa
						      selector: _cmd];
	}







|







1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179

- (size_t)cStringLengthWithEncoding: (of_string_encoding_t)encoding
{
	switch (encoding) {
	case OF_STRING_ENCODING_UTF_8:
		return s->cStringLength;
	case OF_STRING_ENCODING_ASCII:
		if (s->UTF8)
			@throw [OFInvalidEncodingException newWithClass: isa];

		return s->cStringLength;
	default:
		@throw [OFNotImplementedException newWithClass: isa
						      selector: _cmd];
	}
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
	if (![otherString isKindOfClass: [OFString class]])
		@throw [OFInvalidArgumentException newWithClass: isa
						       selector: _cmd];

	otherCString = [otherString UTF8String];
	otherCStringLength = [otherString UTF8StringLength];

	if (!s->isUTF8) {
		minimumCStringLength = (s->cStringLength > otherCStringLength
		    ? otherCStringLength : s->cStringLength);

		if ((compare = memcasecmp(s->cString, otherCString,
		    minimumCStringLength)) == 0) {
			if (s->cStringLength > otherCStringLength)
				return OF_ORDERED_DESCENDING;







|







1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
	if (![otherString isKindOfClass: [OFString class]])
		@throw [OFInvalidArgumentException newWithClass: isa
						       selector: _cmd];

	otherCString = [otherString UTF8String];
	otherCStringLength = [otherString UTF8StringLength];

	if (!s->UTF8) {
		minimumCStringLength = (s->cStringLength > otherCStringLength
		    ? otherCStringLength : s->cStringLength);

		if ((compare = memcasecmp(s->cString, otherCString,
		    minimumCStringLength)) == 0) {
			if (s->cStringLength > otherCStringLength)
				return OF_ORDERED_DESCENDING;
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
- (of_unichar_t)characterAtIndex: (size_t)index
{
	of_unichar_t character;

	if (index >= s->length)
		@throw [OFOutOfRangeException newWithClass: isa];

	if (!s->isUTF8)
		return s->cString[index];

	index = of_string_index_to_position(s->cString, index,
	    s->cStringLength);

	if (!of_string_utf8_to_unicode(s->cString + index,
	    s->cStringLength - index, &character))







|







1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
- (of_unichar_t)characterAtIndex: (size_t)index
{
	of_unichar_t character;

	if (index >= s->length)
		@throw [OFOutOfRangeException newWithClass: isa];

	if (!s->UTF8)
		return s->cString[index];

	index = of_string_index_to_position(s->cString, index,
	    s->cStringLength);

	if (!of_string_utf8_to_unicode(s->cString + index,
	    s->cStringLength - index, &character))
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
{
	size_t start = range.start;
	size_t end = range.start + range.length;

	if (end > s->length)
		@throw [OFOutOfRangeException newWithClass: isa];

	if (s->isUTF8) {
		start = of_string_index_to_position(s->cString, start,
		    s->cStringLength);
		end = of_string_index_to_position(s->cString, end,
		    s->cStringLength);
	}

	return [OFString stringWithUTF8String: s->cString + start







|







1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
{
	size_t start = range.start;
	size_t end = range.start + range.length;

	if (end > s->length)
		@throw [OFOutOfRangeException newWithClass: isa];

	if (s->UTF8) {
		start = of_string_index_to_position(s->cString, start,
		    s->cStringLength);
		end = of_string_index_to_position(s->cString, end,
		    s->cStringLength);
	}

	return [OFString stringWithUTF8String: s->cString + start

Modified src/OFTCPSocket.h from [f9ba7e8037] to [d3fc0d3305].

32
33
34
35
36
37
38
39
40
41
42




43
44
45
46
47
48
49
 * \brief A class which provides functions to create and use TCP sockets.
 *
 * To connect to a server, create a socket and connect it.
 * To create a server, create a socket, bind it and listen on it.
 */
@interface OFTCPSocket: OFStreamSocket
{
	BOOL			isListening;
	struct sockaddr_storage	*sockAddr;
	socklen_t		sockAddrLen;
}





/**
 * \brief Connect the OFTCPSocket to the specified destination.
 *
 * \param host The host to connect to
 * \param port The port on the host to connect to
 */







|



>
>
>
>







32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
 * \brief A class which provides functions to create and use TCP sockets.
 *
 * To connect to a server, create a socket and connect it.
 * To create a server, create a socket, bind it and listen on it.
 */
@interface OFTCPSocket: OFStreamSocket
{
	BOOL			listening;
	struct sockaddr_storage	*sockAddr;
	socklen_t		sockAddrLen;
}

#ifdef OF_HAVE_PROPERTIES
@property (assign, readonly, getter=isBlocking) BOOL *listening;
#endif

/**
 * \brief Connect the OFTCPSocket to the specified destination.
 *
 * \param host The host to connect to
 * \param port The port on the host to connect to
 */

Modified src/OFTCPSocket.m from [0cc2514733] to [ad3ac403d1].

331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
						      socket: self];

	if (listen(sock, backLog) == -1)
		@throw [OFListenFailedException newWithClass: isa
						      socket: self
						     backLog: backLog];

	isListening = YES;
}

- (void)listen
{
	if (sock == INVALID_SOCKET)
		@throw [OFNotConnectedException newWithClass: isa
						      socket: self];

	if (listen(sock, 5) == -1)
		@throw [OFListenFailedException newWithClass: isa
						      socket: self
						     backLog: 5];

	isListening = YES;
}

- (OFTCPSocket*)accept
{
	OFTCPSocket *newSocket;
	struct sockaddr_storage *addr;
	socklen_t addrLen;







|













|







331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
						      socket: self];

	if (listen(sock, backLog) == -1)
		@throw [OFListenFailedException newWithClass: isa
						      socket: self
						     backLog: backLog];

	listening = YES;
}

- (void)listen
{
	if (sock == INVALID_SOCKET)
		@throw [OFNotConnectedException newWithClass: isa
						      socket: self];

	if (listen(sock, 5) == -1)
		@throw [OFListenFailedException newWithClass: isa
						      socket: self
						     backLog: 5];

	listening = YES;
}

- (OFTCPSocket*)accept
{
	OFTCPSocket *newSocket;
	struct sockaddr_storage *addr;
	socklen_t addrLen;
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456

	/* Get rid of a warning, never reached anyway */
	assert(0);
}

- (BOOL)isListening
{
	return isListening;
}

- (void)close
{
	[super close];

	isListening = NO;
	[self freeMemory: sockAddr];
	sockAddr = NULL;
	sockAddrLen = 0;
}
@end







|






|





437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456

	/* Get rid of a warning, never reached anyway */
	assert(0);
}

- (BOOL)isListening
{
	return listening;
}

- (void)close
{
	[super close];

	listening = NO;
	[self freeMemory: sockAddr];
	sockAddr = NULL;
	sockAddrLen = 0;
}
@end