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 SOCKET_SUBSYSTEM_H |
| 6 #define SOCKET_SUBSYSTEM_H |
| 7 |
| 8 #include <assert.h> |
| 9 #include <errno.h> |
| 10 #include <memory.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/PthreadHelpers.h" |
| 21 #include "../net/BaseSocketSubSystem.h" |
| 22 #include "../net/IOInterfaces.h" |
| 23 #include "ppapi/cpp/file_ref.h" |
| 24 #include "ppapi/cpp/file_system.h" |
| 25 #include "ppapi/utility/completion_callback_factory.h" |
| 26 |
| 27 static const unsigned long kFirstAddr = 0x00000000; |
| 28 static const int64_t kMicrosecondsPerSecond = 1000 * 1000; |
| 29 static const int64_t kNanosecondsPerMicrosecond = 1000; |
| 30 |
| 31 class SocketSubSystem : public BaseSocketSubSystem { |
| 32 public: |
| 33 explicit SocketSubSystem(pp::Instance* instance); |
| 34 ~SocketSubSystem(); |
| 35 pp::Instance* instance() { return pp_instance_; } |
| 36 |
| 37 // Syscall implementations |
| 38 int close(FileStream* stream); |
| 39 int read(FileStream* stream, char* buf, size_t count, size_t* nread); |
| 40 int write(FileStream* stream, const char* buf, size_t count, size_t* nwrote); |
| 41 int seek(FileStream* stream, nacl_abi_off_t offset, int whence, |
| 42 nacl_abi_off_t* new_offset); |
| 43 int fstat(FileStream* stream, nacl_abi_stat* out); |
| 44 |
| 45 int fcntl(FileStream* stream, int cmd, va_list ap); |
| 46 int ioctl(FileStream* stream, int request, va_list ap); |
| 47 |
| 48 unsigned long gethostbyname(const char* name); |
| 49 int connect(FileStream** stream, unsigned long addr, unsigned short port); |
| 50 int shutdown(FileStream* stream, int how); |
| 51 int bind(FileStream** stream, unsigned long addr, unsigned short port); |
| 52 int listen(FileStream* stream, int backlog); |
| 53 FileStream* accept(FileStream* stream, struct sockaddr *addr, |
| 54 socklen_t* addrlen); |
| 55 Cond& cond() { return cond_; } |
| 56 Mutex& mutex() { return mutex_; } |
| 57 |
| 58 private: |
| 59 unsigned long first_unused_addr_; |
| 60 pp::Instance* pp_instance_; |
| 61 |
| 62 typedef std::map<std::string, unsigned long> HostMap; |
| 63 typedef std::map<unsigned long, std::string> AddressMap; |
| 64 |
| 65 Cond cond_; |
| 66 Mutex mutex_; |
| 67 |
| 68 // we store a map of virtual addresses here, as PPAPA sockes are name-bound |
| 69 void AddHostAddress(const char* name, unsigned long addr); |
| 70 std::string GetHostByAddr(unsigned long addr); |
| 71 |
| 72 HostMap hosts_; |
| 73 AddressMap addrs_; |
| 74 |
| 75 DISALLOW_COPY_AND_ASSIGN(SocketSubSystem); |
| 76 }; |
| 77 |
| 78 #endif // SOCKET_SUBSYSTEM_H |
| 79 |
OLD | NEW |