int GridFTPModule::close(gfal_file_handle handle) { GridFTPFileDesc* desc = static_cast<GridFTPFileDesc*>(gfal_file_handle_get_fdesc(handle)); if (desc) { gridftp_rw_commit_put(GFAL_GRIDFTP_SCOPE_CLOSE, desc); if (is_write_only(desc->open_flags)) { desc->request->wait(GFAL_GRIDFTP_SCOPE_CLOSE); } else if (is_read_only(desc->open_flags)) { if (!desc->request->done) globus_ftp_client_abort(desc->handler->get_ftp_client_handle()); try { desc->request->wait(GFAL_GRIDFTP_SCOPE_CLOSE); } catch (const Gfal::CoreException& e) { if (e.code() != ECANCELED) throw; } } gfal_file_handle_delete(handle); delete desc; } return 0; }
ssize_t GridFTPModule::pwrite(gfal_file_handle handle, const void* buffer, size_t count, off_t offset) { GridFTPFileDesc* desc = static_cast<GridFTPFileDesc*>(gfal_file_handle_get_fdesc(handle)); return gridftp_rw_internal_pwrite(_handle_factory, desc, buffer, count, offset); }
int gfal_http_closedir(plugin_handle plugin_data, gfal_file_handle dir_desc, GError** err) { GfalHttpInternal* davix = static_cast<GfalHttpInternal*>(plugin_data); Davix::DavixError* daverr = NULL; int ret = 0; if (davix->posix->closedir((DAVIX_DIR*)gfal_file_handle_get_fdesc(dir_desc), &daverr) != 0) { davix2gliberr(daverr, err); Davix::DavixError::clearError(&daverr); ret = -1; } gfal_file_handle_delete(dir_desc); return ret; }
struct dirent* gfal_http_readdir(plugin_handle plugin_data, gfal_file_handle dir_desc, GError** err) { GfalHttpInternal* davix = static_cast<GfalHttpInternal*>(plugin_data); Davix::DavixError* daverr = NULL; daverr = NULL; struct dirent* de = davix->posix->readdir((DAVIX_DIR*)gfal_file_handle_get_fdesc(dir_desc), &daverr); if (de == NULL && daverr != NULL) { davix2gliberr(daverr, err); Davix::DavixError::clearError(&daverr); } return de; }
ssize_t GridFTPModule::read(gfal_file_handle handle, void* buffer, size_t count) { GridFTPFileDesc* desc = static_cast<GridFTPFileDesc*>(gfal_file_handle_get_fdesc(handle)); ssize_t ret; Glib::Mutex::Lock locker(desc->lock); if (desc->is_not_seeked() && is_read_only(desc->open_flags) && desc->stream != NULL) { gfal_log(GFAL_VERBOSE_TRACE, " read in the GET main flow ... "); ret = gridftp_read_stream(GFAL_GRIDFTP_SCOPE_READ, desc->stream, buffer, count); } else { gfal_log(GFAL_VERBOSE_TRACE, " read with a pread ... "); ret = gridftp_rw_internal_pread(_handle_factory, desc, buffer, count, desc->current_offset); } desc->current_offset += ret; return ret; }
off_t GridFTPModule::lseek(gfal_file_handle handle, off_t offset, int whence) { GridFTPFileDesc* desc = static_cast<GridFTPFileDesc*>(gfal_file_handle_get_fdesc(handle)); Glib::Mutex::Lock locker(desc->lock); switch (whence) { case SEEK_SET: desc->current_offset = offset; break; case SEEK_CUR: desc->current_offset += offset; break; case SEEK_END: // not supported for now ( no meaning in write-once files ... ) default: std::ostringstream o; throw Gfal::CoreException(GFAL_GRIDFTP_SCOPE_LSEEK, "Invalid whence", EINVAL); } return desc->current_offset; }