The Pedigree Project  0.1
Classes | Public Types | Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
UnixSocket Class Reference

#include <UnixFilesystem.h>

+ Inheritance diagram for UnixSocket:
+ Collaboration diagram for UnixSocket:

Classes

struct  buf
 

Public Types

enum  SocketType { Streaming, Datagram }
 
enum  SocketState {
  Listening, Connecting, Inactive, Active,
  Closed
}
 

Public Member Functions

 UnixSocket (String name, Filesystem *pFs, File *pParent, UnixSocket *other=nullptr, SocketType type=Datagram)
 
virtual ~UnixSocket ()
 
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)
 
virtual int select (bool bWriting=false, int timeout=0)
 
virtual bool isSocket () const
 
UnixSocketgetOther () const
 
bool bind (UnixSocket *other, bool block=false)
 
void unbind ()
 
void acknowledgeBind ()
 
void addSocket (UnixSocket *socket)
 
UnixSocketgetSocket (bool block=false)
 
void addWaiter (Semaphore *waiter)
 
void removeWaiter (Semaphore *waiter)
 
void addWaiter (Thread *thread, Event *event)
 
void removeWaiter (Event *event)
 
SocketType getType () const
 
SocketState getState () const
 
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
 
virtual uint64_t write (uint64_t location, uint64_t size, uintptr_t buffer, bool bCanBlock=true) final
 
virtual physical_uintptr_t getPhysicalPage (size_t offset)
 
virtual void returnPhysicalPage (size_t offset)
 
virtual void sync ()
 
virtual void sync (size_t offset, bool async)
 
Time::Timestamp getCreationTime ()
 
void setCreationTime (Time::Timestamp t)
 
Time::Timestamp getAccessedTime ()
 
void setAccessedTime (Time::Timestamp t)
 
Time::Timestamp getModifiedTime ()
 
void setModifiedTime (Time::Timestamp t)
 
String getName () const
 
void getName (String &s) const
 
virtual String getFullPath (bool bWithLabel=true)
 
virtual void truncate ()
 
size_t getSize ()
 
void setSize (size_t sz)
 
virtual bool isSymlink ()
 
virtual bool isDirectory ()
 
virtual bool isPipe () const
 
virtual bool isFifo () const
 
uintptr_t getInode () const
 
virtual void setInode (uintptr_t inode)
 
FilesystemgetFilesystem () const
 
void setFilesystem (Filesystem *pFs)
 
virtual void fileAttributeChanged ()
 
virtual void increaseRefCount (bool bIsWriter)
 
virtual void decreaseRefCount (bool bIsWriter)
 
void setPermissions (uint32_t perms)
 
uint32_t getPermissions () const
 
void setUid (size_t uid)
 
size_t getUid () const
 
void setGid (size_t gid)
 
size_t getGid () const
 
FilegetParent () const
 
void monitor (Thread *pThread, Event *pEvent)
 
void cullMonitorTargets (Thread *pThread)
 
virtual bool supports (const size_t command) const
 
virtual int command (const size_t command, void *buffer)
 
virtual size_t getBlockSize () const
 
void enableDirect ()
 
void disableDirect ()
 
virtual void preallocate (size_t expectedSize, bool zero=true)
 
virtual Fileopen ()
 

Private Types

typedef Buffer< uint8_t, true > UnixSocketStream
 

Private Member Functions

void setCreds ()
 
virtual bool isBytewise () const
 

Private Attributes

SocketType m_Type
 
SocketState m_State
 
RingBuffer< struct buf * > m_Datagrams
 
UnixSocketm_pOther
 
UnixSocketStream m_Stream
 
List< UnixSocket * > m_PendingSockets
 
Mutex m_Mutex
 
Semaphore m_AckWaiter
 
struct ucred m_Creds
 

Additional Inherited Members

- Protected Member Functions inherited from File
virtual uintptr_t readBlock (uint64_t location)
 
virtual void writeBlock (uint64_t location, uintptr_t addr)
 
virtual void extend (size_t newSize)
 
virtual void extend (size_t newSize, uint64_t location, uint64_t size)
 
void dataChanged ()
 
void getFilesystemLabel (HugeStaticString &s)
 
virtual void pinBlock (uint64_t location)
 
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)
 
- Static Protected Member Functions inherited from File
static void writeCallback (CacheConstants::CallbackCause cause, uintptr_t loc, uintptr_t page, void *meta)
 
- Protected Attributes inherited from File
String m_Name
 
Time::Timestamp m_AccessedTime
 
Time::Timestamp m_ModifiedTime
 
Time::Timestamp m_CreationTime
 
uintptr_t m_Inode
 
class Filesystemm_pFilesystem
 
size_t m_Size
 
Filem_pParent
 
size_t m_nWriters
 
size_t m_nReaders
 
size_t m_Uid
 
size_t m_Gid
 
uint32_t m_Permissions
 
HashTable< DataCacheKey, uintptr_t > m_DataCache
 
bool m_bDirect
 
Cache m_FillCache
 
Mutex m_Lock
 
List< MonitorTarget * > m_MonitorTargets
 

Detailed Description

A UNIX socket.

Definition at line 111 of file UnixFilesystem.h.

Constructor & Destructor Documentation

UnixSocket::~UnixSocket ( )
virtual
Todo:
update read/write to handle the other socket going away correctly

Definition at line 54 of file UnixFilesystem.cc.

References assert, Directory::fromFile(), and Directory::remove().

Member Function Documentation

virtual bool UnixSocket::isBytewise ( ) const
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 216 of file UnixFilesystem.h.

virtual bool UnixSocket::isSocket ( ) const
inlinevirtual

Returns true if the File is actually a socket.

Reimplemented from File.

Definition at line 146 of file UnixFilesystem.h.

uint64_t UnixSocket::readBytewise ( uint64_t  location,
uint64_t  size,
uintptr_t  buffer,
bool  bCanBlock = true 
)
virtual

Reads bytes from the file, if isBytewise() == true.

Reimplemented from File.

Definition at line 123 of file UnixFilesystem.cc.

int UnixSocket::select ( bool  bWriting = false,
int  timeout = 0 
)
virtual

Similar to POSIX's select() function

Returns
1 if ready for reading/writing, 0 otherwise
Note
Default implementation says always ready to read/write so be sure to override if that's not right

Reimplemented from File.

Definition at line 79 of file UnixFilesystem.cc.

Referenced by UnixSocketSyscalls::shutdown().

+ Here is the caller graph for this function:

uint64_t UnixSocket::writeBytewise ( uint64_t  location,
uint64_t  size,
uintptr_t  buffer,
bool  bCanBlock = true 
)
virtual

Writes bytes to the file, if isBytewise() == true.

Reimplemented from File.

Definition at line 176 of file UnixFilesystem.cc.

References ERROR, Process::getId(), File::getName(), Process::getUserId(), Processor::information(), and String::view().


The documentation for this class was generated from the following files: