OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2012 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 SOCKET_H | |
6 #define SOCKET_H | |
7 | |
8 #include <deque> | |
9 #include <queue> | |
10 #include <vector> | |
11 | |
12 #include "../include/ppapi/cpp/completion_callback.h" | |
13 #include "../include/ppapi/cpp/private/tcp_socket_private.h" | |
14 #include "base/PthreadHelpers.h" | |
15 #include "net/SocketSubSystem.h" | |
16 | |
17 class TCPSocket : public FileStream { | |
18 public: | |
19 explicit TCPSocket(SocketSubSystem* sys, int oflag); | |
Dmitry Polukhin
2012/05/29 15:00:51
explicit is useless if c-tor has more more than 1
vissi
2012/05/30 08:10:51
I wanted to eliminate lint warning, removed now.
| |
20 virtual ~TCPSocket(); | |
21 | |
22 int oflag() { return oflag_; } | |
23 bool is_block() { return !(oflag_ & O_NONBLOCK); } | |
24 bool is_open() { return socket_ != NULL; } | |
25 | |
26 bool connect(const char* host, uint16_t port); | |
27 bool acceptFrom(PP_Resource resource); | |
28 | |
29 virtual void addref(); | |
30 virtual void release(); | |
31 | |
32 virtual void close(); | |
33 virtual int read(char* buf, size_t count, size_t* nread); | |
34 virtual int write(const char* buf, size_t count, size_t* nwrote); | |
35 | |
36 virtual int fcntl(int cmd, va_list ap); | |
37 | |
38 virtual bool is_read_ready(); | |
39 virtual bool is_write_ready(); | |
40 virtual bool is_exception(); | |
41 | |
42 private: | |
43 void sendtask(); | |
Dmitry Polukhin
2012/05/29 15:00:51
I think this function should be renamed to SendTas
vissi
2012/05/30 08:10:51
This function is not used anywhere, removed now.
| |
44 | |
45 void Connect(int32_t result, const char* host, uint16_t port, int32_t* pres); | |
46 void OnConnect(int32_t result, int32_t* pres); | |
47 | |
48 void Read(int32_t result, int32_t* pres); | |
49 void OnRead(int32_t result, int32_t* pres); | |
50 | |
51 void Write(int32_t result, int32_t* pres); | |
52 void OnWrite(int32_t result, int32_t* pres); | |
53 | |
54 void Close(int32_t result, int32_t* pres); | |
55 | |
56 bool Accept(int32_t result, PP_Resource resource, int32_t* pres); | |
57 | |
58 static const size_t kBufSize = 64 * 1024; | |
59 | |
60 SocketSubSystem* sys; | |
Dmitry Polukhin
2012/05/29 15:00:51
should end with underscore i.e. sys_
vissi
2012/05/30 08:10:51
Done.
| |
61 int ref_; | |
62 int oflag_; | |
63 pp::CompletionCallbackFactory<TCPSocket, ThreadSafeRefCount> factory_; | |
64 pp::TCPSocketPrivate* socket_; | |
65 std::deque<char> in_buf_; | |
66 std::vector<char> out_buf_; | |
67 std::vector<char> read_buf_; | |
68 std::vector<char> write_buf_; | |
69 bool write_sent_; | |
70 | |
71 DISALLOW_COPY_AND_ASSIGN(TCPSocket); | |
72 }; | |
73 | |
74 #endif // SOCKET_H | |
75 | |
OLD | NEW |