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