Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(71)

Side by Side Diff: native_client_sdk/src/libraries/nacl_io/mount_node_socket.h

Issue 23498015: [NaCl SDK] Support non blocking TCP/UDP (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merge Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef LIBRARIES_NACL_IO_MOUNT_NODE_SOCKET_H_ 5 #ifndef LIBRARIES_NACL_IO_MOUNT_NODE_SOCKET_H_
6 #define LIBRARIES_NACL_IO_MOUNT_NODE_SOCKET_H_ 6 #define LIBRARIES_NACL_IO_MOUNT_NODE_SOCKET_H_
7 7
8 #include "nacl_io/ossocket.h" 8 #include "nacl_io/ossocket.h"
9 #ifdef PROVIDES_SOCKET_API 9 #ifdef PROVIDES_SOCKET_API
10 10
11 #include <ppapi/c/pp_errors.h> 11 #include <ppapi/c/pp_errors.h>
12 #include <ppapi/c/pp_resource.h> 12 #include <ppapi/c/pp_resource.h>
13 #include <ppapi/c/ppb_net_address.h> 13 #include <ppapi/c/ppb_net_address.h>
14 14
15 #include "nacl_io/mount.h" 15 #include "nacl_io/mount.h"
16 #include "nacl_io/mount_node.h"
17 #include "nacl_io/mount_node_stream.h"
16 #include "nacl_io/pepper_interface.h" 18 #include "nacl_io/pepper_interface.h"
17 19
18 namespace nacl_io { 20 namespace nacl_io {
19 21
20 /* Only allow single maximum transfers of 64K or less. Socket users 22 /* Only allow single maximum transfers of 64K or less. Socket users
21 * should be looping on Send/Recv size. */ 23 * should be looping on Send/Recv size. */
22 static const size_t MAX_SOCK_TRANSFER = 65536; 24 static const size_t MAX_SOCK_TRANSFER = 65536;
23 25
24 class MountSocket; 26 class MountStream;
25 27
26 class MountNodeSocket : public MountNode { 28 class MountNodeSocket : public MountNodeStream {
27 public: 29 public:
28 explicit MountNodeSocket(Mount* mount); 30 explicit MountNodeSocket(Mount* mount);
29 31
30 protected: 32 protected:
31 virtual void Destroy(); 33 virtual void Destroy();
32 virtual Error Init(int flags) = 0; 34 virtual Error Init(int flags) = 0;
33 35
34 public: 36 public:
35 virtual uint32_t GetEventStatus();
36
37 // Normal read/write operations on a file (recv/send). 37 // Normal read/write operations on a file (recv/send).
38 virtual Error Read(size_t offs, void* buf, size_t count, int* out_bytes); 38 virtual Error Read(size_t offs, void* buf, size_t count, int* out_bytes);
39 virtual Error Write(size_t offs, 39 virtual Error Write(size_t offs,
40 const void* buf, 40 const void* buf,
41 size_t count, 41 size_t count,
42 int* out_bytes); 42 int* out_bytes);
43 43
44 // Unsuported Functions 44 // Unsuported Functions
45 virtual Error Accept(const struct sockaddr* addr, socklen_t len); 45 virtual Error Accept(const struct sockaddr* addr, socklen_t len);
46 virtual Error Listen(int backlog); 46 virtual Error Listen(int backlog);
47 virtual Error GetSockOpt(int lvl, int optname, void* optval, socklen_t* len); 47 virtual Error GetSockOpt(int lvl, int optname, void* optval, socklen_t* len);
48 virtual Error SetSockOpt(int lvl, 48 virtual Error SetSockOpt(int lvl,
49 int optname, 49 int optname,
50 const void* optval, 50 const void* optval,
51 socklen_t len); 51 socklen_t len);
52 virtual Error Shutdown(int how); 52 virtual Error Shutdown(int how);
53 virtual Error MMap(void* addr, 53 virtual Error MMap(void* addr,
54 size_t length, 54 size_t length,
55 int prot, 55 int prot,
56 int flags, 56 int flags,
57 size_t offset, 57 size_t offset,
58 void** out_addr); 58 void** out_addr);
59 59
60 // Normal Functions. 60 // Socket Functions.
61 virtual Error Bind(const struct sockaddr* addr, socklen_t len); 61 virtual Error Bind(const struct sockaddr* addr, socklen_t len);
62 virtual Error Connect(const struct sockaddr* addr, socklen_t len); 62 virtual Error Connect(const struct sockaddr* addr, socklen_t len);
63 virtual Error Recv(void* buf, size_t len, int flags, int* out_len); 63 virtual Error Recv(void* buf, size_t len, int flags, int* out_len);
64 virtual Error RecvFrom(void* buf, 64 virtual Error RecvFrom(void* buf,
65 size_t len, 65 size_t len,
66 int flags, 66 int flags,
67 struct sockaddr* src_addr, 67 struct sockaddr* src_addr,
68 socklen_t* addrlen, 68 socklen_t* addrlen,
69 int* out_len); 69 int* out_len);
70 70
71 virtual Error Send(const void* buf, size_t len, int flags, int* out_len); 71 virtual Error Send(const void* buf, size_t len, int flags, int* out_len);
72 virtual Error SendTo(const void* buf, 72 virtual Error SendTo(const void* buf,
73 size_t len, 73 size_t len,
74 int flags, 74 int flags,
75 const struct sockaddr* dest_addr, 75 const struct sockaddr* dest_addr,
76 socklen_t addrlen, 76 socklen_t addrlen,
77 int* out_len); 77 int* out_len);
78 78
79 virtual Error GetPeerName(struct sockaddr* addr, socklen_t* len); 79 virtual Error GetPeerName(struct sockaddr* addr, socklen_t* len);
80 virtual Error GetSockName(struct sockaddr* addr, socklen_t* len); 80 virtual Error GetSockName(struct sockaddr* addr, socklen_t* len);
81 81
82 PP_Resource socket_resource() { return socket_resource_; }
83
84 // Updates socket's state, recording last error.
85 void SetError_Locked(int pp_error_num);
86
82 protected: 87 protected:
83 NetAddressInterface* NetAddress(); 88
89 // Wraps common error checks, timeouts, work pump for send.
90 Error SendHelper(const void* buf,
91 size_t len,
92 int flags,
93 PP_Resource addr,
94 int* out_len);
95
96 // Wraps common error checks, timeouts, work pump for recv.
97 Error RecvHelper(void* buf,
98 size_t len,
99 int flags,
100 PP_Resource* addr,
101 int* out_len);
102
103
104 // Per socket type send and recv
105 virtual Error Recv_Locked(void* buffer,
106 size_t len,
107 PP_Resource* out_addr,
108 int* out_len) = 0;
109
110 virtual Error Send_Locked(const void* buffer,
111 size_t len,
112 PP_Resource addr,
113 int* out_len) = 0;
114
115
116 NetAddressInterface* NetInterface();
117 TCPSocketInterface* TCPInterface();
118 UDPSocketInterface* UDPInterface();
119
84 PP_Resource SockAddrToResource(const struct sockaddr* addr, socklen_t len); 120 PP_Resource SockAddrToResource(const struct sockaddr* addr, socklen_t len);
85 socklen_t ResourceToSockAddr(PP_Resource addr, 121 socklen_t ResourceToSockAddr(PP_Resource addr,
86 socklen_t len, 122 socklen_t len,
87 struct sockaddr* out_addr); 123 struct sockaddr* out_addr);
88 124
89 bool IsEquivalentAddress(PP_Resource addr1, PP_Resource addr2); 125 bool IsEquivalentAddress(PP_Resource addr1, PP_Resource addr2);
90 126
91 protected: 127 protected:
92 PP_Resource socket_resource_; 128 PP_Resource socket_resource_;
93 PP_Resource local_addr_; 129 PP_Resource local_addr_;
94 PP_Resource remote_addr_; 130 PP_Resource remote_addr_;
131 uint32_t socket_flags_;
132 int last_errno_;
95 133
96 friend class KernelProxy; 134 friend class KernelProxy;
97 friend class MountSocket; 135 friend class MountStream;
98 }; 136 };
99 137
100 138
101 } // namespace nacl_io 139 } // namespace nacl_io
102 140
103 141
104 #endif // PROVIDES_SOCKET_API 142 #endif // PROVIDES_SOCKET_API
105 #endif // LIBRARIES_NACL_IO_MOUNT_NODE_SOCKET_H_ 143 #endif // LIBRARIES_NACL_IO_MOUNT_NODE_SOCKET_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698