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

Unified 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 side-by-side diff with in-line comments
Download patch
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,89 @@
+// 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(int fd);
+ int read(FileHandle* handle, char* buf, size_t count, size_t* nread);
+ int write(FileHandle* handle, const char* buf, size_t count, size_t* nwrote);
+ int seek(FileHandle* handle, nacl_abi_off_t offset, int whence,
+ nacl_abi_off_t* new_offset);
+ //int dup(int fd, int *newfd);
+ //int dup2(int fd, int newfd);
+ int fstat(FileHandle* handle, nacl_abi_stat* out);
+
+ int fcntl(FileHandle* handle, int cmd, va_list ap);
+ int ioctl(FileHandle* handle, int request, va_list ap);
+
+ unsigned long gethostbyname(const char* name);
+ int socket(int socket_family, int socket_type, int protocol);
+ int connect(FileHandle* handle, unsigned long addr, unsigned short port);
+ int shutdown(int fd, int how);
+ int bind(FileHandle* handle, unsigned long addr, unsigned short port);
+ int listen(FileHandle* handle, int backlog);
+ int accept(FileHandle* handle, struct sockaddr *addr, socklen_t *addrlen);
+ Cond& cond() { return cond_; }
+ Mutex& mutex() { return mutex_; }
+
+ static FileStream* const kBadFileStream;
+ int IsReady(int nfds, fd_set* fds, bool (FileStream::*is_ready)(),
+ bool apply);
+
+ 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_;
+
+ int GetFirstUnusedDescriptor();
+ FileStream* GetStream(int fd);
+ bool IsKnowDescriptor(int fd);
+ void AddHostAddress(const char* name, unsigned long addr);
+
+ HostMap hosts_;
+ AddressMap addrs_;
+
+ DISALLOW_COPY_AND_ASSIGN(SocketSubSystem);
+};
+
+#endif // SOCKET_SUBSYSTEM_H
+

Powered by Google App Engine
This is Rietveld 408576698