CPN
Computational Process Networks
Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | Private Member Functions | Private Attributes | List of all members
WakeupHandle Class Reference

A convenience handle for event loops so that one can interrupt a Poll before it times out. More...

#include <WakeupHandle.h>

+ Inheritance diagram for WakeupHandle:
+ Collaboration diagram for WakeupHandle:

Public Types

typedef AutoLock< PthreadMutexALock
 

Public Member Functions

 WakeupHandle ()
 
virtual ~WakeupHandle ()
 
void SendWakeup ()
 Causes this handler to become readable any Poll on this FileHandler will then return. More...
 
void Read ()
 Read until not readable anymore. 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 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

void OnReadable ()
 Called by Poll when it detects that the file is readable. More...
 

Private Attributes

int wfd
 

Detailed Description

A convenience handle for event loops so that one can interrupt a Poll before it times out.

SendWakeup my be called from any thread.

Definition at line 35 of file WakeupHandle.h.

Member Typedef Documentation

Definition at line 43 of file FileHandle.h.

Constructor & Destructor Documentation

WakeupHandle::WakeupHandle ( )

Definition at line 30 of file WakeupHandle.cc.

References FileHandle::FD(), FileHandle::Readable(), FileHandle::SetBlocking(), wfd, and FileHandle::Writeable().

31  : wfd(-1)
32 {
33  int filedes[2];
34  if (pipe(filedes) != 0) {
35  throw ErrnoException();
36  }
37  FD(filedes[0]);
38  wfd = filedes[1];
39  Readable(false);
40  Writeable(false);
41  SetBlocking(false);
42  SetBlocking(wfd, false);
43 }
void SetBlocking(bool blocking)
Manipulate how the current file handles blocking.
Definition: FileHandle.cc:111
bool Writeable() const
Gives the current writability status of the file.
Definition: FileHandle.h:102
int FD() const
Definition: FileHandle.h:106
bool Readable() const
Gives the current readability status of the file.
Definition: FileHandle.h:91

+ Here is the call graph for this function:

WakeupHandle::~WakeupHandle ( )
virtual

Definition at line 45 of file WakeupHandle.cc.

References wfd.

45  {
46  close(wfd);
47  wfd = -1;
48 }

Member Function Documentation

void FileHandle::Close ( )
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().

146  {
147  ALock al(file_lock);
148  if (fd != -1) {
149  if (close(fd) != 0) {
150  throw ErrnoException();
151  }
152  fd = -1;
153  }
154  readable = false;
155  writeable = false;
156  eof = false;
157 }
bool writeable
Definition: FileHandle.h:216
PthreadMutex file_lock
Definition: FileHandle.h:213
AutoLock< PthreadMutex > ALock
Definition: FileHandle.h:43
bool readable
Definition: FileHandle.h:215

+ Here is the caller graph for this function:

bool FileHandle::Closed ( ) const
inlineinherited
bool FileHandle::Eof ( ) const
inlineinherited
Returns
the current end of file condition

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().

115 { ALock al(file_lock); return eof; }
PthreadMutex file_lock
Definition: FileHandle.h:213
AutoLock< PthreadMutex > ALock
Definition: FileHandle.h:43

+ Here is the caller graph for this function:

bool FileHandle::Eof ( bool  e)
inlineinherited

Set/reset the end of file condition.

Parameters
ethe new end of file condition
Returns
the new end of file condition

Definition at line 120 of file FileHandle.h.

References FileHandle::eof, and FileHandle::file_lock.

120 { ALock al(file_lock); return eof = e; }
PthreadMutex file_lock
Definition: FileHandle.h:213
AutoLock< PthreadMutex > ALock
Definition: FileHandle.h:43
int FileHandle::FD ( ) const
inlineinherited
int FileHandle::FD ( int  filed)
inlineinherited

Set the current file descriptor.

Parameters
filedthe new file descriptor
Returns
the new file descriptor

Definition at line 111 of file FileHandle.h.

References FileHandle::fd, and FileHandle::file_lock.

111 { ALock al(file_lock); return fd = filed; }
PthreadMutex file_lock
Definition: FileHandle.h:213
AutoLock< PthreadMutex > ALock
Definition: FileHandle.h:43
void FileHandle::Flush ( )
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().

