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

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, 7 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 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(int fd);
41 int read(FileHandle* handle, char* buf, size_t count, size_t* nread);
42 int write(FileHandle* handle, const char* buf, size_t count, size_t* nwrote);
43 int seek(FileHandle* handle, nacl_abi_off_t offset, int whence,
44 nacl_abi_off_t* new_offset);
45 //int dup(int fd, int *newfd);
46 //int dup2(int fd, int newfd);
47 int fstat(FileHandle* handle, nacl_abi_stat* out);
48
49 int fcntl(FileHandle* handle, int cmd, va_list ap);
50 int ioctl(FileHandle* handle, int request, va_list ap);
51
52 unsigned long gethostbyname(const char* name);
53 int socket(int socket_family, int socket_type, int protocol);
54 int connect(FileHandle* handle, unsigned long addr, unsigned short port);
55 int shutdown(int fd, int how);
56 int bind(FileHandle* handle, unsigned long addr, unsigned short port);
57 int listen(FileHandle* handle, int backlog);
58 int accept(FileHandle* handle, struct sockaddr *addr, socklen_t *addrlen);
59 Cond& cond() { return cond_; }
60 Mutex& mutex() { return mutex_; }
61
62 static FileStream* const kBadFileStream;
63 int IsReady(int nfds, fd_set* fds, bool (FileStream::*is_ready)(),
64 bool apply);
65
66 private:
67 unsigned long first_unused_addr_;
68 static SocketSubSystem* instance_;
69 pp::Instance* pp_instance_;
70
71 typedef std::map<std::string, unsigned long> HostMap;
72 typedef std::map<unsigned long, std::string> AddressMap;
73
74 Cond cond_;
75 Mutex mutex_;
76
77 int GetFirstUnusedDescriptor();
78 FileStream* GetStream(int fd);
79 bool IsKnowDescriptor(int fd);
80 void AddHostAddress(const char* name, unsigned long addr);
81
82 HostMap hosts_;
83 AddressMap addrs_;
84
85 DISALLOW_COPY_AND_ASSIGN(SocketSubSystem);
86 };
87
88 #endif // SOCKET_SUBSYSTEM_H
89
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698