Skip to content

io baseline#43

Open
vrancurel wants to merge 2 commits intomasterfrom
ft/io2
Open

io baseline#43
vrancurel wants to merge 2 commits intomasterfrom
ft/io2

Conversation

@vrancurel
Copy link
Copy Markdown
Owner

No description provided.

Comment thread src/cmds.cpp
{
if (argc != 4)
{
fprintf(stderr, "usage: put file n_data n_parities\n");
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use std::cerr instead of fprintf

Comment thread src/io.h Outdated
@@ -0,0 +1,10 @@
#ifndef __IO_H__
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

__KAD_IO_H__ has less risk of conflict (IO is pretty common) and is consistent with the other guards (that uses a KAD prefix).

Also, we should add license preamble here as well.

Comment thread src/cmds.cpp
return SHELL_CONT;
}

do_put(argv[1], atoi(argv[2]), atoi(argv[3]));
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

atoi is unsafe (I think the linter may complains about it), you can use the stou32 helper from utils.cpp

Comment thread src/io.cpp
@@ -0,0 +1,125 @@

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add license preamble:

/*
 * Copyright 2017-2018 the QuadIron authors
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * 1. Redistributions of source code must retain the above copyright notice,
 *    this list of conditions and the following disclaimer.
 *
 * 2. Redistributions in binary form must reproduce the above copyright notice,
 *    this list of conditions and the following disclaimer in the documentation
 *    and/or other materials provided with the distribution.
 *
 * 3. Neither the name of the copyright holder nor the names of its contributors
 *    may be used to endorse or promote products derived from this software
 *    without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */

Comment thread src/io.cpp Outdated
@@ -0,0 +1,125 @@

#include <nttec/nttec.h>
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor: the "pattern" used in the other files is

#include <stdinclude1>
#include <stdinclude2>

#include <systemdeps1>
#include <systemdeps2>

#include "local_include1"
#include "local_include2"

Here that would gives

#include <cstdio>
#include <cstdlib>
#include <streambuf>

#include <sys/mman.h>
#include <sys/stat.h>
#include <unistd.h>
#include <fcntl.h>
#include <nttec/nttec.h>

#include "io.h"

Comment thread src/io.cpp Outdated

//do it
offset = 0;
for (u_int i = 0; i < fec->n_data; i++) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

u_int is not standard, use uint32_t instead

Comment thread src/io.cpp

template class nttec::fec::RsFnt<uint32_t>;

int vflag = 1;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

static int? (to limit the scope) or even static bool (since it's a flag).

Comment thread src/io.cpp
struct stat sb;
size_t length, data_size;
off_t offset;
char cfilename[1024];
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use an std::string instead of a fixed size buffer?

Comment thread src/io.cpp

if (fstat(fd, &sb) == -1) {
std::cerr << "fstat " << filename << " failed\n";
return -1;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we return here (or throw an exception if you follow my advice) then we will leak an open fd

Comment thread src/io.cpp
if (length % fec->n_data != 0) {
// FIXME
std::cerr << "file size is not multiple of n_data\n";
return -1;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we return here (or throw an exception if you follow my advice) then we will leak an open fd

@vrancurel
Copy link
Copy Markdown
Owner Author

OK thorough review. Any idea why the tests are failing ? how can I check on my laptop before pushing ?

@slaperche-scality
Copy link
Copy Markdown
Collaborator

The test are fine (we don't have that much for now anyway ^^")

The problem are:

  • code formatting (clang-format is unhappy): you can format your code by running make format
  • code itself (clang-tidy is unhappy): you can run make lint to see the problems (or make fix-lint to see the problems and fix automatically the ones that clang can fix by itself)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants