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