|
CPN
Computational Process Networks
|
Generic file handle could be a file, or a socket or a device. More...
#include <FileHandle.h>
Inheritance diagram for FileHandle:
Collaboration diagram for FileHandle:Public Types | |
| typedef AutoLock< PthreadMutex > | ALock |
Public Member Functions | |
| FileHandle () | |
| Construct a closed FileHandle. More... | |
| FileHandle (int filed) | |
| Construct a FileHandle with filed as the open file descriptor. More... | |
| virtual | ~FileHandle () |
| Close the file descriptor. Use Reset if one wants to not close the file descriptor. More... | |
| int | Poll (double timeout) |
| bool | Readable (bool r) |
| Set that the file is currently readable or not. More... | |
| bool | Readable () const |
| Gives the current readability status of the file. More... | |
| bool | Writeable (bool w) |
| Set that this file is currently writeable or not. More... | |
| bool | Writeable () const |
| Gives the current writability status of the file. More... | |
| int | FD () const |
| int | FD (int filed) |
| Set the current file descriptor. More... | |
| bool | Eof () const |
| bool | Eof (bool e) |
| Set/reset the end of file condition. More... | |
| bool | Good () const |
| Convenience method for testing if the file this FileHandle has is open and not at end of file. More... | |
| bool | Closed () const |
| void | SetBlocking (bool blocking) |
| Manipulate how the current file handles blocking. More... | |
| bool | IsBlocking () const |
| Test if the current file is in blocking or non blocking mode. More... | |
| void | Reset () |
| Clear all internal state including the file descriptor! WARNING does not close the file! More... | |
| void | Close () |
| Close the file and reset the internal state. More... | |
| unsigned | Read (void *ptr, unsigned len) |
| Read data from the file descriptor. More... | |
| unsigned | Readv (const iovec *iov, int iovcnt) |
| scatter gather io version of Read More... | |
| unsigned | Write (const void *ptr, unsigned len) |
| Write data to the file descriptor. More... | |
| unsigned | Writev (const iovec *iov, int iovcnt) |
| scatter gather io version of Write More... | |
| void | Flush () |
| Tell the OS to flush any buffers it has. May not be supported for all file types. More... | |
Static Public Member Functions | |
| static int | Poll (IteratorRef< FileHandle * > begin, IteratorRef< FileHandle * > end, double timeout) |
| poll a list of FileHandles for any activity and call the appropriate On method. More... | |
| static void | SetBlocking (int fd, bool blocking) |
| a convenience method that allows one to set the same blocking parameters for a file descriptor without setting it inside a FileHandle. More... | |
| static bool | IsBlocking (int fd) |
| Test the given file descriptor if it is in blocking mode. More... | |
Protected Member Functions | |
| virtual void | OnReadable () |
| Called by Poll when it detects that the file is readable. More... | |
| virtual void | OnWriteable () |
| Called by Poll when it detects that the file is writeable. More... | |
Protected Attributes | |
| PthreadMutex | file_lock |
| int | fd |
| bool | readable |
| bool | writeable |
| bool | eof |
Private Member Functions | |
| FileHandle (const FileHandle &) | |
| FileHandle & | operator= (const FileHandle &) |
Generic file handle could be a file, or a socket or a device.
If needed wouldn't be very hard to add an open function here.
Definition at line 41 of file FileHandle.h.
| typedef AutoLock<PthreadMutex> FileHandle::ALock |
Definition at line 43 of file FileHandle.h.
| FileHandle::FileHandle | ( | ) |
| FileHandle::FileHandle | ( | int | filed | ) |
Construct a FileHandle with filed as the open file descriptor.
| filed | the file descriptor to use |
Definition at line 96 of file FileHandle.cc.
|
virtual |
Close the file descriptor. Use Reset if one wants to not close the file descriptor.
Definition at line 101 of file FileHandle.cc.
Here is the call graph for this function:
|
private |
| void FileHandle::Close | ( | ) |
Close the file and reset the internal state.
Definition at line 146 of file FileHandle.cc.
References eof, fd, file_lock, readable, and writeable.
Referenced by CPN::ConnectionServer::Close(), CPN::RemoteContext::EntryPoint(), CPN::RemoteQueue::HandleError(), CPN::RemoteQueue::InternalCheckStatus(), and CPN::RemoteContextDaemon::Terminate().
Here is the caller graph for this function:
|
inline |
Definition at line 128 of file FileHandle.h.
Referenced by SocketHandle::Connect(), CPN::ConnectionServer::ConnectReader(), CPN::ConnectionServer::ConnectWriter(), CPN::RemoteQueue::FileThreadEntryPoint(), CPN::RemoteQueue::InternalCheckStatus(), CPN::RemoteQueue::LogState(), CPN::ConnectionServer::LogState(), CPN::RemoteContextDaemon::Run(), CPN::RemoteContextDaemon::Client::Send(), and CPN::RemoteContext::SendMessage().
Here is the caller graph for this function:
|
inline |
Definition at line 115 of file FileHandle.h.
References eof, and file_lock.
Referenced by CPN::RemoteQueue::EnqueuePacket(), CPN::RemoteContext::EntryPoint(), CPN::RemoteQueue::InternalCheckStatus(), CPN::RemoteContextDaemon::Client::Read(), and CPN::RemoteQueue::Read().
Here is the caller graph for this function:Set/reset the end of file condition.
| e | the new end of file condition |
Definition at line 120 of file FileHandle.h.
References eof, and file_lock.
|
inline |
Definition at line 106 of file FileHandle.h.
Referenced by ServerSocketHandle::Accept(), CPN::RemoteContextDaemon::Client::Client(), SocketHandle::Connect(), CPN::ConnectionServer::ConnectWriter(), SocketHandle::CreatePair(), CPN::RemoteQueue::FileThreadEntryPoint(), Flush(), CPN::ConnectionServer::GetAddress(), SocketHandle::GetKeepAlive(), SocketHandle::GetLingerTimeout(), SocketHandle::GetNoDelay(), SocketHandle::GetPendingError(), SocketHandle::GetReceiveBufferSize(), SocketHandle::GetReceiveTimeout(), SocketHandle::GetSendBufferSize(), SocketHandle::GetSendTimeout(), IsBlocking(), ServerSocketHandle::Listen(), Poll(), CPN::RemoteContextDaemon::Run(), SetBlocking(), SocketHandle::SetKeepAlive(), SocketHandle::SetLingerTimeout(), SocketHandle::SetNoDelay(), SocketHandle::SetReceiveBufferSize(), SocketHandle::SetReceiveTimeout(), SocketHandle::SetSendBufferSize(), SocketHandle::SetSendTimeout(), SocketHandle::ShutdownRead(), SocketHandle::ShutdownWrite(), and WakeupHandle::WakeupHandle().
Here is the caller graph for this function:Set the current file descriptor.
| filed | the new file descriptor |
Definition at line 111 of file FileHandle.h.
| void FileHandle::Flush | ( | ) |
Tell the OS to flush any buffers it has. May not be supported for all file types.
Definition at line 293 of file FileHandle.cc.
References FD().
Here is the call graph for this function:
|
inline |
Convenience method for testing if the file this FileHandle has is open and not at end of file.
Definition at line 125 of file FileHandle.h.
References eof, fd, and file_lock.
Referenced by CPN::RemoteContext::EntryPoint(), and CPN::RemoteContextDaemon::Client::Read().
Here is the caller graph for this function:| bool FileHandle::IsBlocking | ( | ) | const |
Test if the current file is in blocking or non blocking mode.
Definition at line 128 of file FileHandle.cc.
References FD().
Here is the call graph for this function:Test the given file descriptor if it is in blocking mode.
| fd | the file descriptor to test |
Definition at line 132 of file FileHandle.cc.
|
inlineprotectedvirtual |
Called by Poll when it detects that the file is readable.
Reimplemented in WakeupHandle.
Definition at line 210 of file FileHandle.h.
References Readable().
Referenced by Poll().
Here is the call graph for this function:
Here is the caller graph for this function:
|
inlineprotectedvirtual |
Called by Poll when it detects that the file is writeable.
Definition at line 212 of file FileHandle.h.
References Writeable().
Referenced by Poll().
Here is the call graph for this function:
Here is the caller graph for this function:
|
private |
|
static |
poll a list of FileHandles for any activity and call the appropriate On method.
Definition at line 34 of file FileHandle.cc.
References FD(), fd, OnReadable(), OnWriteable(), Readable(), and Writeable().
Referenced by CPN::RemoteContext::EntryPoint(), CPN::RemoteQueue::FileThreadEntryPoint(), CPN::ConnectionServer::Poll(), Poll(), and CPN::RemoteContextDaemon::Run().
Here is the call graph for this function:
Here is the caller graph for this function:| int FileHandle::Poll | ( | double | timeout | ) |
Poll the current file descriptor for activity specified by the current readable or writeable status, if false poll that value, and call one of OnWriteable or OnReadable whos default action is to set Readable or Writeable to true.
| timeout | -1 to wait forever for activity 0 to poll and return immediately or a time to wait in seconds. |
Definition at line 106 of file FileHandle.cc.
References Poll().
Here is the call graph for this function:| unsigned FileHandle::Read | ( | void * | ptr, |
| unsigned | len | ||
| ) |
Read data from the file descriptor.
Will set the end of file condition if read detects end of file.
| ptr | pointer to write data to |
| len | the maximum number of bytes to write to ptr |
Definition at line 159 of file FileHandle.cc.
References eof, fd, file_lock, Readable(), and readable.
Referenced by CPN::RemoteQueue::D4RTagPacket(), and WakeupHandle::Read().
Here is the call graph for this function:
Here is the caller graph for this function:Set that the file is currently readable or not.
| r | true or false |
Definition at line 86 of file FileHandle.h.
References file_lock, and readable.
Referenced by CPN::RemoteContext::EntryPoint(), Poll(), CPN::ConnectionServer::Poll(), and CPN::RemoteQueue::Read().
Here is the caller graph for this function:
|
inline |
Gives the current readability status of the file.
Definition at line 91 of file FileHandle.h.
References file_lock, and readable.
Referenced by ServerSocketHandle::Accept(), CPN::RemoteContextDaemon::Client::Client(), OnReadable(), CPN::RemoteContextDaemon::Read(), Read(), Readv(), SocketHandle::Recv(), CPN::RemoteContextDaemon::Run(), and WakeupHandle::WakeupHandle().
Here is the caller graph for this function:| unsigned FileHandle::Readv | ( | const iovec * | iov, |
| int | iovcnt | ||
| ) |
scatter gather io version of Read
Definition at line 190 of file FileHandle.cc.
References eof, fd, file_lock, Readable(), and readable.
Referenced by CPN::RemoteQueue::EnqueuePacket().
Here is the call graph for this function:
Here is the caller graph for this function:| void FileHandle::Reset | ( | ) |
Clear all internal state including the file descriptor! WARNING does not close the file!
Definition at line 138 of file FileHandle.cc.
References eof, fd, file_lock, readable, and writeable.
Referenced by CPN::ConnectionServer::ConnectWriter(), CPN::RemoteQueue::FileThreadEntryPoint(), and ~FileHandle().
Here is the caller graph for this function:| void FileHandle::SetBlocking | ( | bool | blocking | ) |
Manipulate how the current file handles blocking.
| blocking | true to set to blocking mode (default) false to set to non blocking mode. |
In non blocking mode all reads and writes will not block. Use Poll to block.
Definition at line 111 of file FileHandle.cc.
References FD().
Referenced by WakeupHandle::WakeupHandle().
Here is the call graph for this function:
Here is the caller graph for this function:a convenience method that allows one to set the same blocking parameters for a file descriptor without setting it inside a FileHandle.
| fd | the file descriptor |
| blocking | true or false see SetBlock |
Definition at line 115 of file FileHandle.cc.
| unsigned FileHandle::Write | ( | const void * | ptr, |
| unsigned | len | ||
| ) |
Write data to the file descriptor.
| ptr | pointer to beginning of data to write |
| len | length of data to write |
Definition at line 225 of file FileHandle.cc.
References fd, file_lock, and Writeable().
Referenced by CPN::ConnectionServer::ConnectWriter(), CPN::RemoteContextDaemon::Client::Send(), CPN::RemoteContext::SendMessage(), and CPN::RemoteQueue::WriteBytes().
Here is the call graph for this function:
Here is the caller graph for this function:Set that this file is currently writeable or not.
| w | true or false |
Definition at line 97 of file FileHandle.h.
References file_lock, and writeable.
Referenced by Poll().
Here is the caller graph for this function:
|
inline |
Gives the current writability status of the file.
Definition at line 102 of file FileHandle.h.
References file_lock, and writeable.
Referenced by OnWriteable(), SocketHandle::Send(), WakeupHandle::WakeupHandle(), Write(), and Writev().
Here is the caller graph for this function:| unsigned FileHandle::Writev | ( | const iovec * | iov, |
| int | iovcnt | ||
| ) |
scatter gather io version of Write
Definition at line 261 of file FileHandle.cc.
References fd, file_lock, and Writeable().
Referenced by CPN::RemoteQueue::WriteBytes().
Here is the call graph for this function:
Here is the caller graph for this function:
|
protected |
Definition at line 217 of file FileHandle.h.
Referenced by Close(), Eof(), Good(), Read(), Readv(), SocketHandle::Recv(), and Reset().
|
protected |
Definition at line 214 of file FileHandle.h.
Referenced by Close(), Closed(), FD(), Good(), Poll(), Read(), Readv(), SocketHandle::Recv(), Reset(), SocketHandle::Send(), Write(), Writev(), and ~FileHandle().
|
mutableprotected |
Definition at line 213 of file FileHandle.h.
Referenced by Close(), Closed(), Eof(), FD(), Good(), Read(), Readable(), Readv(), SocketHandle::Recv(), Reset(), SocketHandle::Send(), WakeupHandle::SendWakeup(), Write(), Writeable(), and Writev().
|
protected |
Definition at line 215 of file FileHandle.h.
Referenced by Close(), Read(), Readable(), Readv(), SocketHandle::Recv(), and Reset().
|
protected |
Definition at line 216 of file FileHandle.h.
Referenced by Close(), Reset(), and Writeable().
1.8.5