Skip to content

Commit c3c8a8a

Browse files
committed
Fixed dead-lock issue with GC on the New VM.
1 parent f132629 commit c3c8a8a

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

dist/CN1Sockets.cn1lib

86 Bytes
Binary file not shown.

native/ios/ca_weblite_codename1_net_impl_NativeSocketImpl.m

+24-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,18 @@
22

33
@implementation ca_weblite_codename1_net_impl_NativeSocketImpl
44

5+
static void _yield() {
6+
#ifdef NEW_CODENAME_ONE_VM
7+
CN1_YIELD_THREAD;
8+
#endif
9+
}
10+
11+
static void _resume() {
12+
#ifdef NEW_CODENAME_ONE_VM
13+
CN1_RESUME_THREAD;
14+
#endif
15+
}
16+
517
-(void)dealloc {
618
if ( inputStream != NULL ){
719
[inputStream release];
@@ -29,7 +41,9 @@ -(int)read{
2941
}
3042
errorMessage = NULL;
3143
uint8_t buf[1];
44+
_yield();
3245
int bytesRead = [inputStream read:buf maxLength:1];
46+
_resume();
3347
if ( bytesRead == -1 ){
3448
errorMessage = [[inputStream streamError] localizedDescription];
3549
return -2;
@@ -54,7 +68,9 @@ -(long long)skip:(long long)param{
5468
} else {
5569
bytesToRead = bufSize;
5670
}
71+
_yield();
5772
bytesRead = [inputStream read:buf maxLength:bytesToRead];
73+
_resume();
5874
if ( bytesRead == -1 ){
5975
errorMessage = [[inputStream streamError] localizedDescription];
6076
return -2;
@@ -91,8 +107,9 @@ -(BOOL)write:(int)param{
91107
errorMessage = NULL;
92108
uint8_t buf[1];
93109
buf[0] = (uint8_t)param;
94-
110+
_yield();
95111
NSInteger res = [outputStream write:buf maxLength:1];
112+
_resume();
96113
if ( res <= 0 ){
97114
errorMessage = [[outputStream streamError] localizedDescription];
98115
return NO;
@@ -154,7 +171,9 @@ -(int)readBuf:(int)len{
154171
errorMessage = @"Attempt to read byte array longer than the buffer.";
155172
return -2;
156173
}
174+
_yield();
157175
int bytesRead = [inputStream read:buffer maxLength:len];
176+
_resume();
158177
if ( bytesRead == -1 ){
159178
errorMessage = [[inputStream streamError] localizedDescription];
160179
return -2;
@@ -186,8 +205,9 @@ -(BOOL)createSocket:(NSString*)host param1:(int)port{
186205
isFinished = NO;
187206
CFReadStreamRef readStream;
188207
CFWriteStreamRef writeStream;
208+
_yield();
189209
CFStreamCreatePairWithSocketToHost(NULL, (CFStringRef)host, port, &readStream, &writeStream);
190-
210+
_resume();
191211
inputStream = (NSInputStream *)readStream;
192212
outputStream = (NSOutputStream *)writeStream;
193213

@@ -206,7 +226,9 @@ -(BOOL)closeSocket{
206226
-(BOOL)writeBuf:(NSData*)buffer{
207227
isFinished = NO;
208228
errorMessage = NULL;
229+
_yield();
209230
int bytesWritten = [outputStream write:(const uint8_t*)[buffer bytes] maxLength:[buffer length]];
231+
_resume();
210232
if ( bytesWritten == -1 ){
211233
errorMessage = [[outputStream streamError] localizedDescription];
212234
return NO;

0 commit comments

Comments
 (0)