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

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -