c - Calling close() on a valid file descriptor for a COM port blocks forever if the device has been powered off on Mac OS X -
i'm writing application in c on mac os x communicates bluetooth device using com ports. if bluetooth device powered off after connection has been made, subsequent calls close
block indefinitely. note using aio_read
, aio_write
read , write device.
if device left powered on, close
succeeds expected.
example:
/* open com port */ int fd = open (g_comname, o_rdwr | o_noctty | o_async ); /* ensure fd valid, work, power off bluetooth device */ /* wait until aysnc io complete */ while (aio_cancel(fd, null) == aio_notcanceled) {} /* application hang here */ close(fd);
what doing wrong? guess os waiting confirmation device, never gets anything. there anyway force close connection?
edit:
as suggested, setting o_nonblock
did trick:
fcntl(fd, f_setfl, o_async)
Comments
Post a Comment