1
2
3
4
5
6
7
8
9
|
/*
* Copyright (c) 2008-2021 Jonathan Schleifer <js@nil.im>
*
* All rights reserved.
*
* This file is part of ObjFW. It may be distributed under the terms of the
* Q Public License 1.0, which can be found in the file LICENSE.QPL included in
* the packaging of this file.
*
|
|
|
1
2
3
4
5
6
7
8
9
|
/*
* Copyright (c) 2008-2022 Jonathan Schleifer <js@nil.im>
*
* All rights reserved.
*
* This file is part of ObjFW. It may be distributed under the terms of the
* Q Public License 1.0, which can be found in the file LICENSE.QPL included in
* the packaging of this file.
*
|
︙ | | | ︙ | |
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
#endif
#import "OFSortedList.h"
#import "OFTimer.h"
#import "OFTimer+Private.h"
#import "OFDate.h"
#import "OFObserveFailedException.h"
const OFRunLoopMode OFDefaultRunLoopMode = @"OFDefaultRunLoopMode";
static OFRunLoop *mainRunLoop = nil;
@interface OFRunLoopState: OFObject
#ifdef OF_HAVE_SOCKETS
<OFKernelEventObserverDelegate>
#endif
{
|
>
>
|
|
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
#endif
#import "OFSortedList.h"
#import "OFTimer.h"
#import "OFTimer+Private.h"
#import "OFDate.h"
#import "OFObserveFailedException.h"
#import "OFWriteFailedException.h"
#include "OFRunLoopConstants.inc"
static OFRunLoop *mainRunLoop = nil;
@interface OFRunLoopState: OFObject
#ifdef OF_HAVE_SOCKETS
<OFKernelEventObserverDelegate>
#endif
{
|
︙ | | | ︙ | |
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
|
size_t length;
id exception = nil;
size_t dataLength = _data.count * _data.itemSize;
OFData *newData, *oldData;
@try {
const char *dataItems = _data.items;
length = [object writeBuffer: dataItems + _writtenLength
length: dataLength - _writtenLength];
} @catch (id e) {
length = 0;
exception = e;
}
_writtenLength += length;
if (_writtenLength != dataLength && exception == nil)
return true;
# ifdef OF_HAVE_BLOCKS
if (_block != NULL) {
newData = _block(_data, _writtenLength, exception);
if (newData == nil)
return false;
oldData = _data;
_data = [newData copy];
[oldData release];
|
|
|
>
>
|
>
>
>
|
|
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
|
size_t length;
id exception = nil;
size_t dataLength = _data.count * _data.itemSize;
OFData *newData, *oldData;
@try {
const char *dataItems = _data.items;
length = dataLength - _writtenLength;
[object writeBuffer: dataItems + _writtenLength length: length];
} @catch (OFWriteFailedException *e) {
length = e.bytesWritten;
if (e.errNo != EWOULDBLOCK && e.errNo != EAGAIN)
exception = e;
} @catch (id e) {
length = 0;
exception = e;
}
_writtenLength += length;
OFEnsure(_writtenLength <= dataLength);
if (_writtenLength != dataLength && exception == nil)
return true;
# ifdef OF_HAVE_BLOCKS
if (_block != NULL) {
newData = _block(_writtenLength, exception);
if (newData == nil)
return false;
oldData = _data;
_data = [newData copy];
[oldData release];
|
︙ | | | ︙ | |
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
|
size_t length;
id exception = nil;
size_t cStringLength = [_string cStringLengthWithEncoding: _encoding];
OFString *newString, *oldString;
@try {
const char *cString = [_string cStringWithEncoding: _encoding];
length = [object writeBuffer: cString + _writtenLength
length: cStringLength - _writtenLength];
} @catch (id e) {
length = 0;
exception = e;
}
_writtenLength += length;
if (_writtenLength != cStringLength && exception == nil)
return true;
# ifdef OF_HAVE_BLOCKS
if (_block != NULL) {
newString = _block(_string, _writtenLength, exception);
if (newString == nil)
return false;
oldString = _string;
_string = [newString copy];
[oldString release];
|
|
|
>
>
|
>
>
>
|
|
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
|
size_t length;
id exception = nil;
size_t cStringLength = [_string cStringLengthWithEncoding: _encoding];
OFString *newString, *oldString;
@try {
const char *cString = [_string cStringWithEncoding: _encoding];
length = cStringLength - _writtenLength;
[object writeBuffer: cString + _writtenLength length: length];
} @catch (OFWriteFailedException *e) {
length = e.bytesWritten;
if (e.errNo != EWOULDBLOCK && e.errNo != EAGAIN)
exception = e;
} @catch (id e) {
length = 0;
exception = e;
}
_writtenLength += length;
OFEnsure(_writtenLength <= cStringLength);
if (_writtenLength != cStringLength && exception == nil)
return true;
# ifdef OF_HAVE_BLOCKS
if (_block != NULL) {
newString = _block(_writtenLength, exception);
if (newString == nil)
return false;
oldString = _string;
_string = [newString copy];
[oldString release];
|
︙ | | | ︙ | |
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
|
receiver: &_receiver];
} @catch (id e) {
exception = e;
}
# ifdef OF_HAVE_BLOCKS
if (_block != NULL) {
newData = _block(_data, &_receiver, exception);
if (newData == nil)
return false;
oldData = _data;
_data = [newData copy];
[oldData release];
|
|
|
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
|
receiver: &_receiver];
} @catch (id e) {
exception = e;
}
# ifdef OF_HAVE_BLOCKS
if (_block != NULL) {
newData = _block(exception);
if (newData == nil)
return false;
oldData = _data;
_data = [newData copy];
[oldData release];
|
︙ | | | ︙ | |
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
|
length: _data.count * _data.itemSize];
} @catch (id e) {
exception = e;
}
# ifdef OF_HAVE_BLOCKS
if (_block != NULL) {
newData = _block(_data, exception);
if (newData == nil)
return false;
oldData = _data;
_data = [newData copy];
[oldData release];
|
|
|
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
|
length: _data.count * _data.itemSize];
} @catch (id e) {
exception = e;
}
# ifdef OF_HAVE_BLOCKS
if (_block != NULL) {
newData = _block(exception);
if (newData == nil)
return false;
oldData = _data;
_data = [newData copy];
[oldData release];
|
︙ | | | ︙ | |
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
|
#endif
}
- (void)of_removeTimer: (OFTimer *)timer forMode: (OFRunLoopMode)mode
{
OFRunLoopState *state = stateForMode(self, mode, false);
if (state == nil)
return;
#ifdef OF_HAVE_THREADS
[state->_timersQueueMutex lock];
@try {
#endif
for (OFListItem iter = state->_timersQueue.firstListItem;
iter != NULL; iter = OFListItemNext(iter)) {
|
>
|
>
|
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
|
#endif
}
- (void)of_removeTimer: (OFTimer *)timer forMode: (OFRunLoopMode)mode
{
OFRunLoopState *state = stateForMode(self, mode, false);
/* {} required to avoid -Wmisleading-indentation false positive. */
if (state == nil) {
return;
}
#ifdef OF_HAVE_THREADS
[state->_timersQueueMutex lock];
@try {
#endif
for (OFListItem iter = state->_timersQueue.firstListItem;
iter != NULL; iter = OFListItemNext(iter)) {
|
︙ | | | ︙ | |