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

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, 6 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/KernelProxy.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;
Evgeniy Stepanov 2012/05/28 14:55:12 Hide these constants in .cc, they are not part of
vissi 2012/05/28 15:20:21 Done.
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 Mutex& mutex() { return KernelProxy::KPInstance()->mutex(); }
56 Cond& cond() { return KernelProxy::KPInstance()->cond(); }
57 private:
58 // protect hosts_ and addrs_
59 Mutex mutex_;
60 unsigned long first_unused_addr_;
61 pp::Instance* pp_instance_;
62
63 typedef std::map<std::string, unsigned long> HostMap;
64 typedef std::map<unsigned long, std::string> AddressMap;
65
66 // we store a map of virtual addresses here, as PPAPA sockes are name-bound
67 void AddHostAddress(const char* name, unsigned long addr);
68 std::string GetHostByAddr(unsigned long addr);
69
70 HostMap hosts_;
71 AddressMap addrs_;
72
73 DISALLOW_COPY_AND_ASSIGN(SocketSubSystem);
74 };
75
76 #endif // SOCKET_SUBSYSTEM_H
77
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698