293  {
294  if (fsync(FD()) != 0) {
295  throw ErrnoException();
296  }
297 }
int FD() const
Definition: FileHandle.h:106

+ Here is the call graph for this function:

bool FileHandle::Good ( ) const
inlineinherited

Convenience method for testing if the file this FileHandle has is open and not at end of file.

Returns
true if open and not at end of file otherwise false

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().

125 { ALock al(file_lock); return !(eof || fd == -1); }
PthreadMutex file_lock
Definition: FileHandle.h:213
AutoLock< PthreadMutex > ALock
Definition: FileHandle.h:43

+ Here is the caller graph for this function:

bool FileHandle::IsBlocking ( ) const
inherited

Test if the current file is in blocking or non blocking mode.

Returns
true if blocking or false if non blocking

Definition at line 128 of file FileHandle.cc.

References FileHandle::FD().

128  {
129  return IsBlocking(FD());
130 }
bool IsBlocking() const
Test if the current file is in blocking or non blocking mode.
Definition: FileHandle.cc:128
int FD() const
Definition: FileHandle.h:106

+ Here is the call graph for this function:

bool FileHandle::IsBlocking ( int  fd)
staticinherited

Test the given file descriptor if it is in blocking mode.

Parameters
fdthe file descriptor to test
Returns
true if blocking or false if non blocking

Definition at line 132 of file FileHandle.cc.

132  {
133  int flags = fcntl(fd, F_GETFL, 0);
134  if (-1 == flags) { throw ErrnoException(); }
135  return !(flags & O_NONBLOCK);
136 }
void WakeupHandle::OnReadable ( )
inlineprivatevirtual

Called by Poll when it detects that the file is readable.

Reimplemented from FileHandle.

Definition at line 50 of file WakeupHandle.h.

50 {}
virtual void FileHandle::OnWriteable ( )
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().

212 { Writeable(true); }
bool Writeable() const
Gives the current writability status of the file.
Definition: FileHandle.h:102

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

int FileHandle::Poll ( IteratorRef< FileHandle * >  begin,
IteratorRef< FileHandle * >  end,
double  timeout 
)
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().

34  {
35  fd_set rfd;
36  fd_set wfd;
37  FD_ZERO(&rfd);
38  FD_ZERO(&wfd);
39  int maxfd = 0;
40  IteratorRef<FileHandle*> itr = begin;
41  while (itr != end) {
42  FileHandle *han = *itr;
43  int fd = han->FD();
44  if (fd < 0) {
45  return -1;
46  } else {
47  bool set = false;
48  if (!han->Readable()) {
49  FD_SET(fd, &rfd);
50  set = true;
51  }
52  if (!han->Writeable()) {
53  FD_SET(fd, &wfd);
54  set = true;
55  }
56  if (set) { maxfd = std::max(maxfd, fd); }
57  }
58  ++itr;
59  }
60  timeval tv;
61  timeval *ptv = 0;
62  if (timeout >= 0) {
63  tv.tv_sec = (int)timeout;
64  tv.tv_usec = (int)((timeout - tv.tv_sec) * 1e6);
65  ptv = &tv;
66  }
67  int ret = select(maxfd + 1, &rfd, &wfd, 0, ptv);
68  if (ret < 0) {
69  if (errno == EINTR) {
70  return 0;
71  }
72  throw ErrnoException();
73  }
74  itr = begin;
75  while (itr != end) {
76  FileHandle *han = *itr;
77  int fd = han->FD();
78  if (fd >= 0) {
79  if (FD_ISSET(fd, &rfd)) {
80  han->OnReadable();
81  }
82  if (FD_ISSET(fd, &wfd)) {
83  han->OnWriteable();
84  }
85  }
86  ++itr;
87  }
88  return ret;
89 }
virtual void OnWriteable()
Called by Poll when it detects that the file is writeable.
Definition: FileHandle.h:212
bool Writeable(bool w)
Set that this file is currently writeable or not.
Definition: FileHandle.h:97
A reference to an iterator.
Definition: IteratorRef.h:46
int FD() const
Definition: FileHandle.h:106
bool Readable(bool r)
Set that the file is currently readable or not.
Definition: FileHandle.h:86
Generic file handle could be a file, or a socket or a device.
Definition: FileHandle.h:41
virtual void OnReadable()
Called by Poll when it detects that the file is readable.
Definition: FileHandle.h:210

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

