-
Notifications
You must be signed in to change notification settings - Fork 33
/
js_file.h
117 lines (89 loc) · 2.89 KB
/
js_file.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
// Copyright 2012 The ChromiumOS Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef JS_FILE_H
#define JS_FILE_H
#include <queue>
#include "ppapi/cpp/completion_callback.h"
#include "file_system.h"
#include "pthread_helpers.h"
class JsFile : public FileStream,
public InputInterface {
public:
JsFile(int fd, int oflag, OutputInterface* out);
virtual ~JsFile();
static void InitTerminal();
int fd() { return fd_; }
int oflag() { return oflag_; }
bool is_block() { return !(oflag_ & O_NONBLOCK); }
bool is_open() { return is_open_; }
virtual void OnOpen(bool success, bool is_atty);
virtual void OnRead(const char* buf, size_t size);
virtual void OnWriteAcknowledge(uint64_t count);
virtual void OnClose();
virtual void OnReadReady(bool is_read_ready);
virtual void addref();
virtual void release();
virtual FileStream* dup(int fd);
virtual void close();
virtual int read(char* buf, size_t count, size_t* nread);
virtual int write(const char* buf, size_t count, size_t* nwrote);
virtual int fstat(nacl_abi_stat* out);
virtual int isatty();
virtual int tcgetattr(termios* termios_p);
virtual int tcsetattr(int optional_actions, const termios* termios_p);
virtual int fcntl(int cmd, va_list ap);
virtual int ioctl(int request, va_list ap);
virtual bool is_read_ready();
virtual bool is_write_ready();
protected:
void PostWriteTask(bool always_post);
void Read(int32_t result, size_t size);
void Write(int32_t result);
void Close(int32_t result);
int ref_;
int fd_;
int oflag_;
OutputInterface* out_;
pp::CompletionCallbackFactory<JsFile> factory_;
std::deque<char> in_buf_;
std::deque<char> out_buf_;
bool out_task_sent_;
bool is_open_;
bool is_atty_;
bool is_read_ready_;
uint64_t write_sent_;
uint64_t write_acknowledged_;
uint64_t on_read_call_count_;
static termios tio_;
private:
DISALLOW_COPY_AND_ASSIGN(JsFile);
};
class JsFileHandler : public PathHandler {
public:
explicit JsFileHandler(OutputInterface* out);
virtual ~JsFileHandler();
virtual void addref();
virtual void release();
void Open(int32_t result, JsFile* stream, const char* pathname);
virtual FileStream* open(int fd, const char* pathname, int oflag, int* err);
virtual int stat(const char* pathname, nacl_abi_stat* out);
private:
int ref_;
pp::CompletionCallbackFactory<JsFileHandler> factory_;
OutputInterface* out_;
DISALLOW_COPY_AND_ASSIGN(JsFileHandler);
};
class JsSocket : public JsFile {
public:
JsSocket(int fd, int oflag, OutputInterface* out);
virtual ~JsSocket();
bool connect(const char* host, uint16_t port);
int isatty();
bool is_read_ready();
private:
void Connect(int32_t result, const char* host, uint16_t port);
pp::CompletionCallbackFactory<JsSocket> factory_;
DISALLOW_COPY_AND_ASSIGN(JsSocket);
};
#endif // JS_FILE_H