bool wxDir::GetFirst(wxString *filename, const wxString& filespec, int flags) const { wxCHECK_MSG( IsOpened(), false, wxT("must wxDir::Open() first") ); M_DIR->Rewind(); M_DIR->SetFileSpec(filespec); M_DIR->SetFlags(flags); return GetNext(filename); }
void CLCDOutput::OnDisconnecting(int hConnection) { UNREFERENCED_PARAMETER(hConnection); LOGITRACE(_T("CLCDOutput::OnDisconnecting\n")); // let's hope our device is already gone LOGIASSERT(!IsOpened()); if (LGLCD_INVALID_CONNECTION != m_hConnection) { lgLcdDisconnect(m_hConnection); m_hConnection = LGLCD_INVALID_CONNECTION; } }
bool CFile::SetLength(size_t new_len) { MULE_VALIDATE_STATE(IsOpened(), wxT("CFile: Cannot set length when no file is open.")); #ifdef __WXMSW__ int result = chsize(m_fd, new_len); #else int result = ftruncate(m_fd, new_len); #endif SYSCALL_CHECK((result != -1), wxT("truncating file")); return (result != -1); }
bool wxFFile::Flush() { if ( IsOpened() ) { if ( fflush(m_fp) != 0 ) { wxLogSysError(_("failed to flush the file '%s'"), m_name.c_str()); return false; } } return true; }
void CompilationDatabase::DropTables() { if(!IsOpened()) return; try { // Create the schema m_db->ExecuteUpdate("DROP TABLE COMPILATION_TABLE"); m_db->ExecuteUpdate("DROP TABLE SCHEMA_VERSION"); } catch(wxSQLite3Exception& e) { wxUnusedVar(e); } }
void CLCDOutput::OnDisconnecting(int hConnection) { UNREFERENCED_PARAMETER(hConnection); LCDUITRACE(_T("CLCDOutput::OnDisconnecting\n")); // let's hope our device is already gone LCDUIASSERT(!IsOpened()); if (LGLCD_INVALID_CONNECTION != m_hConnection) { lgLcdDisconnect(m_hConnection); m_hConnection = LGLCD_INVALID_CONNECTION; ZeroMemory(m_pLastBitmap, sizeof(lgLcdBitmap160x43x1)); } }
wxFileOffset wxFFile::Tell() const { wxCHECK_MSG( IsOpened(), wxInvalidOffset, _T("wxFFile::Tell(): file is closed!") ); wxFileOffset rc = wxFtell(m_fp); if ( rc == wxInvalidOffset ) { wxLogSysError(_("Can't find current position in file '%s'"), m_name.c_str()); } return rc; }
void TCPSocket::Bind( const sockaddr_in& addr ) { int error; if (!IsOpened()) { throw TCPException("Socket::bind","Socket没有打开"); } const sockaddr* socketAddress = reinterpret_cast<const sockaddr*>(&addr); error = ::bind(m_descriptor,socketAddress,sizeof(addr)); if(error == SOCKET_ERROR ) { throw TCPException("Socket::bind","绑定Socket失败",error); } }
void TCPSocket::Connect( const sockaddr_in& addr ) throw(TCPException) { int error; if(!IsOpened()) { throw TCPException("Socket::connect", "Socket没有打开"); } const sockaddr* socketAddress = reinterpret_cast<const sockaddr*>(&addr); error = ::connect(m_descriptor, socketAddress, sizeof(addr)); if (error == SOCKET_ERROR) { //throw TCPException("Socket::connect","Socket连接出错",error); } }
// read ssize_t wxFile::Read(void *pBuf, size_t nCount) { wxCHECK( (pBuf != NULL) && IsOpened(), 0 ); ssize_t iRc = wxRead(m_fd, pBuf, nCount); if ( CheckForError(iRc) ) { wxLogSysError(_("can't read from file descriptor %d"), m_fd); return wxInvalidOffset; } return iRc; }
// write size_t wxFile::Write(const void *pBuf, size_t nCount) { wxCHECK( (pBuf != NULL) && IsOpened(), 0 ); ssize_t iRc = wxWrite(m_fd, pBuf, nCount); if ( CheckForError(iRc) ) { wxLogSysError(_("can't write to file descriptor %d"), m_fd); iRc = 0; } return iRc; }
bool AdbIOCompletion::GetOvelappedIoResult(LPOVERLAPPED ovl_data, ULONG* bytes_transferred, bool wait) { if (NULL != bytes_transferred) *bytes_transferred = 0; if (!IsOpened()) { SetLastError(ERROR_INVALID_HANDLE); return false; } ULONG transfer; bool ret = GetOverlappedResult(parent_io_object()->usb_handle(), overlapped(), &transfer, wait) ? true : false; // TODO: This is bizzare but I've seen it happening // that GetOverlappedResult with wait set to true returns "prematurely", // with wrong transferred bytes value and GetLastError reporting // ERROR_IO_PENDING. So, lets give it an up to a 20 ms loop! ULONG error = GetLastError(); if (wait && ret && (0 == transfer) && (0 != expected_transfer_size_) && ((ERROR_IO_INCOMPLETE == error) || (ERROR_IO_PENDING == error))) { for (int trying = 0; trying < 10; trying++) { Sleep(2); ret = GetOverlappedResult(parent_io_object()->usb_handle(), overlapped(), &transfer, wait) ? true : false; error = GetLastError(); if (!ret || (0 != transfer) || ((ERROR_IO_INCOMPLETE != error) && (ERROR_IO_PENDING != error))) { break; } } } if (NULL != ovl_data) CopyMemory(ovl_data, overlapped(), sizeof(OVERLAPPED)); if (NULL != bytes_transferred) *bytes_transferred = is_write_ioctl() ? transferred_bytes_ : transfer; return ret; }
bool AdbInterfaceObject::GetUsbDeviceDescriptor(USB_DEVICE_DESCRIPTOR* desc) { if (!IsOpened()) { SetLastError(ERROR_INVALID_HANDLE); return false; } if (NULL == desc) { SetLastError(ERROR_INVALID_PARAMETER); return false; } CopyMemory(desc, usb_device_descriptor(), sizeof(USB_DEVICE_DESCRIPTOR)); return true; }
sint64 CFile::doSeek(sint64 offset) const { MULE_VALIDATE_STATE(IsOpened(), wxT("Cannot seek on closed file.")); MULE_VALIDATE_PARAMS(offset >= 0, wxT("Invalid position, must be positive.")); sint64 result = SEEK_FD(m_fd, offset, SEEK_SET); if (result == offset) { return result; } else if (result == wxInvalidOffset) { throw CSeekFailureException(wxString(wxT("Seeking failed: ")) + wxSysErrorMsg()); } else { throw CSeekFailureException(wxT("Seeking returned incorrect position")); } }
void TCPSocket::Listen( int queuelen ) throw (TCPException) { int error; if(!IsOpened()) { throw TCPException("Socket::listen","Socket未打开"); } error = ::listen(m_descriptor, queuelen); if(error == SOCKET_ERROR) { throw TCPException("Socket::listen","listen函数有错误"); } }
// close bool wxFile::Close() { if ( IsOpened() ) { if ( CheckForError(wxClose(m_fd)) ) { wxLogSysError(_("can't close file descriptor %d"), m_fd); m_fd = fd_invalid; return false; } else m_fd = fd_invalid; } return true; }
bool wxPipeInputStream::CanRead() const { // we can read if there's something in the put back buffer // even pipe is closed if ( m_wbacksize > m_wbackcur ) return true; wxPipeInputStream * const self = wxConstCast(this, wxPipeInputStream); if ( !IsOpened() ) { // set back to mark Eof as it may have been unset by Ungetch() self->m_lasterror = wxSTREAM_EOF; return false; } DWORD nAvailable; // function name is misleading, it works with anon pipes as well DWORD rc = ::PeekNamedPipe ( m_hInput, // handle NULL, 0, // ptr to buffer and its size NULL, // [out] bytes read &nAvailable, // [out] bytes available NULL // [out] bytes left ); if ( !rc ) { if ( ::GetLastError() != ERROR_BROKEN_PIPE ) { // unexpected error wxLogLastError(wxT("PeekNamedPipe")); } // don't try to continue reading from a pipe if an error occurred or if // it had been closed ::CloseHandle(m_hInput); self->m_hInput = INVALID_HANDLE_VALUE; self->m_lasterror = wxSTREAM_EOF; nAvailable = 0; } return nAvailable != 0; }
int Tcp::Connect(/* [in] */ const Address &addr, /* [in] */ OutConnectHandler *handler) { assert(IsOpened()); int result = uv_tcp_connect(&m_connectReq, *this, addr, OnConnected); if(! result) { Ref(); m_pOutConnectHandler = handler; } return result; }
bool wxFFile::Close() { if ( IsOpened() ) { if ( fclose(m_fp) != 0 ) { wxLogSysError(_("can't close file '%s'"), m_name.c_str()); return false; } Detach(); } return true; }
bool wxFFile::Flush() { if ( IsOpened() ) { // fflush returns non-zero on error // if ( fflush(m_fp) ) { wxLogSysError(_("failed to flush the file '%s'"), m_name.c_str()); return false; } } return true; }
// flush bool wxFile::Flush() { if ( IsOpened() ) { #if defined(__VISUALC__) || wxHAVE_FSYNC if ( wxFsync(m_fd) == -1 ) { wxLogSysError(_("can't flush file descriptor %d"), m_fd); return false; } #else // no fsync // just do nothing #endif // fsync } return true; }
void Minesweeper::PrintSolvingField() { printf( "\n"); for (size_t i = 0; i < m_height + 2; ++i) { for (size_t j = 0; j < m_width + 2; ++j) { //if (m_solvingField[i][j] == 10) if (!IsOpened(j, i)) printf( ANSI_COLOR_YELLOW "- " ANSI_COLOR_RESET); else printf("%lu ", m_solvingField[i][j]); } printf( "\n"); } }
size_t wxFFile::Write(const void *pBuf, size_t nCount) { if ( !nCount ) return 0; wxCHECK_MSG( pBuf, 0, wxT("invalid parameter") ); wxCHECK_MSG( IsOpened(), 0, wxT("can't write to closed file") ); size_t nWritten = fwrite(pBuf, 1, nCount, m_fp); if ( nWritten < nCount ) { wxLogSysError(_("Write error on file '%s'"), m_name.c_str()); } return nWritten; }
// close the key, it's not an error to call it when not opened bool wxRegKey::Close() { if ( IsOpened() ) { m_dwLastError = RegCloseKey((HKEY) m_hKey); m_hKey = 0; if ( m_dwLastError != ERROR_SUCCESS ) { wxLogSysError(m_dwLastError, _("Can't close registry key '%s'"), GetName().c_str()); return false; } } return true; }
size_t wxFFile::Read(void *pBuf, size_t nCount) { if ( !nCount ) return 0; wxCHECK_MSG( pBuf, 0, wxT("invalid parameter") ); wxCHECK_MSG( IsOpened(), 0, wxT("can't read from closed file") ); size_t nRead = fread(pBuf, 1, nCount, m_fp); if ( (nRead < nCount) && Error() ) { wxLogSysError(_("Read error on file '%s'"), m_name.c_str()); } return nRead; }
i64 FileCFILEStream::OffsetGet( FileOffsetMode::mode_t offsetMode, CError *error ) { ASSUME( IsOpened() ); if( offsetMode == FileOffsetMode::FromCurrent ) { DSA( error, Error::Ok() ); return 0; } DSA( error, Error::UnknownError() ); i64 currentOffset = ftell( (FILE *)_file ); if( currentOffset == -1 ) { return 0; } if( offsetMode == FileOffsetMode::FromBegin ) { DSA( error, Error::Ok() ); return currentOffset - _offsetToStart; } ASSUME( offsetMode == FileOffsetMode::FromEnd ); if( fseek( (FILE *)_file, 0, SEEK_END ) != 0 ) { return 0; } i64 fileEnd = ftell( (FILE *)_file ); if( fileEnd == -1 ) { return 0; } i64 offsetDiff = currentOffset - fileEnd; if( fseek( (FILE *)_file, currentOffset, SEEK_SET ) != 0 ) { return 0; } DSA( error, Error::Ok() ); return offsetDiff; }
// flush bool wxFile::Flush() { #ifdef HAVE_FSYNC // fsync() only works on disk files and returns errors for pipes, don't // call it then if ( IsOpened() && GetKind() == wxFILE_KIND_DISK ) { if ( CheckForError(wxFsync(m_fd)) ) { wxLogSysError(_("can't flush file descriptor %d"), m_fd); return false; } } #endif // HAVE_FSYNC return true; }
TCPSocketAddress TCPSocket::GetSockName() throw (TCPException) { int error; if (!IsOpened()) { throw TCPException("Socket::getsockname()","Socket未打开"); } sockaddr_in address; int addrLen = sizeof(address); sockaddr* socketAddress = reinterpret_cast<sockaddr*>(&address); error = ::getsockname(m_descriptor,socketAddress,&addrLen); if (error == SOCKET_ERROR) { throw TCPException("Socket::getSockName","getsockname有异常"); } return TCPSocketAddress(address); }
int TCPSocket::Sendto( const sockaddr_in& addr, const char* data, size_t size, int flags /*= 0*/ ) { int bytes; if(!IsOpened()) { throw TCPException("Socket::sendto", "Socket没有打开", 0); } const sockaddr* socketAddress = reinterpret_cast<const sockaddr*>(&addr); bytes = ::sendto(m_descriptor, data, size, flags, socketAddress, sizeof(addr)); if(bytes == SOCKET_ERROR) { throw TCPException("Socket::sendto", "sendto出错"); } return bytes; }
bool AdbInterfaceObject::GetUsbConfigurationDescriptor( USB_CONFIGURATION_DESCRIPTOR* desc) { if (!IsOpened()) { SetLastError(ERROR_INVALID_HANDLE); return false; } if (NULL == desc) { SetLastError(ERROR_INVALID_PARAMETER); return false; } CopyMemory(desc, usb_config_descriptor(), sizeof(USB_CONFIGURATION_DESCRIPTOR)); return true; }