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 PACKAGES_LIBRARIES_NACL_MOUNTS_NET_SOCKET_H_ |
| 6 #define PACKAGES_LIBRARIES_NACL_MOUNTS_NET_SOCKET_H_ |
| 7 |
| 8 #include <deque> |
| 9 #include <queue> |
| 10 #include <vector> |
| 11 |
| 12 #include "ppapi/cpp/completion_callback.h" |
| 13 #include "../ppapi/cpp/private/tcp_socket_private.h" |
| 14 #include "../net/SocketSubSystem.h" |
| 15 #include "../util/PthreadHelpers.h" |
| 16 |
| 17 class TCPSocket : public Socket { |
| 18 public: |
| 19 TCPSocket(SocketSubSystem* sys, int oflag); |
| 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 Connect(int32_t result, const char* host, uint16_t port, int32_t* pres); |
| 44 void OnConnect(int32_t result, int32_t* pres); |
| 45 |
| 46 void Read(int32_t result, int32_t* pres); |
| 47 void OnRead(int32_t result, int32_t* pres); |
| 48 |
| 49 void Write(int32_t result, int32_t* pres); |
| 50 void OnWrite(int32_t result, int32_t* pres); |
| 51 |
| 52 void Close(int32_t result, int32_t* pres); |
| 53 |
| 54 bool Accept(int32_t result, PP_Resource resource, int32_t* pres); |
| 55 |
| 56 static const size_t kBufSize = 64 * 1024; |
| 57 |
| 58 SocketSubSystem* sys_; |
| 59 int ref_; |
| 60 int oflag_; |
| 61 pp::CompletionCallbackFactory<TCPSocket, ThreadSafeRefCount> factory_; |
| 62 pp::TCPSocketPrivate* socket_; |
| 63 std::deque<char> in_buf_; |
| 64 std::vector<char> out_buf_; |
| 65 std::vector<char> read_buf_; |
| 66 std::vector<char> write_buf_; |
| 67 bool write_sent_; |
| 68 |
| 69 DISALLOW_COPY_AND_ASSIGN(TCPSocket); |
| 70 }; |
| 71 |
| 72 #endif // PACKAGES_LIBRARIES_NACL_MOUNTS_NET_SOCKET_H_ |
| 73 |
OLD | NEW |