Chromium Code Reviews| Index: libraries/nacl-mounts/net/SocketSubSystem.h |
| =================================================================== |
| --- libraries/nacl-mounts/net/SocketSubSystem.h (revision 0) |
| +++ libraries/nacl-mounts/net/SocketSubSystem.h (revision 0) |
| @@ -0,0 +1,80 @@ |
| +// Copyright (c) 2012 The Chromium OS Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef SOCKET_SUBSYSTEM_H |
| +#define SOCKET_SUBSYSTEM_H |
| + |
| +#include <assert.h> |
| +#include <errno.h> |
| +#include <memory.h> |
| +#include <stdarg.h> |
| +#include <stdio.h> |
| +#include <sys/ioctl.h> |
| +#include <sys/types.h> |
| +#include <unistd.h> |
| + |
| +#include <map> |
| +#include <string> |
| + |
| +#include "../base/FileHandle.h" |
| +#include "../base/PthreadHelpers.h" |
| +#include "../net/BaseSocketSubSystem.h" |
| +#include "../net/IOInterfaces.h" |
| +#include "ppapi/cpp/file_ref.h" |
| +#include "ppapi/cpp/file_system.h" |
| +#include "ppapi/utility/completion_callback_factory.h" |
| + |
| +static const unsigned long kFirstAddr = 0x00000000; |
| +static const int64_t kMicrosecondsPerSecond = 1000 * 1000; |
| +static const int64_t kNanosecondsPerMicrosecond = 1000; |
| + |
| +class SocketSubSystem : public BaseSocketSubSystem { |
| + public: |
| + explicit SocketSubSystem(pp::Instance* instance); |
| + ~SocketSubSystem(); |
| + pp::Instance* instance() { return pp_instance_; } |
| + |
| + static SocketSubSystem* GetSocketSubSystem() { return instance_; } |
| + // Syscall implementations |
| + int close(FileStream* stream); |
| + int read(FileStream* stream, char* buf, size_t count, size_t* nread); |
| + int write(FileStream* stream, const char* buf, size_t count, size_t* nwrote); |
| + int seek(FileStream* stream, nacl_abi_off_t offset, int whence, |
| + nacl_abi_off_t* new_offset); |
| + int fstat(FileStream* stream, nacl_abi_stat* out); |
| + |
| + int fcntl(FileStream* stream, int cmd, va_list ap); |
| + int ioctl(FileStream* stream, int request, va_list ap); |
| + |
| + unsigned long gethostbyname(const char* name); |
| + int connect(FileStream** stream, unsigned long addr, unsigned short port); |
| + int shutdown(FileStream* stream, int how); |
| + int bind(FileStream** stream, unsigned long addr, unsigned short port); |
| + int listen(FileStream* stream, int backlog); |
| + FileStream* accept(FileStream* stream, struct sockaddr *addr, |
| + socklen_t* addrlen); |
| + Cond& cond() { return cond_; } |
| + Mutex& mutex() { return mutex_; } |
| + |
| + private: |
| + unsigned long first_unused_addr_; |
| + static SocketSubSystem* instance_; |
| + pp::Instance* pp_instance_; |
| + |
| + typedef std::map<std::string, unsigned long> HostMap; |
| + typedef std::map<unsigned long, std::string> AddressMap; |
| + |
| + Cond cond_; |
| + Mutex mutex_; |
| + |
| + 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.
|
| + |
| + HostMap hosts_; |
| + AddressMap addrs_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(SocketSubSystem); |
| +}; |
| + |
| +#endif // SOCKET_SUBSYSTEM_H |
| + |