|
CPN
Computational Process Networks
|
A FileHandle customized with some socket specific functionality and functions. More...
#include <SocketHandle.h>
Inheritance diagram for SocketHandle:
Collaboration diagram for SocketHandle:Classes | |
| struct | SendOpts |
Public Types | |
| typedef FileHandle::ALock | ALock |
Public Member Functions | |
| SocketHandle () | |
| SocketHandle (int nfd) | |
| void | Connect (const SocketAddress &addr) |
| Create a new socket and try to connect to the given address. More... | |
| void | Connect (const SockAddrList &addrs) |
| Create a new socket and try to connect to one of the addresses in the address list. More... | |
| void | ShutdownRead () |
| Shutdown the read end of this socket. This does NOT close the socket! Any future attempt to read from this socket will fail. More... | |
| void | ShutdownWrite () |
| Shutdown the write end of this socket. Any future attempt to write to this socket will fail. This is how you send an end of file down the socket. More... | |
| unsigned | Recv (void *ptr, unsigned len, bool block) |
| unsigned | Send (const void *ptr, unsigned len, const SendOpts &opts) |
| int | GetPendingError () |
| Get and clear any pending error. More... | |
| void | SetKeepAlive (int ka) |
| int | GetKeepAlive () |
| void | SetLingerTimeout (int seconds) |
| Set the linger socket options. More... | |
| int | GetLingerTimeout () |
| void | SetReceiveBufferSize (int size) |
| int | GetReceiveBufferSize () |
| void | SetSendBufferSize (int size) |
| int | GetSendBufferSize () |
| void | SetReceiveTimeout (double timeout) |
| void | SetSendTimeout (double timeout) |
| double | GetReceiveTimeout () |
| double | GetSendTimeout () |
| void | SetNoDelay (bool nodelay) |
| bool | GetNoDelay () |
| 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 void | CreatePair (SocketHandle &sock1, SocketHandle &sock2) |
| Create a socket pair. More... | |
| static void | CreatePair (int fd[2]) |
| Convenience function that returns actual file descriptors. More... | |
| 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 | |
| bool | Connect (const SocketAddress &addr, int &error) |
A FileHandle customized with some socket specific functionality and functions.
Definition at line 34 of file SocketHandle.h.
| typedef FileHandle::ALock SocketHandle::ALock |
Definition at line 36 of file SocketHandle.h.
|
inline |
Definition at line 38 of file SocketHandle.h.
|
inline |
Definition at line 39 of file SocketHandle.h.
|
inherited |
Close the file and reset the internal state.
Definition at line 146 of file FileHandle.cc.
References FileHandle::eof, FileHandle::fd, FileHandle::file_lock, FileHandle::readable, and FileHandle::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:
|
inlineinherited |
Definition at line 128 of file FileHandle.h.
References FileHandle::fd, and FileHandle::file_lock.
Referenced by 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:| void SocketHandle::Connect | ( | const SocketAddress & | addr | ) |
Create a new socket and try to connect to the given address.
| addr | the address to connect to |
Definition at line 48 of file SocketHandle.cc.
Referenced by Connect(), CPN::ConnectionServer::ConnectWriter(), and CPN::RemoteContext::RemoteContext().
Here is the caller graph for this function:| void SocketHandle::Connect | ( | const SockAddrList & | addrs | ) |
Create a new socket and try to connect to one of the addresses in the address list.
| addrs | the addresses to try to connect to |
Definition at line 53 of file SocketHandle.cc.
References Connect().
Here is the call graph for this function:
|
private |
Definition at line 64 of file SocketHandle.cc.
References ASSERT, FileHandle::Closed(), SocketAddress::Family(), FileHandle::FD(), SocketAddress::GetAddr(), and SocketAddress::GetLen().
Here is the call graph for this function:
|
static |
Create a socket pair.
| sock1 | SocketHandle to fill with one of the created file descriptors |
| sock2 | SocketHandle to fill with one of the created file descriptors |
Definition at line 33 of file SocketHandle.cc.
References ASSERT, and FileHandle::FD().
Here is the call graph for this function:
|
static |
Convenience function that returns actual file descriptors.
Definition at line 42 of file SocketHandle.cc.
|
inlineinherited |
Definition at line 115 of file FileHandle.h.
References FileHandle::eof, and FileHandle::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 FileHandle::eof, and FileHandle::file_lock.
|
inlineinherited |
Definition at line 106 of file FileHandle.h.
References FileHandle::fd, and FileHandle::file_lock.
Referenced by ServerSocketHandle::Accept(), CPN::RemoteContextDaemon::Client::Client(), Connect(), CPN::ConnectionServer::ConnectWriter(), CreatePair(), CPN::RemoteQueue::FileThreadEntryPoint(), FileHandle::Flush(), CPN::ConnectionServer::GetAddress(), GetKeepAlive(), GetLingerTimeout(), GetNoDelay(), GetPendingError(), GetReceiveBufferSize(), GetReceiveTimeout(), GetSendBufferSize(), GetSendTimeout(), FileHandle::IsBlocking(), ServerSocketHandle::Listen(), FileHandle::Poll(), CPN::RemoteContextDaemon::Run(), FileHandle::SetBlocking(), SetKeepAlive(), SetLingerTimeout(), SetNoDelay(), SetReceiveBufferSize(), SetReceiveTimeout(), SetSendBufferSize(), SetSendTimeout(), ShutdownRead(), 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.
References FileHandle::fd, and FileHandle::file_lock.
|
inherited |
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 FileHandle::FD().
Here is the call graph for this function:| int SocketHandle::GetKeepAlive | ( | ) |
Definition at line 219 of file SocketHandle.cc.
References FileHandle::FD().
Here is the call graph for this function:| int SocketHandle::GetLingerTimeout | ( | ) |
Definition at line 239 of file SocketHandle.cc.
References FileHandle::FD().
Here is the call graph for this function:| bool SocketHandle::GetNoDelay | ( | ) |
Definition at line 326 of file SocketHandle.cc.
References FileHandle::FD().
Here is the call graph for this function:| int SocketHandle::GetPendingError | ( | ) |
Get and clear any pending error.
Definition at line 204 of file SocketHandle.cc.
References FileHandle::FD().
Here is the call graph for this function:| int SocketHandle::GetReceiveBufferSize | ( | ) |
Definition at line 258 of file SocketHandle.cc.
References FileHandle::FD().
Here is the call graph for this function:| double SocketHandle::GetReceiveTimeout | ( | ) |
Definition at line 301 of file SocketHandle.cc.
References FileHandle::FD().
Here is the call graph for this function:| int SocketHandle::GetSendBufferSize | ( | ) |
Definition at line 273 of file SocketHandle.cc.
References FileHandle::FD().
Here is the call graph for this function:| double SocketHandle::GetSendTimeout | ( | ) |
Definition at line 310 of file SocketHandle.cc.
References FileHandle::FD().
Here is the call graph for this function:
|
inlineinherited |
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 FileHandle::eof, FileHandle::fd, and FileHandle::file_lock.
Referenced by CPN::RemoteContext::EntryPoint(), and CPN::RemoteContextDaemon::Client::Read().
Here is the caller graph for this function:
|
inherited |
Test if the current file is in blocking or non blocking mode.
Definition at line 128 of file FileHandle.cc.
References FileHandle::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.
|
inlineprotectedvirtualinherited |
Called by Poll when it detects that the file is readable.
Reimplemented in WakeupHandle.
Definition at line 210 of file FileHandle.h.
References FileHandle::Readable().
Referenced by FileHandle::Poll().
Here is the call graph for this function:
Here is the caller graph for this function:
|
inlineprotectedvirtualinherited |
Called by Poll when it detects that the file is writeable.
Definition at line 212 of file FileHandle.h.
References FileHandle::Writeable().
Referenced by FileHandle::Poll().
Here is the call graph for this function:
Here is the caller graph for this function:
|
staticinherited |
poll a list of FileHandles for any activity and call the appropriate On method.
Definition at line 34 of file FileHandle.cc.
References FileHandle::FD(), FileHandle::fd, FileHandle::OnReadable(), FileHandle::OnWriteable(), FileHandle::Readable(), and FileHandle::Writeable().
Referenced by CPN::RemoteContext::EntryPoint(), CPN::RemoteQueue::FileThreadEntryPoint(), CPN::ConnectionServer::Poll(), FileHandle::Poll(), and CPN::RemoteContextDaemon::Run().
Here is the call graph for this function:
Here is the caller graph for this function:
|
inherited |
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 FileHandle::Poll().
Here is the call graph for this function:
|
inherited |
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 FileHandle::eof, FileHandle::fd, FileHandle::file_lock, FileHandle::Readable(), and FileHandle::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 FileHandle::file_lock, and FileHandle::readable.
Referenced by CPN::RemoteContext::EntryPoint(), FileHandle::Poll(), CPN::ConnectionServer::Poll(), and CPN::RemoteQueue::Read().
Here is the caller graph for this function:
|
inlineinherited |
Gives the current readability status of the file.
Definition at line 91 of file FileHandle.h.
References FileHandle::file_lock, and FileHandle::readable.
Referenced by ServerSocketHandle::Accept(), CPN::RemoteContextDaemon::Client::Client(), FileHandle::OnReadable(), CPN::RemoteContextDaemon::Read(), FileHandle::Read(), FileHandle::Readv(), Recv(), CPN::RemoteContextDaemon::Run(), and WakeupHandle::WakeupHandle().
Here is the caller graph for this function:
|
inherited |
scatter gather io version of Read
Definition at line 190 of file FileHandle.cc.
References FileHandle::eof, FileHandle::fd, FileHandle::file_lock, FileHandle::Readable(), and FileHandle::readable.
Referenced by CPN::RemoteQueue::EnqueuePacket().
Here is the call graph for this function:
Here is the caller graph for this function:| unsigned SocketHandle::Recv | ( | void * | ptr, |
| unsigned | len, | ||
| bool | block | ||
| ) |
| ptr | pointer to memory to place read data |
| len | maximum number of bytes to read |
| block | If block true then wait for buffer to be full if block false don't wait for anything |
Definition at line 119 of file SocketHandle.cc.
References FileHandle::eof, FileHandle::fd, FileHandle::file_lock, FileHandle::Readable(), and FileHandle::readable.
Referenced by CPN::RemoteContext::EntryPoint(), and CPN::RemoteQueue::Read().
Here is the call graph for this function:
Here is the caller graph for this function:
|
inherited |
Clear all internal state including the file descriptor! WARNING does not close the file!
Definition at line 138 of file FileHandle.cc.
References FileHandle::eof, FileHandle::fd, FileHandle::file_lock, FileHandle::readable, and FileHandle::writeable.
Referenced by CPN::ConnectionServer::ConnectWriter(), CPN::RemoteQueue::FileThreadEntryPoint(), and FileHandle::~FileHandle().
Here is the caller graph for this function:| unsigned SocketHandle::Send | ( | const void * | ptr, |
| unsigned | len, | ||
| const SendOpts & | opts | ||
| ) |
| ptr | pointer to bytes to write |
| len | number of bytes to write |
| opts | an option object (note that a blank option object this function is exactly the same as Write) |
Definition at line 177 of file SocketHandle.cc.
References FileHandle::fd, FileHandle::file_lock, SocketHandle::SendOpts::flags, and FileHandle::Writeable().
Here is the call graph for this function:
|
inherited |
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 FileHandle::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.
| void SocketHandle::SetKeepAlive | ( | int | ka | ) |
Definition at line 213 of file SocketHandle.cc.
References FileHandle::FD().
Here is the call graph for this function:| void SocketHandle::SetLingerTimeout | ( | int | seconds | ) |
Set the linger socket options.
| seconds | number of seconds to linger, negative to turn off |
Definition at line 228 of file SocketHandle.cc.
References FileHandle::FD().
Here is the call graph for this function:| void SocketHandle::SetNoDelay | ( | bool | nodelay | ) |
Definition at line 319 of file SocketHandle.cc.
References FileHandle::FD().
Referenced by CPN::RemoteContextDaemon::Client::Client(), CPN::RemoteQueue::FileThreadEntryPoint(), and CPN::RemoteContext::RemoteContext().
Here is the call graph for this function:
Here is the caller graph for this function:| void SocketHandle::SetReceiveBufferSize | ( | int | size | ) |
Definition at line 252 of file SocketHandle.cc.
References FileHandle::FD().
Here is the call graph for this function:| void SocketHandle::SetReceiveTimeout | ( | double | timeout | ) |
Definition at line 283 of file SocketHandle.cc.
References FileHandle::FD().
Here is the call graph for this function:| void SocketHandle::SetSendBufferSize | ( | int | size | ) |
Definition at line 267 of file SocketHandle.cc.
References FileHandle::FD().
Here is the call graph for this function:| void SocketHandle::SetSendTimeout | ( | double | timeout | ) |
Definition at line 292 of file SocketHandle.cc.
References FileHandle::FD().
Here is the call graph for this function:| void SocketHandle::ShutdownRead | ( | ) |
Shutdown the read end of this socket. This does NOT close the socket! Any future attempt to read from this socket will fail.
Definition at line 107 of file SocketHandle.cc.
References FileHandle::FD().
Here is the call graph for this function:| void SocketHandle::ShutdownWrite | ( | ) |
Shutdown the write end of this socket. Any future attempt to write to this socket will fail. This is how you send an end of file down the socket.
Definition at line 113 of file SocketHandle.cc.
References FileHandle::FD().
Referenced by CPN::RemoteContext::EndWrite(), CPN::RemoteQueue::SendEndOfReadPacket(), and CPN::RemoteQueue::SendEndOfWritePacket().
Here is the call graph for this function:
Here is the caller graph for this function:
|
inherited |
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 FileHandle::fd, FileHandle::file_lock, and FileHandle::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 FileHandle::file_lock, and FileHandle::writeable.
Referenced by FileHandle::Poll().
Here is the caller graph for this function:
|
inlineinherited |
Gives the current writability status of the file.
Definition at line 102 of file FileHandle.h.
References FileHandle::file_lock, and FileHandle::writeable.
Referenced by FileHandle::OnWriteable(), Send(), WakeupHandle::WakeupHandle(), FileHandle::Write(), and FileHandle::Writev().
Here is the caller graph for this function:
|
inherited |
scatter gather io version of Write
Definition at line 261 of file FileHandle.cc.
References FileHandle::fd, FileHandle::file_lock, and FileHandle::Writeable().
Referenced by CPN::RemoteQueue::WriteBytes().
Here is the call graph for this function:
Here is the caller graph for this function:
|
protectedinherited |
Definition at line 217 of file FileHandle.h.
Referenced by FileHandle::Close(), FileHandle::Eof(), FileHandle::Good(), FileHandle::Read(), FileHandle::Readv(), Recv(), and FileHandle::Reset().
|
protectedinherited |
Definition at line 214 of file FileHandle.h.
Referenced by FileHandle::Close(), FileHandle::Closed(), FileHandle::FD(), FileHandle::Good(), FileHandle::Poll(), FileHandle::Read(), FileHandle::Readv(), Recv(), FileHandle::Reset(), Send(), FileHandle::Write(), FileHandle::Writev(), and FileHandle::~FileHandle().
|
mutableprotectedinherited |
Definition at line 213 of file FileHandle.h.
Referenced by FileHandle::Close(), FileHandle::Closed(), FileHandle::Eof(), FileHandle::FD(), FileHandle::Good(), FileHandle::Read(), FileHandle::Readable(), FileHandle::Readv(), Recv(), FileHandle::Reset(), Send(), WakeupHandle::SendWakeup(), FileHandle::Write(), FileHandle::Writeable(), and FileHandle::Writev().
|
protectedinherited |
Definition at line 215 of file FileHandle.h.
Referenced by FileHandle::Close(), FileHandle::Read(), FileHandle::Readable(), FileHandle::Readv(), Recv(), and FileHandle::Reset().
|
protectedinherited |
Definition at line 216 of file FileHandle.h.
Referenced by FileHandle::Close(), FileHandle::Reset(), and FileHandle::Writeable().
1.8.5