int FileHandle::Poll ( double  timeout)
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.

Parameters
timeout-1 to wait forever for activity 0 to poll and return immediately or a time to wait in seconds.
Returns
zero if timed out, positive if an event occurred or negative if an error occurred.

Definition at line 106 of file FileHandle.cc.

References FileHandle::Poll().

106  {
107  FileHandle *fh = this;
108  return Poll(&fh, &fh + 1, timeout);
109 }
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.
Definition: FileHandle.cc:34
Generic file handle could be a file, or a socket or a device.
Definition: FileHandle.h:41

+ Here is the call graph for this function:

void WakeupHandle::Read ( )

Read until not readable anymore.

Definition at line 70 of file WakeupHandle.cc.

References FileHandle::Read().

Referenced by CPN::ConnectionServer::Poll().

70  {
71  char c[256];
72  unsigned ret = 0;
73  // If we didn't read all the buffer there isn't more to read
74  do {
75  ret = FileHandle::Read(c, sizeof(c));
76  } while (ret == sizeof(c));
77 }
unsigned Read(void *ptr, unsigned len)
Read data from the file descriptor.
Definition: FileHandle.cc:159

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

unsigned FileHandle::Read ( void *  ptr,
unsigned  len 
)
inherited

Read data from the file descriptor.

Will set the end of file condition if read detects end of file.

Note
All the read functions will set readable to false if they read less than the requested amount or we are non blocking and a would block condition happened.
Parameters
ptrpointer to write data to
lenthe maximum number of bytes to write to ptr
Returns
0 if no bytes read (check Eof) or the number of bytes read

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 Read().

159  {
160  int filed;
161  {
162  ALock al(file_lock);
163  if (eof || fd == -1) { return 0; }
164  filed = fd;
165  }
166  unsigned bytesread = 0;
167  int num = read(filed, ptr, len);
168  if (num < 0) {
169  int error = errno;
170  switch (error) {
171  case EAGAIN:
172  Readable(false);
173  case EINTR:
174  case ENOMEM:
175  break;
176  default:
177  throw ErrnoException(error);
178  }
179  } else if (num == 0 && len != 0) {
180  ALock al(file_lock);
181  eof = true;
182  readable = false;
183  } else {
184  if (unsigned(num) < len) { Readable(false); }
185  bytesread = num;
186  }
187  return bytesread;
188 }
PthreadMutex file_lock
Definition: FileHandle.h:213
AutoLock< PthreadMutex > ALock
Definition: FileHandle.h:43
bool readable
Definition: FileHandle.h:215
bool Readable() const
Gives the current readability status of the file.
Definition: FileHandle.h:91

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool FileHandle::Readable ( bool  r)
inlineinherited

Set that the file is currently readable or not.

Parameters
rtrue or false
Returns
the new readable status

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().

86 { ALock al(file_lock); return readable = r; }
PthreadMutex file_lock
Definition: FileHandle.h:213
AutoLock< PthreadMutex > ALock
Definition: FileHandle.h:43
bool readable
Definition: FileHandle.h:215

+ Here is the caller graph for this function:

bool FileHandle::Readable ( ) const
inlineinherited

Gives the current readability status of the file.

Returns
true if it is known that a read will not block

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(), SocketHandle::Recv(), CPN::RemoteContextDaemon::Run(), and WakeupHandle().

91 { ALock al(file_lock); return readable; }
PthreadMutex file_lock
Definition: FileHandle.h:213
AutoLock< PthreadMutex > ALock
Definition: FileHandle.h:43
bool readable
Definition: FileHandle.h:215

+ Here is the caller graph for this function:

unsigned FileHandle::Readv ( const iovec *  iov,
int  iovcnt 
)
inherited

scatter gather io version of Read

Returns
see 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().

