ObjFW  Diff

Differences From Artifact [bb57582da1]:

To Artifact [3a3eebc79f]:


35
36
37
38
39
40
41

42
43
44
45
46
47
48
#import "OFString.h"
#import "OFDataArray.h"
#import "OFSystemInfo.h"
#import "OFRunLoop.h"

#import "OFInvalidArgumentException.h"
#import "OFInvalidFormatException.h"

#import "OFSetOptionFailedException.h"

#import "macros.h"
#import "of_asprintf.h"

@implementation OFStream
#ifndef _WIN32







>







35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#import "OFString.h"
#import "OFDataArray.h"
#import "OFSystemInfo.h"
#import "OFRunLoop.h"

#import "OFInvalidArgumentException.h"
#import "OFInvalidFormatException.h"
#import "OFNotImplementedException.h"
#import "OFSetOptionFailedException.h"

#import "macros.h"
#import "of_asprintf.h"

@implementation OFStream
#ifndef _WIN32
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
- copy
{
	return [self retain];
}

- (BOOL)isAtEndOfStream
{
	if (cache != NULL)
		return NO;

	return [self lowlevelIsAtEndOfStream];
}

- (size_t)readIntoBuffer: (void*)buffer
		  length: (size_t)length
{
	if (cache == NULL)
		return [self lowlevelReadIntoBuffer: buffer
					     length: length];

	if (length >= cacheLength) {
		size_t ret = cacheLength;
		memcpy(buffer, cache, cacheLength);








|








|







98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
- copy
{
	return [self retain];
}

- (BOOL)isAtEndOfStream
{
	if (cacheLength > 0)
		return NO;

	return [self lowlevelIsAtEndOfStream];
}

- (size_t)readIntoBuffer: (void*)buffer
		  length: (size_t)length
{
	if (cacheLength == 0)
		return [self lowlevelReadIntoBuffer: buffer
					     length: length];

	if (length >= cacheLength) {
		size_t ret = cacheLength;
		memcpy(buffer, cache, cacheLength);

1462
1463
1464
1465
1466
1467
1468



1469
1470
1471
1472

1473
1474
1475
1476
1477
1478
1479
1480
























1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491







1492
1493
1494
1495
1496
1497
1498
{
	return blocking;
}

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



	int readFlags, writeFlags;

	readFlags = fcntl([self fileDescriptorForReading], F_GETFL);
	writeFlags = fcntl([self fileDescriptorForWriting], F_GETFL);


	if (readFlags == -1 || writeFlags == -1)
		@throw [OFSetOptionFailedException
		    exceptionWithClass: [self class]
				stream: self];

	if (enable) {
		readFlags &= ~O_NONBLOCK;
























		writeFlags &= ~O_NONBLOCK;
	} else {
		readFlags |= O_NONBLOCK;
		writeFlags |= O_NONBLOCK;
	}

	if (fcntl([self fileDescriptorForReading], F_SETFL, readFlags) == -1 ||
	    fcntl([self fileDescriptorForWriting], F_SETFL, writeFlags) == -1)
		@throw [OFSetOptionFailedException
		    exceptionWithClass: [self class]
				stream: self];







#else
	[self doesNotRecognizeSelector: _cmd];
	abort();
#endif
}

- (int)fileDescriptorForReading







>
>
>
|

|
|
>

|
|
|
|

|
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
|
<
|
|
<
|
|
|
|
|
>
>
>
>
>
>
>







1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511

1512
1513

1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
{
	return blocking;
}

- (void)setBlocking: (BOOL)enable
{
#ifndef _WIN32
	BOOL readImplemented = NO, writeImplemented = NO;

	@try {
		int readFlags;

		readFlags = fcntl([self fileDescriptorForReading], F_GETFL);

		readImplemented = YES;

		if (readFlags == -1)
			@throw [OFSetOptionFailedException
			    exceptionWithClass: [self class]
					stream: self];

		if (enable)
			readFlags &= ~O_NONBLOCK;
		else
			readFlags |= O_NONBLOCK;

		if (fcntl([self fileDescriptorForReading], F_SETFL,
		    readFlags) == -1)
			@throw [OFSetOptionFailedException
			    exceptionWithClass: [self class]
					stream: self];
	} @catch (OFNotImplementedException *e) {
	}

	@try {
		int writeFlags;

		writeFlags = fcntl([self fileDescriptorForWriting], F_GETFL);

		writeImplemented = YES;

		if (writeFlags == -1)
			@throw [OFSetOptionFailedException
			    exceptionWithClass: [self class]
					stream: self];

		if (enable)
			writeFlags &= ~O_NONBLOCK;
		else

			writeFlags |= O_NONBLOCK;


		if (fcntl([self fileDescriptorForWriting], F_SETFL,
		    writeFlags) == -1)
			@throw [OFSetOptionFailedException
			    exceptionWithClass: [self class]
					stream: self];
	} @catch (OFNotImplementedException *e) {
	}

	if (!readImplemented && !writeImplemented)
		@throw [OFNotImplementedException
		    exceptionWithClass: [self class]
			      selector: _cmd];
#else
	[self doesNotRecognizeSelector: _cmd];
	abort();
#endif
}

- (int)fileDescriptorForReading