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

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

Powered by Google App Engine
This is Rietveld 408576698