int _gpgme_io_close (int fd) { int i; _gpgme_close_notify_handler_t handler = NULL; void *value = NULL; TRACE_BEG (DEBUG_SYSIO, "_gpgme_io_close", fd); if (fd == -1) { errno = EBADF; return TRACE_SYSRES (-1); } kill_reader (fd); kill_writer (fd); LOCK (notify_table_lock); for (i = 0; i < DIM (notify_table); i++) { if (notify_table[i].inuse && notify_table[i].fd == fd) { handler = notify_table[i].handler; value = notify_table[i].value; notify_table[i].handler = NULL; notify_table[i].value = NULL; notify_table[i].inuse = 0; break; } } UNLOCK (notify_table_lock); if (handler) handler (fd, value); if (!CloseHandle (fd_to_handle (fd))) { TRACE_LOG1 ("CloseHandle failed: ec=%d", (int) GetLastError ()); /* FIXME: Should translate the error code. */ errno = EIO; return TRACE_SYSRES (-1); } return TRACE_SYSRES (0); }
int _gpgme_io_close ( int fd ) { int i; void (*handler)(int, void*) = NULL; void *value = NULL; if ( fd == -1 ) return -1; DEBUG1 ("** closing handle for fd %d\n", fd); kill_reader (fd); kill_writer (fd); LOCK (notify_table_lock); for ( i=0; i < DIM (notify_table); i++ ) { if (notify_table[i].inuse && notify_table[i].fd == fd) { handler = notify_table[i].handler; value = notify_table[i].value; notify_table[i].handler = NULL; notify_table[i].value = NULL; notify_table[i].inuse = 0; break; } } UNLOCK (notify_table_lock); if (handler) handler (fd, value); if ( !CloseHandle (fd_to_handle (fd)) ) { DEBUG2 ("CloseHandle for fd %d failed: ec=%d\n", fd, (int)GetLastError ()); return -1; } return 0; }