190  {
191  int filed;
192  {
193  ALock al(file_lock);
194  if (eof || fd == -1) { return 0; }
195  filed = fd;
196  }
197  unsigned len = 0;
198  for (int i = 0; i < iovcnt; ++i) {
199  len += iov[i].iov_len;
200  }
201  unsigned bytesread = 0;
202  int num = readv(filed, iov, iovcnt);
203  if (num < 0) {
204  int error = errno;
205  switch (error) {
206  case EAGAIN:
207  Readable(false);
208  case EINTR:
209  case ENOMEM:
210  break;
211  default:
212  throw ErrnoException(error);
213  }
214  } else if (num == 0 && len != 0) {
215  ALock al(file_lock);
216  eof = true;
217  readable = false;
218  } else {
219  if (unsigned(num) < len) { Readable(false); }
220  bytesread = num;
221  }
222  return bytesread;
223 }
PthreadMutex file_lock
Definition: FileHandle.h:213
AutoLock< PthreadMutex > ALock
Definition: FileHandle.h:43
bool readable
Definition: FileHandle.h:215
bool Readable() const
Gives the current readability status of the file.
Definition: FileHandle.h:91

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void FileHandle::Reset ( )
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().

138  {
139  ALock al(file_lock);
140  readable = false;
141  writeable = false;
142  eof = false;
143  fd = -1;
144 }
bool writeable
Definition: FileHandle.h:216
PthreadMutex file_lock
Definition: FileHandle.h:213
AutoLock< PthreadMutex > ALock
Definition: FileHandle.h:43
bool readable
Definition: FileHandle.h:215

+ Here is the caller graph for this function:

void WakeupHandle::SendWakeup ( )

Causes this handler to become readable any Poll on this FileHandler will then return.

Definition at line 50 of file WakeupHandle.cc.

References FileHandle::file_lock, and wfd.

Referenced by CPN::RemoteQueueHolder::Shutdown().

50  {
51  int wfiled;
52  {
54  wfiled = wfd;
55  }
56  char c = 0;
57  int ret = 0;
58  do {
59  ret = write(wfiled, &c, sizeof(c));
60  if (ret < 0) {
61  if (errno == EAGAIN) {
62  // The buffer is full.
63  break;
64  }
65  throw ErrnoException();
66  }
67  } while (ret != sizeof(c));
68 }
PthreadMutex file_lock
Definition: FileHandle.h:213

+ Here is the caller graph for this function:

void FileHandle::SetBlocking ( bool  blocking)
inherited

Manipulate how the current file handles blocking.

Parameters
blockingtrue 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().

111  {
112  SetBlocking(FD(), blocking);
113 }
void SetBlocking(bool blocking)
Manipulate how the current file handles blocking.
Definition: FileHandle.cc:111
int FD() const
Definition: FileHandle.h:106

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void FileHandle::SetBlocking ( int  fd,
bool  blocking 
)
staticinherited

a convenience method that allows one to set the same blocking parameters for a file descriptor without setting it inside a FileHandle.

Parameters
fdthe file descriptor
blockingtrue or false see SetBlock

Definition at line 115 of file FileHandle.cc.

115  {
116  int flags = fcntl(fd, F_GETFL, 0);
117  if (-1 == flags) { throw ErrnoException(); }
118  if (blocking) {
119  flags &= ~O_NONBLOCK;
120  } else {
121  flags |= O_NONBLOCK;
122  }
123  if (fcntl(fd, F_SETFL, flags) != 0) {
124  throw ErrnoException();
125  }
126 }
unsigned FileHandle::Write ( const void *  ptr,
unsigned  len 
)
inherited

Write data to the file descriptor.

Note
All write functions will set Writeable to false if they write less than the amount requested or if the file is in non blocking mode and the write returned would block.
Parameters
ptrpointer to beginning of data to write
lenlength of data to write
Returns
number of bytes written

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().

