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

Side by Side Diff: libraries/nacl-mounts/net/SocketSubSystem.h

Issue 10392070: Socket subsystem implementation (Closed) Base URL: http://naclports.googlecode.com/svn/trunk/src/
Patch Set: Created 8 years, 6 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
(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_BASE_SOCKET_SUBSYSTEM_H_
6 #define PACKAGES_LIBRARIES_NACL_MOUNTS_BASE_SOCKET_SUBSYSTEM_H_
7
8 #include <assert.h>
9 #include <errno.h>
10 #include <stdarg.h>
11 #include <stdio.h>
12 #include <sys/types.h>
13 #include <unistd.h>
14
15 #include <map>
16 #include <string>
17
18 #include "../base/KernelProxy.h"
19 #include "../net/BaseSocketSubSystem.h"
20 #include "../net/Socket.h"
21 #include "ppapi/cpp/file_ref.h"
22 #include "ppapi/cpp/file_system.h"
23 #include "../ppapi/cpp/private/host_resolver_private.h"
24 #include "ppapi/utility/completion_callback_factory.h"
25
26 class SocketSubSystem : public BaseSocketSubSystem {
27 public:
28 explicit SocketSubSystem(pp::Instance* instance);
29 virtual ~SocketSubSystem();
30 pp::Instance* instance() { return pp_instance_; }
31
32 // Syscall implementations
33 int close(Socket* stream);
34 int read(Socket* stream, char* buf, size_t count, size_t* nread);
35 int write(Socket* stream, const char* buf, size_t count, size_t* nwrote);
36 int seek(Socket* stream, nacl_abi_off_t offset, int whence,
37 nacl_abi_off_t* new_offset);
38 int fstat(Socket* stream, nacl_abi_stat* out);
39
40 int fcntl(Socket* stream, int cmd, va_list ap);
41 int ioctl(Socket* stream, int request, va_list ap);
42
43 unsigned long gethostbyname(const char* name);
44 int connect(Socket** stream, const sockaddr* serv_addr, socklen_t addrlen);
45 int bind(Socket** stream, const sockaddr* addr, socklen_t addrlen);
46 int shutdown(Socket* stream, int how);
47 int listen(Socket* stream, int backlog);
48 Socket* accept(Socket* stream, struct sockaddr *addr,
49 socklen_t* addrlen);
50 int getaddrinfo(const char* hostname, const char* servname,
51 const addrinfo* hints, addrinfo** res);
52 void freeaddrinfo(addrinfo* ai);
53 int getnameinfo(const sockaddr *sa, socklen_t salen,
54 char *host, size_t hostlen,
55 char *serv, size_t servlen, int flags);
56 Mutex& mutex() { return KernelProxy::KPInstance()->select_mutex(); }
57 Cond& cond() { return KernelProxy::KPInstance()->select_cond(); }
58 private:
59 // protect hosts_ and addrs_
60 Mutex host_mutex_;
61 pp::Instance* pp_instance_;
62
63 typedef std::map<std::string, unsigned long> HostMap;
64 typedef std::map<unsigned long, std::string> AddressMap;
65
66 struct GetAddrInfoParams {
67 const char* hostname;
68 const char* servname;
69 const struct addrinfo* hints;
70 struct addrinfo** res;
71 };
72
73 uint32_t AddHostAddress(const char* name, uint32_t addr);
74 addrinfo* CreateAddrInfo(const PP_NetAddress_Private& addr,
75 const addrinfo* hints,
76 const char* name);
77 bool GetHostPort(const sockaddr* serv_addr, socklen_t addrlen,
78 std::string* hostname, uint16_t* port);
79 void Resolve(int32_t result, GetAddrInfoParams* params, int32_t* pres);
80 void OnResolve(int32_t result, GetAddrInfoParams* params, int32_t* pres);
81 // we store a map of virtual addresses here, as PPAPI sockes are name-bound
82 HostMap hosts_;
83 AddressMap addrs_;
Dmitry Polukhin 2012/06/05 14:44:55 It looks like we don't need them anymore.
vissi 2012/06/07 10:04:07 Done.
84
85 pp::CompletionCallbackFactory<SocketSubSystem, ThreadSafeRefCount> factory_;
86 pp::HostResolverPrivate* host_resolver_;
87
88 DISALLOW_COPY_AND_ASSIGN(SocketSubSystem);
89 };
90
91 #endif // PACKAGES_LIBRARIES_NACL_MOUNTS_BASE_SOCKET_SUBSYSTEM_H_
92
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698