//-----------------------------------------------------------------// bool change_speed(speed_t brate) { if(fd_ < 0) return false; if(cfsetspeed(&attr_, brate) == -1) { close_(); return false; } if(tcsetattr(fd_, TCSANOW, &attr_) == -1) { close_(); return false; } return true; }
File_Extractor::fex_t( fex_type_t t ) : type_( t ) { own_file_ = NULL; close_(); }
void use_device(struct reader *reader, struct writer *writer, struct device *d) /*@ requires reader(reader) &*& writer(writer) &*& lockset(currentThread, nil) &*& [?f1]d->ops |-> ?ops &*& [f1]file_ops(ops, ?device, ?file_) &*& [?f2]device(); @*/ /*@ ensures reader(reader) &*& writer(writer) &*& lockset(currentThread, nil) &*& [f1]d->ops |-> ops &*& [f1]file_ops(ops, device, file_) &*& [f2]device(); @*/ { //@ open file_ops(ops, _, _); device_open *open_ = d->ops->open_; device_close *close_ = d->ops->close_; void *file = open_(); bool exitMenu = false; while (!exitMenu) /*@ invariant reader(reader) &*& writer(writer) &*& file_(f2, file) &*& lockset(currentThread, nil) &*& [f1]d->ops |-> ops &*& [f1]ops->read |-> ?read &*& [f1]ops->write |-> ?write &*& [_]is_device_read(read, file_) &*& [_]is_device_write(write, file_); @*/ { int choice = 0; writer_write_string(writer, "Device Menu:\r\n" "1. Read Value\r\n" "2. Write Value\r\n" "0. Exit\r\n"); choice = reader_read_nonnegative_integer(reader); if (choice == 1) { device_read *read_ = d->ops->read; int value = read_(file); writer_write_string(writer, "Value read: "); writer_write_integer_as_decimal(writer, value); writer_write_string(writer, "\r\n"); } else if (choice == 2) { int value = 0; device_write *write_ = d->ops->write; writer_write_string(writer, "Enter value:\r\n"); value = reader_read_nonnegative_integer(reader); write_(file, value); writer_write_string(writer, "The value has been written\r\n"); } else { exitMenu = true; } } close_(file); //@ close [f1]file_ops(ops, device, file_); }
//-----------------------------------------------------------------// bool close() { if(fd_ < 0) return false; int status; if(ioctl(fd_, TIOCMGET, &status) == -1) { close_(); return false; } status &= ~TIOCM_DTR; /* turn off DTR */ status &= ~TIOCM_RTS; /* turn off RTS */ if(ioctl(fd_, TIOCMSET, &status) == -1) { close_(); return false; } close_(); return true; }
void channel_impl::process_frame(const frame::ptr_t& frame) { assert(frame->get_channel() == m_channel_id); try { m_continuation(frame); } catch (amqpp::channel_exception& e) { close_(e); } }
/** * qdb->free(): De-allocate qdb_t structure * * @param db a pointer of qdb_t object */ static void free_(qdb_t *db) { if (db == NULL) return; Q_MUTEX_ENTER(db->qmutex); close_(db); free(db->info.dbtype); free(db->info.addr); free(db->info.username); free(db->info.password); free(db->info.database); free(db); Q_MUTEX_LEAVE(db->qmutex); Q_MUTEX_DESTROY(db->qmutex); return; }
void closeSocket(int socket){ close_(socket); }
~Object() { if (!id_) return; MPQC_ASSERT(close_); MPQC_FILE_THREADSAFE; close_(id_); }
/** * qdb->open(): Connect to database server * * @param db a pointer of qdb_t object * * @return true if successful, otherwise returns false. */ static bool open_(qdb_t *db) { if (db == NULL) return false; // if connected, close first if (db->connected == true) { close_(db); } #ifdef _Q_ENABLE_MYSQL Q_MUTEX_ENTER(db->qmutex); // initialize handler if (db->mysql != NULL) close_(db); if (mysql_library_init(0, NULL, NULL) != 0) { Q_MUTEX_LEAVE(db->qmutex); return false; } if ((db->mysql = mysql_init(NULL)) == NULL) { Q_MUTEX_LEAVE(db->qmutex); return false; } // set options my_bool reconnect = _Q_MYSQL_OPT_RECONNECT; unsigned int connect_timeout = _Q_MYSQL_OPT_CONNECT_TIMEOUT; unsigned int read_timeout = _Q_MYSQL_OPT_READ_TIMEOUT; unsigned int write_timeout = _Q_MYSQL_OPT_WRITE_TIMEOUT; if (reconnect != false) { mysql_options(db->mysql, MYSQL_OPT_RECONNECT, (char *)&reconnect); } if (connect_timeout > 0) { mysql_options(db->mysql, MYSQL_OPT_CONNECT_TIMEOUT, (char *)&connect_timeout); } if (read_timeout > 0) { mysql_options(db->mysql, MYSQL_OPT_READ_TIMEOUT, (char *)&read_timeout); } if (write_timeout > 0) { mysql_options(db->mysql, MYSQL_OPT_WRITE_TIMEOUT, (char *)&write_timeout); } // try to connect if (mysql_real_connect(db->mysql, db->info.addr, db->info.username, db->info.password, db->info.database, db->info.port, NULL, 0) == NULL) { close_(db); // free mysql handler Q_MUTEX_LEAVE(db->qmutex); return false; } // set auto-commit if (mysql_autocommit(db->mysql, db->info.autocommit) != 0) { close_(db); // free mysql handler Q_MUTEX_LEAVE(db->qmutex); return false; } // set flag db->connected = true; Q_MUTEX_LEAVE(db->qmutex); return true; #else return false; #endif }
void close() noexcept { std::unique_lock< mutex > lk( mtx_); close_( lk); }
channel_impl::~channel_impl() { close_(); }
void channel_impl::close_(const amqpp::channel_exception& e) { close_(e.reply_code(), e.reply_text(), e.class_id(), e.method_id()); }
//-----------------------------------------------------------------// bool open(const std::string& path, speed_t brate, char_len clen = char_len::bits8, stop_len slen = stop_len::one, parity par = parity::none, bool hc = false) { int cpar = 0; int ipar = IGNBRK; switch(par) { case parity::none: cpar = 0; ipar = IGNPAR; break; case parity::even: cpar = PARENB; ipar = INPCK; break; case parity::odd: cpar = (PARENB | PARODD); ipar = INPCK; break; default: return false; } int bstop = 0; switch(slen) { case stop_len::one: bstop = 0; break; case stop_len::two: bstop = CSTOPB; break; default: return false; } int cbits = 0; switch(clen) { case char_len::bits8: cbits = CS8; break; case char_len::bits7: cbits = CS7; break; default: return false; } fd_ = ::open(path.c_str(), O_RDWR | O_NOCTTY | O_NDELAY); if(fd_ < 0) { return false; } if(tcgetattr(fd_, &attr_back_) == -1) { ::close(fd_); fd_ = -1; } memset(&attr_, 0, sizeof(attr_)); if(hc) { attr_.c_cflag = cbits | cpar | bstop | CRTSCTS | CREAD; } else { attr_.c_cflag = cbits | cpar | bstop | CLOCAL | CREAD; } attr_.c_iflag = ipar; attr_.c_oflag = 0; attr_.c_lflag = 0; attr_.c_cc[VMIN] = 0; // block untill n bytes are received attr_.c_cc[VTIME] = 1; // block untill a timer expires (n * 100 mSec.) if(cfsetspeed(&attr_, brate) == -1) { close_(); return false; } if(tcsetattr(fd_, TCSANOW, &attr_) == -1) { close_(); return false; } int status; if(ioctl(fd_, TIOCMGET, &status) == -1) { close_(); return false; } return true; }
void File_Extractor::close() { close_v(); close_(); }
void QgsScopedSqlite::reset( sqlite3* db ) { close_(); db_ = db; }
QgsScopedSqlite::~QgsScopedSqlite() { close_(); }