Commit ad39a4c6 authored by Kirill Smelkov's avatar Kirill Smelkov

.

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