Skip to content

Commit

Permalink
#43: imaptest
Browse files Browse the repository at this point in the history
- code cleanup, removed unused variables
- write_operations and write_buffer now in rados_mail_object.
- bugfix: mail_buffer size now correctly calculated (get_used_size,
instead buffer_size)
- added additional buffer (checks / free) statements to make sure read
and write buffer are empty in every case.
  • Loading branch information
jrse committed Jul 14, 2017
1 parent 0917cff commit 0239941
Show file tree
Hide file tree
Showing 6 changed files with 109 additions and 109 deletions.
3 changes: 1 addition & 2 deletions src/librmb/rados-mail-object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ RadosMailObject::RadosMailObject() {
this->save_date = 0;
this->received_date = 0;
memset(this->guid, 0, GUID_128_SIZE);
completion_private = librados::Rados::aio_create_completion();
// std::make_shared<librados::AioCompletion>(*librados::Rados::aio_create_completion());
this->object_size = -1;
this->active_op = false;
this->mail_buffer = NULL;
}
18 changes: 10 additions & 8 deletions src/librmb/rados-mail-object.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include <iostream>
#include <sstream>
#include <rados/librados.hpp>

#include <map>
#define GUID_128_SIZE 16

namespace librmb {
Expand All @@ -16,8 +16,7 @@ class RadosMailObject {
public:
RadosMailObject();
virtual ~RadosMailObject() {
completion_private->release();
write_op.remove();

}

void set_oid(const char* oid) { this->oid = oid; }
Expand Down Expand Up @@ -46,11 +45,14 @@ class RadosMailObject {
const uint64_t get_object_size() { return this->object_size; }

void set_object_size(uint64_t& size) { this->object_size = size; }
librados::ObjectWriteOperation& get_write_op() { return this->write_op; }

librados::AioCompletion* get_completion_private() { return this->completion_private; }
bool has_active_op() { return active_op; }
void set_active_op(bool active) { this->active_op = active; }
std::map<librados::AioCompletion*, librados::ObjectWriteOperation*>* get_completion_op_map() {
return &completion_op;
}
void set_mail_buffer(char* mail_buffer) { this->mail_buffer = mail_buffer; }
char* get_mail_buffer() { return this->mail_buffer; }

private:
std::string oid;
Expand All @@ -65,11 +67,11 @@ class RadosMailObject {

uint8_t guid[GUID_128_SIZE];
uint64_t object_size; // byte
std::map<librados::AioCompletion*, librados::ObjectWriteOperation*> completion_op;

librados::ObjectWriteOperation write_op;

librados::AioCompletion* completion_private;
bool active_op;
// used as pointer to a buffer_t (to avoid using dovecot datatypes in library)
char* mail_buffer;

public:
// X_ATTRIBUTES
Expand Down
4 changes: 2 additions & 2 deletions src/storage-rbox/rbox-copy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ static int rbox_mail_storage_try_copy(struct mail_save_context **_ctx, struct ma
librados::IoCtx dest_io_ctx = r_storage->s->get_io_ctx();
librados::IoCtx src_io_ctx;

char *ns_src_mail = mail->box->list->ns->owner->username;
char *ns_dest_mail = ctx->dest_mail->box->list->ns->owner->username;
const char *ns_src_mail = mail->box->list->ns->owner->username;
const char *ns_dest_mail = ctx->dest_mail->box->list->ns->owner->username;

i_debug("rbox_mail_storage_try_copy: mail = %p", mail);
debug_print_mail_save_context(*_ctx, "rbox_mail_storage_try_copy", NULL);
Expand Down
12 changes: 10 additions & 2 deletions src/storage-rbox/rbox-mail.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@ int rbox_get_index_record(struct mail *_mail) {
struct rbox_mail *rmail = (struct rbox_mail *)_mail;
struct rbox_mailbox *rbox = (struct rbox_mailbox *)_mail->transaction->box;

i_debug("last_seq %lu, mail_seq %lu, ext_id = %lu, uid=%d, old_oid=%s", rmail->last_seq, _mail->seq, rbox->ext_id,
_mail->uid, rmail->mail_object->get_oid().c_str());
i_debug("last_seq %lu, mail_seq %lu, ext_id = %lu, uid=%lu, old_oid=%s", (unsigned long)rmail->last_seq,
(unsigned long)_mail->seq, (unsigned long)rbox->ext_id, (unsigned long)_mail->uid,
rmail->mail_object->get_oid().c_str());

if (rmail->last_seq != _mail->seq) {
const struct obox_mail_index_record *obox_rec;
Expand Down Expand Up @@ -270,6 +271,10 @@ static int rbox_mail_get_stream(struct mail *_mail, bool get_body ATTR_UNUSED, s
return -1;
}

if (rmail->mail_buffer != NULL) {
i_free(rmail->mail_buffer);
}

rmail->mail_buffer = p_new(default_pool, char, size_r + 1);
if (rmail->mail_buffer == NULL) {
FUNC_END_RET("ret == -1; out of memory");
Expand All @@ -296,6 +301,8 @@ static int rbox_mail_get_stream(struct mail *_mail, bool get_body ATTR_UNUSED, s
}

mail_data_bl.copy(0, ret, &rmail->mail_buffer[0]);
i_debug("rbox_mail_get_stream(oid=%s, size_r = %lu, read_from_rados = %d):",
rmail->mail_object->get_oid().c_str(), size_r, ret);

offset += ret;
} while (ret > 0);
Expand Down Expand Up @@ -344,6 +351,7 @@ void rbox_index_mail_set_seq(struct mail *_mail, uint32_t seq, bool saving) {
i_free(rmail_->mail_buffer);
}
if (rmail_->mail_object != NULL) {
rmail_->mail_object->get_completion_op_map()->clear();
delete rmail_->mail_object;
rmail_->mail_object = NULL;
}
Expand Down
Loading

0 comments on commit 0239941

Please sign in to comment.