| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef LIBRARIES_NACL_IO_KERNEL_HANDLE_H_ | 5 #ifndef LIBRARIES_NACL_IO_KERNEL_HANDLE_H_ |
| 6 #define LIBRARIES_NACL_IO_KERNEL_HANDLE_H_ | 6 #define LIBRARIES_NACL_IO_KERNEL_HANDLE_H_ |
| 7 | 7 |
| 8 #include <fcntl.h> | 8 #include <fcntl.h> |
| 9 #include <pthread.h> | 9 #include <pthread.h> |
| 10 #include <ppapi/c/pp_resource.h> |
| 10 | 11 |
| 11 #include "nacl_io/error.h" | 12 #include "nacl_io/error.h" |
| 12 #include "nacl_io/mount.h" | 13 #include "nacl_io/mount.h" |
| 13 #include "nacl_io/mount_node.h" | 14 #include "nacl_io/mount_node.h" |
| 15 #include "nacl_io/ossocket.h" |
| 14 #include "nacl_io/ostypes.h" | 16 #include "nacl_io/ostypes.h" |
| 15 | 17 |
| 16 #include "sdk_util/macros.h" | 18 #include "sdk_util/macros.h" |
| 17 #include "sdk_util/ref_object.h" | 19 #include "sdk_util/ref_object.h" |
| 18 #include "sdk_util/scoped_ref.h" | 20 #include "sdk_util/scoped_ref.h" |
| 19 #include "sdk_util/simple_lock.h" | 21 #include "sdk_util/simple_lock.h" |
| 20 | 22 |
| 21 namespace nacl_io { | 23 namespace nacl_io { |
| 22 | 24 |
| 23 class MountNodeSocket; | 25 class MountNodeSocket; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 38 // KernelHandle can only be referenced when the KernelProxy lock is held. | 40 // KernelHandle can only be referenced when the KernelProxy lock is held. |
| 39 class KernelHandle : public sdk_util::RefObject { | 41 class KernelHandle : public sdk_util::RefObject { |
| 40 public: | 42 public: |
| 41 | 43 |
| 42 KernelHandle(); | 44 KernelHandle(); |
| 43 KernelHandle(const ScopedMount& mnt, const ScopedMountNode& node); | 45 KernelHandle(const ScopedMount& mnt, const ScopedMountNode& node); |
| 44 ~KernelHandle(); | 46 ~KernelHandle(); |
| 45 | 47 |
| 46 Error Init(int open_flags); | 48 Error Init(int open_flags); |
| 47 | 49 |
| 50 Error Accept(PP_Resource* new_sock, struct sockaddr* addr, socklen_t* len); |
| 51 Error Connect(const struct sockaddr* addr, socklen_t len); |
| 52 Error Fcntl(int request, int* result, ...); |
| 53 Error VFcntl(int request, int* result, va_list args); |
| 54 Error GetDents(struct dirent* pdir, size_t count, int* bytes_written); |
| 55 Error Read(void* buf, size_t nbytes, int* bytes_read); |
| 56 Error Recv(void* buf, size_t len, int flags, int* out_len); |
| 57 Error RecvFrom(void* buf, |
| 58 size_t len, |
| 59 int flags, |
| 60 struct sockaddr* src_addr, |
| 61 socklen_t* addrlen, |
| 62 int* out_len); |
| 48 // Assumes |out_offset| is non-NULL. | 63 // Assumes |out_offset| is non-NULL. |
| 49 Error Seek(off_t offset, int whence, off_t* out_offset); | 64 Error Seek(off_t offset, int whence, off_t* out_offset); |
| 50 | 65 Error Send(const void* buf, size_t len, int flags, int* out_len); |
| 51 // Dispatches Read, Write, GetDents to atomically update offs_. | 66 Error SendTo(const void* buf, |
| 52 Error Read(void* buf, size_t nbytes, int* bytes_read); | 67 size_t len, |
| 68 int flags, |
| 69 const struct sockaddr* dest_addr, |
| 70 socklen_t addrlen, |
| 71 int* out_len); |
| 53 Error Write(const void* buf, size_t nbytes, int* bytes_written); | 72 Error Write(const void* buf, size_t nbytes, int* bytes_written); |
| 54 Error GetDents(struct dirent* pdir, size_t count, int* bytes_written); | |
| 55 Error Fcntl(int request, int* result, ...); | |
| 56 Error VFcntl(int request, int* result, va_list args); | |
| 57 | 73 |
| 58 const ScopedMountNode& node() { return node_; } | 74 const ScopedMountNode& node() { return node_; } |
| 59 const ScopedMount& mount() { return mount_; } | 75 const ScopedMount& mount() { return mount_; } |
| 60 | 76 |
| 77 const HandleAttr& Attr() { return handle_attr_; } |
| 78 private: |
| 61 // Returns the MountNodeSocket* if this node is a socket otherwise returns | 79 // Returns the MountNodeSocket* if this node is a socket otherwise returns |
| 62 // NULL. | 80 // NULL. |
| 63 MountNodeSocket* socket_node(); | 81 MountNodeSocket* socket_node(); |
| 64 | 82 |
| 65 const HandleAttr& Data() { return handle_data_; } | |
| 66 private: | |
| 67 ScopedMount mount_; | 83 ScopedMount mount_; |
| 68 ScopedMountNode node_; | 84 ScopedMountNode node_; |
| 69 sdk_util::SimpleLock handle_lock_; | 85 sdk_util::SimpleLock handle_lock_; |
| 70 HandleAttr handle_data_; | 86 HandleAttr handle_attr_; |
| 71 | 87 |
| 72 friend class KernelProxy; | 88 friend class KernelProxy; |
| 73 DISALLOW_COPY_AND_ASSIGN(KernelHandle); | 89 DISALLOW_COPY_AND_ASSIGN(KernelHandle); |
| 74 }; | 90 }; |
| 75 | 91 |
| 76 typedef sdk_util::ScopedRef<KernelHandle> ScopedKernelHandle; | 92 typedef sdk_util::ScopedRef<KernelHandle> ScopedKernelHandle; |
| 77 | 93 |
| 78 } // namespace nacl_io | 94 } // namespace nacl_io |
| 79 | 95 |
| 80 #endif // LIBRARIES_NACL_IO_KERNEL_HANDLE_H_ | 96 #endif // LIBRARIES_NACL_IO_KERNEL_HANDLE_H_ |
| OLD | NEW |