225  {
226  int filed;
227  {
228  ALock al(file_lock);
229  if (fd == -1) { return 0; }
230  filed = fd;
231  }
232  unsigned written = 0;
233  int num = write(filed, ptr, len);
234  if (num < 0) {
235  int error = errno;
236  switch (error) {
237  case EAGAIN: // Would block
238  //case EWOULDBLOCK:
239  Writeable(false);
240  case EINTR: // Returned because of signal
241  case ENOMEM:
242  case ENOBUFS: // Buffers are full
243  break;
244  case EPIPE:
245  case EBADF:
246  case EFAULT:
247  case EFBIG:
248  case EINVAL:
249  case EIO:
250  case ENOSPC:
251  default:
252  throw ErrnoException(error);
253  }
254  } else {
255  if (unsigned(num) < len) { Writeable(false); }
256  written = num;
257  }
258  return written;
259 }
PthreadMutex file_lock
Definition: FileHandle.h:213
AutoLock< PthreadMutex > ALock
Definition: FileHandle.h:43
bool Writeable() const
Gives the current writability status of the file.
Definition: FileHandle.h:102

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool FileHandle::Writeable ( bool  w)
inlineinherited

Set that this file is currently writeable or not.

Parameters
wtrue or false
Returns
the new writeable status

Definition at line 97 of file FileHandle.h.

References FileHandle::file_lock, and FileHandle::writeable.

Referenced by FileHandle::Poll().

97 { ALock al(file_lock); return writeable = w; }
bool writeable
Definition: FileHandle.h:216
PthreadMutex file_lock
Definition: FileHandle.h:213
AutoLock< PthreadMutex > ALock
Definition: FileHandle.h:43

+ Here is the caller graph for this function:

bool FileHandle::Writeable ( ) const
inlineinherited

Gives the current writability status of the file.

Returns
true if it is known that a write will not block

Definition at line 102 of file FileHandle.h.

References FileHandle::file_lock, and FileHandle::writeable.

Referenced by FileHandle::OnWriteable(), SocketHandle::Send(), WakeupHandle(), FileHandle::Write(), and FileHandle::Writev().

102 { ALock al(file_lock); return writeable; }
bool writeable
Definition: FileHandle.h:216
PthreadMutex file_lock
Definition: FileHandle.h:213
AutoLock< PthreadMutex > ALock
Definition: FileHandle.h:43

+ Here is the caller graph for this function:

unsigned FileHandle::Writev ( const iovec *  iov,
int  iovcnt 
)
inherited

scatter gather io version of Write

Returns
see Write

Definition at line 261 of file FileHandle.cc.

References FileHandle::fd, FileHandle::file_lock, and FileHandle::Writeable().

Referenced by CPN::RemoteQueue::WriteBytes().

261  {
262  int filed;
263  {
264  ALock al(file_lock);
265  if (fd == -1) { return 0; }
266  filed = fd;
267  }
268  unsigned written = 0;
269  int num = writev(filed, iov, iovcnt);
270  if (num < 0) {
271  int error = errno;
272  switch (error) {
273  case EAGAIN:
274  Writeable(false);
275  case EINTR:
276  case ENOMEM:
277  case ENOBUFS:
278  break;
279  default:
280  throw ErrnoException(error);
281  }
282  } else {
283  unsigned len = 0;
284  for (int i = 0; i < iovcnt; ++i) {
285  len += iov[i].iov_len;
286  }
287  if (unsigned(num) < len) { Writeable(false); }
288  written = num;
289  }
290  return written;
291 }
PthreadMutex file_lock
Definition: FileHandle.h:213
AutoLock< PthreadMutex > ALock
Definition: FileHandle.h:43
bool Writeable() const
Gives the current writability status of the file.
Definition: FileHandle.h:102

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Member Data Documentation

bool FileHandle::eof
protectedinherited
int FileHandle::fd
protectedinherited
PthreadMutex FileHandle::file_lock
mutableprotectedinherited
bool FileHandle::readable
protectedinherited
int WakeupHandle::wfd
private

Definition at line 51 of file WakeupHandle.h.

Referenced by SendWakeup(), WakeupHandle(), and ~WakeupHandle().

bool FileHandle::writeable
protectedinherited

Definition at line 216 of file FileHandle.h.

Referenced by FileHandle::Close(), FileHandle::Reset(), and FileHandle::Writeable().


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