diff options
author | John Langford <jl@hunch.net> | 2014-01-23 19:43:09 +0400 |
---|---|---|
committer | John Langford <jl@hunch.net> | 2014-01-23 19:43:09 +0400 |
commit | f9a6b9bd2f40abf378481ae6ca92966dfdae2d5e (patch) | |
tree | bec1fcf318c70d61fed8955a4482bf43aadbf177 /vowpalwabbit/io_buf.h | |
parent | 238040fb9f5cfd408ea97c4349e8df005481241a (diff) | |
parent | cb8d90352a0007c8b133f535ad0f9111c7a58cee (diff) |
reconcile
Diffstat (limited to 'vowpalwabbit/io_buf.h')
-rw-r--r-- | vowpalwabbit/io_buf.h | 29 |
1 files changed, 12 insertions, 17 deletions
diff --git a/vowpalwabbit/io_buf.h b/vowpalwabbit/io_buf.h index e8b8157c..8b62ca76 100644 --- a/vowpalwabbit/io_buf.h +++ b/vowpalwabbit/io_buf.h @@ -120,13 +120,11 @@ class io_buf { void set(char *p){space.end = p;} virtual ssize_t read_file(int f, void* buf, size_t nbytes){ -#ifdef _WIN32 - return _read(f, buf, (unsigned int)nbytes); -#else - return read(f, buf, (unsigned int)nbytes); -#endif + return read_file_or_socket(f, buf, nbytes); } + static ssize_t read_file_or_socket(int f, void* buf, size_t nbytes); + size_t fill(int f) { if (space.end_array - endloaded == 0) { @@ -144,15 +142,12 @@ class io_buf { return 0; } - virtual ssize_t write_file(int f, const void* buf, size_t nbytes) - { -#ifdef _WIN32 - return _write(f, buf, (unsigned int)nbytes); -#else - return write(f, buf, (unsigned int)nbytes); -#endif + virtual ssize_t write_file(int f, const void* buf, size_t nbytes) { + return write_file_or_socket(f, buf, nbytes); } + static ssize_t write_file_or_socket(int f, const void* buf, size_t nbytes); + virtual void flush() { if (write_file(files[0], space.begin, space.size()) != (int) space.size()) std::cerr << "error, failed to write example\n"; @@ -160,19 +155,19 @@ class io_buf { virtual bool close_file(){ if(files.size()>0){ -#ifdef _WIN32 - _close(files.pop()); -#else - close(files.pop()); -#endif + close_file_or_socket(files.pop()); return true; } return false; } + static void close_file_or_socket(int f); + void close_files(){ while(close_file()); } + + static bool is_socket(int f); }; void buf_write(io_buf &o, char* &pointer, size_t n); |