@@ -2204,8 +2204,8 @@ public IRubyObject close_on_exec_set(ThreadContext context, IRubyObject arg) {
2204
2204
int fd = -1 ;
2205
2205
2206
2206
if (fptr == null || (fd = fptr .fd ().realFileno ) == -1
2207
- || !posix .isNative ()) {
2208
- runtime .getWarnings ().warning ("close_on_exec is not implemented for this stream type: " + fptr .fd ().ch .getClass ().getSimpleName ());
2207
+ || !posix .isNative () || Platform . IS_WINDOWS ) {
2208
+ runtime .getWarnings ().warning ("close_on_exec is not implemented on this platform for this stream type: " + fptr .fd ().ch .getClass ().getSimpleName ());
2209
2209
return context .nil ;
2210
2210
}
2211
2211
@@ -2408,12 +2408,12 @@ public void setBlocking(boolean blocking) {
2408
2408
2409
2409
@ JRubyMethod (name = "fcntl" )
2410
2410
public IRubyObject fcntl (ThreadContext context , IRubyObject cmd ) {
2411
- return ctl (context . runtime , cmd , null );
2411
+ return ctl (context , cmd , null );
2412
2412
}
2413
2413
2414
2414
@ JRubyMethod (name = "fcntl" )
2415
2415
public IRubyObject fcntl (ThreadContext context , IRubyObject cmd , IRubyObject arg ) {
2416
- return ctl (context . runtime , cmd , arg );
2416
+ return ctl (context , cmd , arg );
2417
2417
}
2418
2418
2419
2419
@ JRubyMethod (name = "ioctl" , required = 1 , optional = 1 )
@@ -2427,10 +2427,11 @@ public IRubyObject ioctl(ThreadContext context, IRubyObject[] args) {
2427
2427
arg = context .runtime .getNil ();
2428
2428
}
2429
2429
2430
- return ctl (context . runtime , cmd , arg );
2430
+ return ctl (context , cmd , arg );
2431
2431
}
2432
2432
2433
- private IRubyObject ctl (Ruby runtime , IRubyObject cmd , IRubyObject arg ) {
2433
+ private IRubyObject ctl (ThreadContext context , IRubyObject cmd , IRubyObject arg ) {
2434
+ Ruby runtime = context .runtime ;
2434
2435
long realCmd = cmd .convertToInteger ().getLongValue ();
2435
2436
long nArg = 0 ;
2436
2437
@@ -2463,25 +2464,31 @@ private IRubyObject ctl(Ruby runtime, IRubyObject cmd, IRubyObject arg) {
2463
2464
// for mode changes which should persist across fork() boundaries. Since JVM has no fork
2464
2465
// this is not a problem for us.
2465
2466
if (realCmd == FcntlLibrary .FD_CLOEXEC ) {
2466
- close_on_exec_set (runtime . getCurrentContext () , runtime .getTrue ());
2467
+ close_on_exec_set (context , runtime .getTrue ());
2467
2468
} else if (realCmd == Fcntl .F_SETFD .intValue ()) {
2468
2469
if (arg != null && (nArg & FcntlLibrary .FD_CLOEXEC ) == FcntlLibrary .FD_CLOEXEC ) {
2469
- close_on_exec_set (runtime . getCurrentContext () , arg );
2470
+ close_on_exec_set (context , arg );
2470
2471
} else {
2471
2472
throw runtime .newNotImplementedError ("F_SETFD only supports FD_CLOEXEC" );
2472
2473
}
2473
2474
} else if (realCmd == Fcntl .F_GETFD .intValue ()) {
2474
- return runtime .newFixnum (close_on_exec_p (runtime . getCurrentContext () ).isTrue () ? FD_CLOEXEC : 0 );
2475
+ return runtime .newFixnum (close_on_exec_p (context ).isTrue () ? FD_CLOEXEC : 0 );
2475
2476
} else if (realCmd == Fcntl .F_SETFL .intValue ()) {
2476
2477
if ((nArg & OpenFlags .O_NONBLOCK .intValue ()) != 0 ) {
2477
- boolean block = (nArg & ModeFlags .NONBLOCK ) != ModeFlags .NONBLOCK ;
2478
+ fptr .setBlocking (runtime , true );
2479
+ } else {
2480
+ fptr .setBlocking (runtime , false );
2481
+ }
2478
2482
2479
- fptr .setBlocking (runtime , block );
2483
+ if ((nArg & OpenFlags .O_CLOEXEC .intValue ()) != 0 ) {
2484
+ close_on_exec_set (context , context .tru );
2480
2485
} else {
2481
- throw runtime . newNotImplementedError ( "F_SETFL only supports O_NONBLOCK" );
2486
+ close_on_exec_set ( context , context . fals );
2482
2487
}
2483
2488
} else if (realCmd == Fcntl .F_GETFL .intValue ()) {
2484
- return fptr .isBlocking () ? RubyFixnum .zero (runtime ) : RubyFixnum .newFixnum (runtime , ModeFlags .NONBLOCK );
2489
+ return runtime .newFixnum (
2490
+ (fptr .isBlocking () ? 0 : OpenFlags .O_NONBLOCK .intValue ()) |
2491
+ (close_on_exec_p (context ).isTrue () ? FD_CLOEXEC : 0 ));
2485
2492
} else {
2486
2493
throw runtime .newNotImplementedError ("JRuby only supports F_SETFL and F_GETFL with NONBLOCK for fcntl/ioctl" );
2487
2494
}
0 commit comments