Commit ad39a4c6 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 5a045ed1
......@@ -22,6 +22,7 @@
#include "wcfs_misc.h"
#include <golang/libgolang.h>
#include <golang/errors.h>
using namespace golang;
#include <inttypes.h>
......@@ -33,6 +34,7 @@ using namespace golang;
#include <memory>
#if 0
// error
error error::New(const string &text) {
error err;
......@@ -43,23 +45,24 @@ error error::New(const string &text) {
string error::Error() const {
return _err;
}
#endif
// io::
namespace io {
const error EOF_ = error::New("EOF");
const error ErrUnexpectedEOF = error::New("unexpected EOF");
const error EOF_ = errors::New("EOF");
const error ErrUnexpectedEOF = errors::New("unexpected EOF");
} // io::
// os::
namespace os {
// XXX -> make public
static error _pathError(const char *op, const string &path, int syserr);
int File::fd() const { return _fd; }
string File::name() const { return _path; }
int _File::fd() const { return _fd; }
string _File::name() const { return _path; }
tuple<File, error> open(const string &path, int flags, mode_t mode) {
......@@ -72,8 +75,8 @@ tuple<File, error> open(const string &path, int flags, mode_t mode) {
return make_tuple(f, err);
}
error File::close() {
File &f = *this;
error _File::close() {
_File &f = *this;
int err = ::close(f._fd);
if (err != 0)
......@@ -82,8 +85,8 @@ error File::close() {
return nil;
}
tuple<int, error> File::read(void *buf, size_t count) {
File &f = *this;
tuple<int, error> _File::read(void *buf, size_t count) {
_File &f = *this;
int n;
n = ::read(f._fd, buf, count);
......@@ -95,8 +98,8 @@ tuple<int, error> File::read(void *buf, size_t count) {
return make_tuple(n, nil);
}
tuple <int, error> File::write(const void *buf, size_t count) {
File &f = *this;
tuple <int, error> _File::write(const void *buf, size_t count) {
_File &f = *this;
int n, wrote=0;
// NOTE contrary to write(2) we have to write all data as io.Writer requires.
......@@ -113,8 +116,8 @@ tuple <int, error> File::write(const void *buf, size_t count) {
return make_tuple(wrote, nil);
}
error File::stat(struct stat *st) {
File &f = *this;
error _File::stat(struct stat *st) {
_File &f = *this;
int err = fstat(f._fd, st);
if (err != 0)
......@@ -124,8 +127,8 @@ error File::stat(struct stat *st) {
// _errno returns error corresponding to op(file) and errno.
error File::_errno(const char *op) {
File &f = *this;
error _File::_errno(const char *op) {
_File &f = *this;
return _pathError(op, f._path, errno);
}
......@@ -146,12 +149,12 @@ namespace mm {
// map_into memory-maps f.fd[offset +size) into [addr +size).
// prot is PROT_* from mmap(2).
// flags is MAP_* from mmap(2); MAP_FIXED is added automatically.
error map_into(void *addr, size_t size, int prot, int flags, const os::File &f, off_t offset) {
error map_into(void *addr, size_t size, int prot, int flags, const os::File f, off_t offset) {
void *addr2;
addr2 = mmap(addr, size, prot, MAP_FIXED | flags, f.fd(), offset);
addr2 = mmap(addr, size, prot, MAP_FIXED | flags, f->fd(), offset);
if (addr2 == MAP_FAILED)
return os::_pathError("mmap", f.name(), errno);
return os::_pathError("mmap", f->name(), errno);
if (addr2 != addr)
panic("mmap(addr, MAP_FIXED): returned !addr");
return nil;
......@@ -239,6 +242,7 @@ vector<string> split(const string &s, char sep) {
} // strings::
#if 0
// context::
namespace context {
......@@ -262,6 +266,7 @@ Context* background() {
}
} // context::
#endif
// xstrconv:: (strconv-like)
namespace xstrconv {
......
......@@ -53,6 +53,7 @@ using std::vector;
// nil is synonym for nullptr and NULL.
const nullptr_t nil = nullptr;
#if 0
// error mimics error from Go.
class error {
string _err;
......@@ -82,6 +83,7 @@ public:
// New creats error with text
static error New(const string &text);
};
#endif
// io::
namespace io {
......@@ -102,7 +104,9 @@ namespace os {
// os::File mimics os.File from Go.
// its operations return error with full file context.
class File {
class _File;
typedef refptr<_File> File;
class _File {
int _fd;
string _path;
......@@ -141,7 +145,7 @@ tuple<File, error> open(const string &path, int flags = O_RDONLY,
// mm::
namespace mm {
error map_into(void *addr, size_t, int prot, int flags, const os::File &f, off_t offset);
error map_into(void *addr, size_t, int prot, int flags, const os::File f, off_t offset);
// XXX unmap
} // mm::
......@@ -173,6 +177,7 @@ vector<string> split(const string &s, char sep);
} // strings::
#if 0
// context::
namespace context {
......@@ -189,6 +194,7 @@ extern const error canceled;
extern const error deadlineExceeded;
} // context::
#endif
#if 0
interface(Context) {
......@@ -213,6 +219,7 @@ public:
// ---- misc ----
#if 0
#include <unordered_map>
#include <unordered_set>
......@@ -255,6 +262,7 @@ struct set : std::unordered_set<Key> {
return s.find(k) != s.end();
}
};
#endif
// xstrconv::
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment