|
The Pedigree Project 0.1
|
#include <UnixFilesystem.h>
Inheritance diagram for UnixSocket:
Collaboration diagram for UnixSocket:Classes | |
| struct | buf |
Public Types | |
| enum | SocketType { Streaming , Datagram , SequencedPacket } |
| enum | SocketState { Listening , Connecting , Inactive , Active , Closed } |
Public Types inherited from File | |
| enum | AttributeMask : uint32_t { AccessTime = 1U << 0 , ModifyTime = 1U << 1 , ChangeTime = 1U << 2 , Owner = 1U << 3 , Group = 1U << 4 , Permissions = 1U << 5 } |
Public Member Functions | |
| UnixSocket (const String &name, Filesystem *pFs, File *pParent, UnixSocket *other=nullptr, SocketType type=Datagram) | |
| virtual uint64_t | readBytewise (uint64_t location, uint64_t size, uintptr_t buffer, bool bCanBlock=true) |
| virtual uint64_t | writeBytewise (uint64_t location, uint64_t size, uintptr_t buffer, bool bCanBlock=true) |
| uint64_t | recvfrom (uint64_t size, uintptr_t buffer, bool bCanBlock, String &from) |
| bool | sendDatagram (uint64_t size, uintptr_t buffer, bool bCanBlock, uintptr_t source, const SharedPointer< SocketRights > &rights, int *error=nullptr) |
| bool | receiveDatagram (uint64_t size, uintptr_t buffer, bool bCanBlock, String &from, SharedPointer< SocketRights > &rights, uint64_t &bytesRead, uint64_t &datagramLength) |
| uint64_t | sendStream (uint64_t size, uintptr_t buffer, bool bCanBlock, const SharedPointer< SocketRights > &rights, bool *interrupted=nullptr) |
| uint64_t | sendStream (const struct iovec *vectors, size_t vectorCount, bool bCanBlock, const SharedPointer< SocketRights > &rights, bool *interrupted=nullptr) |
| uint64_t | receiveStream (uint64_t size, uintptr_t buffer, bool bCanBlock, SharedPointer< SocketRights > *rights, bool *interrupted=nullptr) |
| uint64_t | receiveStream (struct iovec *vectors, size_t vectorCount, bool bCanBlock, SharedPointer< SocketRights > *rights, bool *interrupted=nullptr) |
| bool | sendPacket (uint64_t size, uintptr_t buffer, bool bCanBlock, const SharedPointer< SocketRights > &rights, int *error=nullptr) |
| bool | receivePacket (uint64_t size, uintptr_t buffer, bool bCanBlock, SharedPointer< SocketRights > &rights, uint64_t &bytesRead, uint64_t &packetLength, bool *interrupted=nullptr) |
| virtual int | select (bool bWriting=false, int timeout=0) |
| virtual bool | isSocket () const |
| virtual bool | isSeekable () const |
| bool | bind (UnixSocket *other, bool block=false) |
| void | unbind () |
| bool | shutdown (int how) |
| bool | writeShutdown () const |
| bool | readShutdown () const |
| void | acknowledgeBind () |
| bool | addSocket (UnixSocket *socket) |
| UnixSocket * | getSocket (bool block=false) |
| void | addWaiter (Semaphore *waiter, bool read, bool write) |
| void | removeWaiter (Semaphore *waiter) |
| void | addWaiter (Thread *thread, Event *event) |
| void | removeWaiter (Event *event) |
| SocketType | getType () const |
| SocketState | getState () const |
| bool | wasConnected () const |
| ReadinessGenerations | readinessGenerations () override |
| void | failConnection () |
| bool | markListening () |
| struct ucred | getCredentials () const |
| struct ucred | getPeerCredentials () const |
Public Member Functions inherited from File | |
| File () | |
| File (const String &name, Time::Timestamp accessedTime, Time::Timestamp modifiedTime, Time::Timestamp creationTime, uintptr_t inode, class Filesystem *pFs, size_t size, File *pParent) | |
| virtual | ~File () |
| virtual uint64_t | read (uint64_t location, uint64_t size, uintptr_t buffer, bool bCanBlock=true) final |
| size_t | readCached (uint64_t location, size_t size, uintptr_t buffer, bool(*prepare)(uintptr_t, size_t)=nullptr) |
| virtual uint64_t | write (uint64_t location, uint64_t size, uintptr_t buffer, bool bCanBlock=true) final |
| uint64_t | append (uint64_t size, uintptr_t buffer, uint64_t &location, bool bCanBlock=true) |
| WriteGuard | lockWrites () |
| virtual physical_uintptr_t | getPhysicalPage (size_t offset) |
| virtual bool | isDirectPhysicalMapping () const |
| size_t | physicalMappingFlags () const |
| virtual void | returnPhysicalPage (size_t offset) |
| virtual bool | tryBeginMappingRelease () |
| void | endMappingRelease () |
| bool | syncAndReturnPhysicalPage (size_t offset, bool async) |
| virtual bool | sync () |
| bool | syncRange (size_t offset, size_t length) |
| virtual bool | sync (size_t offset, bool async) |
| virtual bool | syncPages (const uint64_t *offsets, size_t count) |
| Time::Timestamp | getCreationTime () |
| void | setCreationTime (Time::Timestamp t) |
| Time::Timestamp | getAccessedTime () |
| void | setAccessedTime (Time::Timestamp t) |
| Time::Timestamp | getModifiedTime () |
| void | setModifiedTime (Time::Timestamp t) |
| void | setTimes (Time::Timestamp accessed, Time::Timestamp modified, bool changeAccessed, bool changeModified) |
| virtual Attributes | getAttributes () const |
| virtual XattrStatus | getExtendedAttribute (const StringView &name, void *buffer, size_t capacity, size_t &required) |
| virtual XattrStatus | listExtendedAttributes (void *buffer, size_t capacity, size_t &required) |
| virtual XattrStatus | setExtendedAttribute (const StringView &name, const void *value, size_t length, unsigned flags) |
| virtual XattrStatus | removeExtendedAttribute (const StringView &name) |
| virtual bool | prepareSharedMapping (size_t offset, size_t length) |
| String | getName () const |
| void | getName (String &s) const |
| virtual void | getFullPath (String &result, bool bWithMount=true) |
| virtual String | getFullPath (bool bWithMount=true) |
| virtual void | truncate () |
| bool | resize (size_t size) |
| virtual size_t | getSize () |
| void | setSize (size_t sz) |
| virtual bool | isSymlink () |
| virtual bool | isDirectory () |
| virtual bool | isBlockDevice () const |
| virtual uint64_t | deviceNumber () const |
| virtual bool | isPipe () const |
| virtual bool | isFifo () const |
| bool | supportsRegularFileOperations () |
| virtual bool | isCharacterDevice () const |
| virtual bool | isConsole () const |
| virtual uint64_t | maximumFileSize () const |
| virtual bool | allowMapping (bool shared, bool writeRequested, bool &mayWrite) |
| bool | acquireMappingUse (bool executable, bool sharedWrite) |
| void | releaseMappingUse (bool executable, bool sharedWrite) |
| uintptr_t | getInode () const |
| virtual void | setInode (uintptr_t inode) |
| virtual uintptr_t | futexIdentity () |
| Filesystem * | getFilesystem () const |
| void | setFilesystem (Filesystem *pFs) |
| virtual void | fileAttributeChanged () |
| void | publishEvent (FileEventMask mask, const StringView &name=StringView(), bool targetIsDirectory=false) |
| virtual FileHandleStatus | subscribeInodeEvents (FileEventMask mask, const SharedPointer< FileEventObserver > &observer, FileEventSubscription &subscription) |
| virtual void | finishInodeRetirement () |
| virtual void | increaseRefCount (bool bIsWriter) |
| virtual void | decreaseRefCount (bool bIsWriter) |
| virtual bool | retainVfsReference () |
| virtual void | releaseVfsReference () |
| virtual bool | isStableVfsRoot () const |
| void | setPermissions (uint32_t perms) |
| uint32_t | getPermissions () const |
| bool | setOwnership (size_t uid, size_t gid, bool changeUid, bool changeGid) |
| void | setUid (size_t uid) |
| size_t | getUid () const |
| void | setGid (size_t gid) |
| size_t | getGid () const |
| File * | getParent () const |
| void | getNamespace (ParentLease &parent, String &name) const |
| virtual ReadyMask | queryReady (bool reading, bool writing) |
| virtual bool | supportsReadinessNotifications () const |
| void | monitor (Thread *pThread, Event *pEvent) |
| void | cullMonitorTargets (Thread *pThread) |
| void | cullMonitorTargets (Event *pEvent) |
| virtual bool | supports (const size_t command) const |
| virtual int | command (const size_t command, void *buffer) |
| virtual size_t | getBlockSize () const |
| void | markPageExternallyWritable (size_t offset) |
| size_t | populateRange (size_t offset, size_t length) |
| void | enableDirect () |
| void | disableDirect () |
| virtual void | preallocate (size_t expectedSize, bool zero=true) |
| bool | allocateRange (size_t offset, size_t length, bool keepSize=false) |
| virtual File * | open () |
| virtual File * | openForDescriptor (RetainedFile &owner) |
Public Member Functions inherited from ReadinessSource | |
| MUST_USE_RESULT bool | subscribeReadiness (ReadyMask interest, const SharedPointer< ReadinessObserver > &observer, ReadinessSubscription &subscription) |
Public Member Functions inherited from FileEventSource | |
| MUST_USE_RESULT bool | subscribeFileEvents (FileEventMask interest, const SharedPointer< FileEventObserver > &observer, FileEventSubscription &subscription) |
Private Types | |
| typedef Buffer< uint8_t, true > | UnixSocketStream |
| typedef RingBuffer< struct buf * > | DatagramBuffer |
Private Member Functions | |
| void | setCreds () |
| void | notifyStream (UnixSocketConnection::Stream *stream) |
| SocketState | getStateLocked () const |
| UnixSocketConnection::Stream * | incomingStream (const SharedPointer< UnixSocketConnection > &connection) const |
| UnixSocketConnection::Stream * | outgoingStream (const SharedPointer< UnixSocketConnection > &connection) const |
| virtual bool | isBytewise () const |
Static Private Member Functions | |
| static void | destroyDatagram (struct buf *datagram) |
Private Attributes | |
| SocketType | m_Type |
| SocketState | m_State |
| DatagramBuffer | m_Datagrams |
| UnixSocketStream | m_Stream |
| SharedPointer< UnixSocketConnection > | m_Connection |
| bool | m_ConnectionSide |
| List< UnixSocket * > | m_PendingSockets |
| struct ucred | m_Creds |
Static Private Attributes | |
| static Mutex | m_ConnectionLock |
Additional Inherited Members | |
Static Public Attributes inherited from File | |
| static constexpr size_t | MaxReadPages = 32 |
Protected Member Functions inherited from File | |
| bool | tryAcquireFilesystemOperation (OperationBarrier::Lease &operation) const |
| virtual void | updateAttributes (const Attributes &attributes, uint32_t mask) |
| virtual bool | changeOwnership (size_t uid, size_t gid, bool changeUid, bool changeGid) |
| virtual bool | allowPhysicalPage () const |
| virtual bool | prepareWrite (uint64_t location, uint64_t size) |
| virtual bool | allowResize (size_t oldSize, size_t newSize) |
| virtual bool | prepareShrink (const ShrinkContext &context, UniquePointer< PreparedShrink > &prepared) |
| virtual bool | resizeFile (size_t size) |
| virtual bool | allocateFileRange (size_t offset, size_t length) |
| virtual Mutex & | writeSerializationLock () |
| virtual Mutex & | dataMutationLock () |
| virtual size_t & | physicalPageLoans () |
| bool | clearDataCache () |
| virtual uintptr_t | readBlock (uint64_t location) |
| virtual bool | readPage (uint64_t location, uintptr_t destination) |
| virtual bool | readPages (ReadPage *pages, size_t count) |
| virtual void | writeBlock (uint64_t location, uintptr_t addr) |
| virtual void | writeBlocks (uint64_t location, uintptr_t addr, size_t length) |
| virtual void | extend (size_t newSize) |
| virtual void | extend (size_t newSize, uint64_t location, uint64_t size) |
| virtual void | publishInodeEvent (const FileEvent &event) |
| void | dataChanged () |
| void | getFilesystemLabel (HugeStaticString &s) |
| void | enableFillCacheWriteback () |
| void | shutdownFillCacheWriteback () |
| bool | syncFillCache (size_t offset, bool async, bool &present) |
| virtual bool | useFillCache () const |
| virtual MUST_USE_RESULT bool | pinBlock (uint64_t location) |
| virtual MUST_USE_RESULT uintptr_t | acquireCachedBlock (uint64_t location, bool retryChanged) |
| virtual void | unpinBlock (uint64_t location) |
| void | evict (uint64_t location) |
| void | setPermissionsOnly (uint32_t perms) |
| void | setUidOnly (size_t uid) |
| void | setGidOnly (size_t gid) |
| void | retainDetachedParent () |
| void | moveNamespace (const String &name, File *parent) |
| bool | snapshotNamespace (ParentLease &parent, String &name, FileEventMask interest) const |
| virtual CacheState & | cacheState () |
| void | setPhysicalMappingFlags (size_t flags) |
Protected Member Functions inherited from ReadinessSource | |
| void | notifyReadiness (ReadyMask mask) |
| void | closeReadiness (ReadyMask mask=ReadyInvalid|ReadyHangup) |
Protected Member Functions inherited from FileEventSource | |
| bool | hasFileEventObservers (FileEventMask mask) const |
| void | notifyFileEvent (const FileEvent &event) |
| void | notifyFinalFileEvent (const FileEvent &event) |
| void | beginFinalFileEvent (const FileEvent &event) |
| void | drainFileEvents () |
| void | closeFileEvents () |
Static Protected Member Functions inherited from File | |
| static bool | writeCallback (CacheConstants::CallbackCause cause, uintptr_t loc, uintptr_t page, void *meta) |
| static bool | fillCacheCallback (CacheConstants::CallbackCause cause, uintptr_t loc, uintptr_t page, void *meta) |
Static Protected Member Functions inherited from FileEventSource | |
| static bool | anyFileEventObservers () |
Protected Attributes inherited from File | |
| String | m_Name |
| Time::Timestamp | m_AccessedTime |
| Time::Timestamp | m_ModifiedTime |
| Time::Timestamp | m_CreationTime |
| uintptr_t | m_Inode |
| uintptr_t | m_FutexIdentity = 0 |
| class Filesystem * | m_pFilesystem |
| size_t | m_Size |
| File * | m_pParent |
| Mutex | m_MetadataLock |
| File * | m_pDetachedParent |
| bool | m_bDetachedParentHandled |
| size_t | m_nWriters |
| size_t | m_nReaders |
| size_t | m_Uid |
| size_t | m_Gid |
| uint32_t | m_Permissions |
| CacheState | m_CacheState |
| bool | m_bDirect |
| Mutex | m_WriteLock |
| Mutex | m_DataMutationLock |
| size_t | m_PhysicalPageLoans = 0 |
| size_t | m_PhysicalMappingFlags = 0 |
| Mutex | m_Lock |
| List< MonitorTarget * > | m_MonitorTargets |
A UNIX socket.
Definition at line 263 of file UnixFilesystem.h.
|
private |
Definition at line 423 of file UnixFilesystem.h.
|
private |
Definition at line 391 of file UnixFilesystem.h.
| enum UnixSocket::SocketState |
Definition at line 267 of file UnixFilesystem.h.
| enum UnixSocket::SocketType |
Definition at line 265 of file UnixFilesystem.h.
| UnixSocket::UnixSocket | ( | const String & | name, |
| Filesystem * | pFs, | ||
| File * | pParent, | ||
| UnixSocket * | other = nullptr, |
||
| SocketType | type = Datagram |
||
| ) |
Definition at line 569 of file UnixFilesystem.cc.
|
virtual |
Definition at line 592 of file UnixFilesystem.cc.
| void UnixSocket::acknowledgeBind | ( | ) |
Definition at line 1064 of file UnixFilesystem.cc.
| bool UnixSocket::addSocket | ( | UnixSocket * | socket | ) |
Definition at line 1087 of file UnixFilesystem.cc.
| void UnixSocket::addWaiter | ( | Semaphore * | waiter, |
| bool | read, | ||
| bool | write | ||
| ) |
Definition at line 1142 of file UnixFilesystem.cc.
Definition at line 1227 of file UnixFilesystem.cc.
| bool UnixSocket::bind | ( | UnixSocket * | other, |
| bool | block = false |
||
| ) |
Definition at line 932 of file UnixFilesystem.cc.
|
staticprivate |
Definition at line 922 of file UnixFilesystem.cc.
| void UnixSocket::failConnection | ( | ) |
Definition at line 1376 of file UnixFilesystem.cc.
|
inline |
Definition at line 383 of file UnixFilesystem.h.
| struct ucred UnixSocket::getPeerCredentials | ( | ) | const |
Definition at line 1400 of file UnixFilesystem.cc.
| UnixSocket * UnixSocket::getSocket | ( | bool | block = false | ) |
Definition at line 1124 of file UnixFilesystem.cc.
| UnixSocket::SocketState UnixSocket::getState | ( | ) | const |
Definition at line 1321 of file UnixFilesystem.cc.
|
private |
Definition at line 1326 of file UnixFilesystem.cc.
|
inline |
Definition at line 362 of file UnixFilesystem.h.
|
private |
Definition at line 1413 of file UnixFilesystem.cc.
|
inlineprivatevirtual |
File subclasses can define this and return true if they require read() calls to perform actual data reads, and false if readBlock() is otherwise sufficient.
Reimplemented from File.
Definition at line 401 of file UnixFilesystem.h.
|
inlinevirtual |
Whether ordinary reads and writes consume a persistent byte offset.
Reimplemented from File.
Definition at line 320 of file UnixFilesystem.h.
|
inlinevirtual |
Returns true if the File is actually a socket.
Reimplemented from File.
Definition at line 316 of file UnixFilesystem.h.
| bool UnixSocket::markListening | ( | ) |
Definition at line 1303 of file UnixFilesystem.cc.
|
private |
Definition at line 1536 of file UnixFilesystem.cc.
|
private |
Definition at line 1418 of file UnixFilesystem.cc.
|
virtual |
Reads bytes from the file, if isBytewise() == true.
Reimplemented from File.
Definition at line 659 of file UnixFilesystem.cc.
|
overridevirtual |
Rising-edge sequences for the endpoint's reusable I/O predicates.
Reimplemented from ReadinessSource.
Definition at line 1344 of file UnixFilesystem.cc.
References Buffer< T, allowShortOperation >::readableGeneration().
| bool UnixSocket::readShutdown | ( | ) | const |
Definition at line 1055 of file UnixFilesystem.cc.
| bool UnixSocket::receiveDatagram | ( | uint64_t | size, |
| uintptr_t | buffer, | ||
| bool | bCanBlock, | ||
| String & | from, | ||
| SharedPointer< SocketRights > & | rights, | ||
| uint64_t & | bytesRead, | ||
| uint64_t & | datagramLength | ||
| ) |
Remove one datagram, preserving its full length and ancillary ownership.
Definition at line 717 of file UnixFilesystem.cc.
References Mailbox< T, preallocatedSize, Notifications >::read(), SharedPointer< T >::reset(), and select().
| bool UnixSocket::receivePacket | ( | uint64_t | size, |
| uintptr_t | buffer, | ||
| bool | bCanBlock, | ||
| SharedPointer< SocketRights > & | rights, | ||
| uint64_t & | bytesRead, | ||
| uint64_t & | packetLength, | ||
| bool * | interrupted = nullptr |
||
| ) |
Definition at line 841 of file UnixFilesystem.cc.
| uint64_t UnixSocket::receiveStream | ( | struct iovec * | vectors, |
| size_t | vectorCount, | ||
| bool | bCanBlock, | ||
| SharedPointer< SocketRights > * | rights, | ||
| bool * | interrupted = nullptr |
||
| ) |
Definition at line 692 of file UnixFilesystem.cc.
| uint64_t UnixSocket::receiveStream | ( | uint64_t | size, |
| uintptr_t | buffer, | ||
| bool | bCanBlock, | ||
| SharedPointer< SocketRights > * | rights, | ||
| bool * | interrupted = nullptr |
||
| ) |
Read stream bytes and optionally detach the first crossed control record.
Definition at line 685 of file UnixFilesystem.cc.
References receiveStream().
Referenced by receiveStream().
Here is the caller graph for this function:| uint64_t UnixSocket::recvfrom | ( | uint64_t | size, |
| uintptr_t | buffer, | ||
| bool | bCanBlock, | ||
| String & | from | ||
| ) |
Definition at line 665 of file UnixFilesystem.cc.
| void UnixSocket::removeWaiter | ( | Event * | event | ) |
Definition at line 1283 of file UnixFilesystem.cc.
| void UnixSocket::removeWaiter | ( | Semaphore * | waiter | ) |
Definition at line 1207 of file UnixFilesystem.cc.
|
virtual |
Similar to POSIX's select() function
Reimplemented from File.
Definition at line 596 of file UnixFilesystem.cc.
References Buffer< T, allowShortOperation >::canRead(), Mailbox< T, preallocatedSize, Notifications >::canWrite(), Mailbox< T, preallocatedSize, Notifications >::dataReady(), and Mailbox< T, preallocatedSize, Notifications >::waitFor().
Referenced by UnixSocketSyscalls::queryReady(), and receiveDatagram().
Here is the caller graph for this function:| bool UnixSocket::sendDatagram | ( | uint64_t | size, |
| uintptr_t | buffer, | ||
| bool | bCanBlock, | ||
| uintptr_t | source, | ||
| const SharedPointer< SocketRights > & | rights, | ||
| int * | error = nullptr |
||
| ) |
Queue one indivisible datagram and its optional descriptor ownership.
Definition at line 864 of file UnixFilesystem.cc.
References File::dataChanged(), Mailbox< T, preallocatedSize, Notifications >::tryWrite(), and Mailbox< T, preallocatedSize, Notifications >::write().
Referenced by writeBytewise().
Here is the caller graph for this function:| bool UnixSocket::sendPacket | ( | uint64_t | size, |
| uintptr_t | buffer, | ||
| bool | bCanBlock, | ||
| const SharedPointer< SocketRights > & | rights, | ||
| int * | error = nullptr |
||
| ) |
Queue or consume one record on a connected sequenced-packet socket.
Definition at line 802 of file UnixFilesystem.cc.
Referenced by writeBytewise().
Here is the caller graph for this function:| uint64_t UnixSocket::sendStream | ( | const struct iovec * | vectors, |
| size_t | vectorCount, | ||
| bool | bCanBlock, | ||
| const SharedPointer< SocketRights > & | rights, | ||
| bool * | interrupted = nullptr |
||
| ) |
Definition at line 780 of file UnixFilesystem.cc.
| uint64_t UnixSocket::sendStream | ( | uint64_t | size, |
| uintptr_t | buffer, | ||
| bool | bCanBlock, | ||
| const SharedPointer< SocketRights > & | rights, | ||
| bool * | interrupted = nullptr |
||
| ) |
Write one ordered stream record with optional descriptor ownership.
Definition at line 773 of file UnixFilesystem.cc.
References sendStream().
Referenced by sendStream(), and writeBytewise().
Here is the caller graph for this function:
|
private |
Definition at line 1423 of file UnixFilesystem.cc.
| bool UnixSocket::shutdown | ( | int | how | ) |
Definition at line 1012 of file UnixFilesystem.cc.
| void UnixSocket::unbind | ( | ) |
Definition at line 962 of file UnixFilesystem.cc.
| bool UnixSocket::wasConnected | ( | ) | const |
Definition at line 1339 of file UnixFilesystem.cc.
|
virtual |
Writes bytes to the file, if isBytewise() == true.
Reimplemented from File.
Definition at line 758 of file UnixFilesystem.cc.
References sendDatagram(), sendPacket(), and sendStream().
| bool UnixSocket::writeShutdown | ( | ) | const |
Definition at line 1046 of file UnixFilesystem.cc.
|
private |
Definition at line 431 of file UnixFilesystem.h.
|
staticprivate |
Definition at line 442 of file UnixFilesystem.h.
|
private |
Definition at line 432 of file UnixFilesystem.h.
|
private |
Definition at line 438 of file UnixFilesystem.h.
|
private |
Definition at line 424 of file UnixFilesystem.h.
|
private |
Definition at line 435 of file UnixFilesystem.h.
|
private |
Definition at line 416 of file UnixFilesystem.h.
|
private |
Definition at line 429 of file UnixFilesystem.h.
|
private |
Definition at line 415 of file UnixFilesystem.h.