blob: 8b654ab14bb03f0d4bb0946c880a4d0c2b42ba74 [file] [log] [blame]
Christopher Wileya59f7b92013-02-26 15:07:02 -08001// Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef SHILL_FILE_IO_H_
6#define SHILL_FILE_IO_H_
7
8#include <base/lazy_instance.h>
9
10namespace shill {
11
12// A POSIX file IO wrapper to allow mocking in unit tests.
13class FileIO {
14 public:
15 virtual ~FileIO();
16
17 // This is a singleton -- use FileIO::GetInstance()->Foo()
18 static FileIO *GetInstance();
19
20 virtual ssize_t Write(int fd, const void *buf, size_t count);
21 virtual ssize_t Read(int fd, void *buf, size_t count);
22 virtual int Close(int fd);
23 virtual int SetFdNonBlocking(int fd);
24
25 protected:
26 FileIO();
27
28 private:
29 friend struct base::DefaultLazyInstanceTraits<FileIO>;
30
31 DISALLOW_COPY_AND_ASSIGN(FileIO);
32};
33
34} // namespace shill
35
36#endif // SHILL_FILE_IO_H_