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_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 unsigned long first_unused_addr_; |
| 62 pp::Instance* pp_instance_; |
| 63 |
| 64 typedef std::map<std::string, unsigned long> HostMap; |
| 65 typedef std::map<unsigned long, std::string> AddressMap; |
| 66 |
| 67 struct GetAddrInfoParams { |
| 68 const char* hostname; |
| 69 const char* servname; |
| 70 const struct addrinfo* hints; |
| 71 struct addrinfo** res; |
| 72 }; |
| 73 |
| 74 uint32_t AddHostAddress(const char* name, uint32_t addr); |
| 75 addrinfo* CreateAddrInfo(const PP_NetAddress_Private& addr, |
| 76 const addrinfo* hints, |
| 77 const char* name); |
| 78 addrinfo* GetFakeAddress(const char* hostname, uint16_t port, |
| 79 const addrinfo* hints); |
| 80 bool GetHostPort(const sockaddr* serv_addr, socklen_t addrlen, |
| 81 std::string* hostname, uint16_t* port); |
| 82 void Resolve(int32_t result, GetAddrInfoParams* params, int32_t* pres); |
| 83 void OnResolve(int32_t result, GetAddrInfoParams* params, int32_t* pres); |
| 84 // we store a map of virtual addresses here, as PPAPI sockes are name-bound |
| 85 HostMap hosts_; |
| 86 AddressMap addrs_; |
| 87 |
| 88 pp::CompletionCallbackFactory<SocketSubSystem, ThreadSafeRefCount> factory_; |
| 89 pp::HostResolverPrivate* host_resolver_; |
| 90 |
| 91 DISALLOW_COPY_AND_ASSIGN(SocketSubSystem); |
| 92 }; |
| 93 |
| 94 #endif // PACKAGES_LIBRARIES_NACL_MOUNTS_BASE_SOCKET_SUBSYSTEM_H_ |
| 95 |
OLD | NEW |