@@ -1274,6 +1274,7 @@ - (BOOL)acceptOnInterface:(NSString *)inInterface port:(uint16_t)port error:(NSE
1274
1274
NSString *reason = @" Error enabling non-blocking IO on socket (fcntl)" ;
1275
1275
err = [self errnoErrorWithReason: reason];
1276
1276
1277
+ LogVerbose (@" close(socketFD)" );
1277
1278
close (socketFD);
1278
1279
return SOCKET_NULL;
1279
1280
}
@@ -1285,6 +1286,7 @@ - (BOOL)acceptOnInterface:(NSString *)inInterface port:(uint16_t)port error:(NSE
1285
1286
NSString *reason = @" Error enabling address reuse (setsockopt)" ;
1286
1287
err = [self errnoErrorWithReason: reason];
1287
1288
1289
+ LogVerbose (@" close(socketFD)" );
1288
1290
close (socketFD);
1289
1291
return SOCKET_NULL;
1290
1292
}
@@ -1297,6 +1299,7 @@ - (BOOL)acceptOnInterface:(NSString *)inInterface port:(uint16_t)port error:(NSE
1297
1299
NSString *reason = @" Error in bind() function" ;
1298
1300
err = [self errnoErrorWithReason: reason];
1299
1301
1302
+ LogVerbose (@" close(socketFD)" );
1300
1303
close (socketFD);
1301
1304
return SOCKET_NULL;
1302
1305
}
@@ -1309,6 +1312,7 @@ - (BOOL)acceptOnInterface:(NSString *)inInterface port:(uint16_t)port error:(NSE
1309
1312
NSString *reason = @" Error in listen() function" ;
1310
1313
err = [self errnoErrorWithReason: reason];
1311
1314
1315
+ LogVerbose (@" close(socketFD)" );
1312
1316
close (socketFD);
1313
1317
return SOCKET_NULL;
1314
1318
}
@@ -1425,6 +1429,7 @@ - (BOOL)acceptOnInterface:(NSString *)inInterface port:(uint16_t)port error:(NSE
1425
1429
{
1426
1430
if (socket4FD != SOCKET_NULL)
1427
1431
{
1432
+ LogVerbose (@" close(socket4FD)" );
1428
1433
close (socket4FD);
1429
1434
}
1430
1435
@@ -2362,7 +2367,6 @@ - (void)didNotConnect:(int)aConnectIndex error:(NSError *)error
2362
2367
return ;
2363
2368
}
2364
2369
2365
- [self endConnectTimeout ];
2366
2370
[self closeWithError: error];
2367
2371
}
2368
2372
@@ -2495,62 +2499,72 @@ - (void)closeWithError:(NSError *)error
2495
2499
// So we have to unpause the source if needed.
2496
2500
// This allows the cancel handler to be run, which in turn releases the source and closes the socket.
2497
2501
2498
- if (accept4Source)
2499
- {
2500
- LogVerbose (@" dispatch_source_cancel(accept4Source)" );
2501
- dispatch_source_cancel (accept4Source);
2502
-
2503
- // We never suspend accept4Source
2504
-
2505
- accept4Source = NULL ;
2506
- }
2507
-
2508
- if (accept6Source)
2502
+ if (!accept4Source && !accept6Source && !readSource && !writeSource)
2509
2503
{
2510
- LogVerbose (@" dispatch_source_cancel(accept6Source)" );
2511
- dispatch_source_cancel (accept6Source);
2512
-
2513
- // We never suspend accept6Source
2514
-
2515
- accept6Source = NULL ;
2516
- }
2517
- if (!readSource && !writeSource) {
2518
2504
LogVerbose (@" manually closing close" );
2519
2505
2520
- if (socket4FD) {
2506
+ if (socket4FD != SOCKET_NULL)
2507
+ {
2508
+ LogVerbose (@" close(socket4FD)" );
2521
2509
close (socket4FD);
2510
+ socket4FD = SOCKET_NULL;
2522
2511
}
2523
2512
2524
- if (socket6FD) {
2513
+ if (socket6FD != SOCKET_NULL)
2514
+ {
2515
+ LogVerbose (@" close(socket6FD)" );
2525
2516
close (socket6FD);
2517
+ socket6FD = SOCKET_NULL;
2526
2518
}
2527
2519
}
2528
-
2529
- if (readSource)
2520
+ else
2530
2521
{
2531
- LogVerbose (@" dispatch_source_cancel(readSource)" );
2532
- dispatch_source_cancel (readSource);
2533
-
2534
- [self resumeReadSource ];
2522
+ if (accept4Source)
2523
+ {
2524
+ LogVerbose (@" dispatch_source_cancel(accept4Source)" );
2525
+ dispatch_source_cancel (accept4Source);
2526
+
2527
+ // We never suspend accept4Source
2528
+
2529
+ accept4Source = NULL ;
2530
+ }
2535
2531
2536
- readSource = NULL ;
2537
- }
2532
+ if (accept6Source)
2533
+ {
2534
+ LogVerbose (@" dispatch_source_cancel(accept6Source)" );
2535
+ dispatch_source_cancel (accept6Source);
2536
+
2537
+ // We never suspend accept6Source
2538
+
2539
+ accept6Source = NULL ;
2540
+ }
2538
2541
2539
- if (writeSource)
2540
- {
2541
- LogVerbose (@" dispatch_source_cancel(writeSource)" );
2542
- dispatch_source_cancel (writeSource);
2542
+ if (readSource)
2543
+ {
2544
+ LogVerbose (@" dispatch_source_cancel(readSource)" );
2545
+ dispatch_source_cancel (readSource);
2546
+
2547
+ [self resumeReadSource ];
2548
+
2549
+ readSource = NULL ;
2550
+ }
2543
2551
2544
- [self resumeWriteSource ];
2552
+ if (writeSource)
2553
+ {
2554
+ LogVerbose (@" dispatch_source_cancel(writeSource)" );
2555
+ dispatch_source_cancel (writeSource);
2556
+
2557
+ [self resumeWriteSource ];
2558
+
2559
+ writeSource = NULL ;
2560
+ }
2545
2561
2546
- writeSource = NULL ;
2562
+ // The sockets will be closed by the cancel handlers of the corresponding source
2563
+
2564
+ socket4FD = SOCKET_NULL;
2565
+ socket6FD = SOCKET_NULL;
2547
2566
}
2548
2567
2549
- // The sockets will be closed by the cancel handlers of the corresponding source
2550
-
2551
- socket4FD = SOCKET_NULL;
2552
- socket6FD = SOCKET_NULL;
2553
-
2554
2568
// If the client has passed the connect/accept method, then the connection has at least begun.
2555
2569
// Notify delegate that it is now ending.
2556
2570
BOOL shouldCallDelegate = (flags & kSocketStarted );
0 commit comments