Back to index

nordugrid-arc-nox  1.1.0~rc6
Public Types | Public Member Functions | Static Public Member Functions | Protected Attributes | Private Attributes | Static Private Attributes
Hopi::PayloadBigFile Class Reference

#include <PayloadFile.h>

Inheritance diagram for Hopi::PayloadBigFile:
Inheritance graph
[legend]
Collaboration diagram for Hopi::PayloadBigFile:
Collaboration graph
[legend]

List of all members.

Public Types

typedef signed long long int Size_t

Public Member Functions

 PayloadBigFile (const char *filename, Size_t start, Size_t end)
 Creates object associated with file for reading from it.
virtual ~PayloadBigFile (void)
 Creates object associated with file for writing into it.
virtual Size_t Pos (void) const
 Returns current position in stream if supported.
virtual Size_t Size (void) const
 Returns size of underlying object if supported.
virtual Size_t Limit (void) const
 Returns position at which stream reading will stop if supported.
virtual bool Get (char *buf, int &size)
 Extracts information from stream up to 'size' bytes.
 operator bool (void)
 Returns true if stream is valid.
bool operator! (void)
 Returns true if stream is invalid.
virtual bool Get (std::string &buf)
 Read as many as possible (sane amount) of bytes into buf.
virtual std::string Get (void)
 Read as many as possible (sane amount) of bytes.
virtual bool Put (const char *buf, Size_t size)
 Push 'size' bytes from 'buf' into stream.
virtual bool Put (const std::string &buf)
 Push information from 'buf' into stream.
virtual bool Put (const char *buf)
 Push null terminated information from 'buf' into stream.
virtual int Timeout (void) const
 Query current timeout for Get() and Put() operations.
virtual void Timeout (int to)
 Set current timeout for Get() and Put() operations.

Static Public Member Functions

static Size_t Threshold (void)
static void Threshold (Size_t t)

Protected Attributes

int timeout_
int handle_
 Timeout for read/write operations.
bool seekable_
 Handle for operations.

Private Attributes

size_t limit_

Static Private Attributes

static Size_t threshold_ = 1024*1024*10

Detailed Description

Definition at line 43 of file PayloadFile.h.


Member Typedef Documentation

typedef signed long long int Arc::PayloadStreamInterface::Size_t [inherited]

Definition at line 18 of file PayloadStream.h.


Constructor & Destructor Documentation

Hopi::PayloadBigFile::PayloadBigFile ( const char *  filename,
Size_t  start,
Size_t  end 
)

Creates object associated with file for reading from it.

Definition at line 118 of file PayloadFile.cpp.

                                                                          :
                       PayloadStream(open_file_read(filename)) {
  seekable_ = false;
  if(handle_ == -1) return;
  ::lseek(handle_,start,SEEK_SET);
  limit_ = end;
}

Creates object associated with file for writing into it.

Use size=-1 for undefined size.

Definition at line 131 of file PayloadFile.cpp.

                                    {
  if(handle_ != -1) ::close(handle_);
}

Member Function Documentation

bool Hopi::PayloadBigFile::Get ( char *  buf,
int &  size 
) [virtual]

Extracts information from stream up to 'size' bytes.

'size' contains number of read bytes on exit. Returns true in case of success.

Reimplemented from Arc::PayloadStream.

Definition at line 153 of file PayloadFile.cpp.

                                            {
  if(handle_ == -1) return false;
  if(limit_ == (size_t)(-1)) return PayloadStream::Get(buf,size);
  Size_t cpos = Pos();
  if(cpos >= limit_) {
    size=0; return false;
  }
  if((cpos+size) > limit_) size=limit_-cpos;
  return PayloadStream::Get(buf,size);
}

Here is the call graph for this function:

bool Arc::PayloadStream::Get ( std::string &  buf) [virtual, inherited]

Read as many as possible (sane amount) of bytes into buf.

Implements Arc::PayloadStreamInterface.

Definition at line 67 of file PayloadStream.cpp.

                                      {
  char tbuf[1024];
  int l = sizeof(tbuf);
  bool result = Get(tbuf,l);
  buf.assign(tbuf,l);
  return result;
}

Here is the call graph for this function:

Here is the caller graph for this function:

virtual std::string Arc::PayloadStream::Get ( void  ) [inline, virtual, inherited]

Read as many as possible (sane amount) of bytes.

Implements Arc::PayloadStreamInterface.

Definition at line 71 of file PayloadStream.h.

{ std::string buf; Get(buf); return buf; };

Here is the call graph for this function:

Here is the caller graph for this function:

Returns position at which stream reading will stop if supported.

That may be not same as Size() if instance is meant to provide access to only part of underlying obejct.

Reimplemented from Arc::PayloadStream.

Definition at line 147 of file PayloadFile.cpp.

                                                       {
  Size_t s = Size();
  if((limit_ == (size_t)(-1)) || (limit_ > s)) return s;
  return limit_;
}

Here is the call graph for this function:

Hopi::PayloadBigFile::operator bool ( void  ) [inline, virtual]

Returns true if stream is valid.

Reimplemented from Arc::PayloadStream.

Definition at line 59 of file PayloadFile.h.

{ return (handle_ != -1); };
bool Hopi::PayloadBigFile::operator! ( void  ) [inline, virtual]

Returns true if stream is invalid.

Reimplemented from Arc::PayloadStream.

Definition at line 60 of file PayloadFile.h.

{ return (handle_ == -1); };

Returns current position in stream if supported.

Reimplemented from Arc::PayloadStream.

Definition at line 135 of file PayloadFile.cpp.

                                                     {
  if(handle_ == -1) return 0;
  return ::lseek(handle_,0,SEEK_CUR);
}

Here is the caller graph for this function:

bool Arc::PayloadStream::Put ( const char *  buf,
Size_t  size 
) [virtual, inherited]

Push 'size' bytes from 'buf' into stream.

Returns true on success.

Implements Arc::PayloadStreamInterface.

Definition at line 75 of file PayloadStream.cpp.

                                                   {
  ssize_t l;
  if(handle_ == -1) return false;
  time_t start = time(NULL);
  for(;size;) {
#ifndef WIN32
    struct pollfd fd;
    fd.fd=handle_; fd.events=POLLOUT | POLLERR; fd.revents=0;
    int to = timeout_-(unsigned int)(time(NULL)-start);
    if(to < 0) to=0;
    if(poll(&fd,1,to*1000) != 1) return false;
    if(!(fd.revents & POLLOUT)) return false;
#endif
    l=::write(handle_,buf,size);
    if(l == -1) {
           return false;
    }
    buf+=l; size-=l;
#ifdef WIN32
    int to = timeout_-(unsigned int)(time(NULL)-start);
    if(to < 0) return false;
#endif
  };  
  return true;
}

Here is the caller graph for this function:

virtual bool Arc::PayloadStream::Put ( const std::string &  buf) [inline, virtual, inherited]

Push information from 'buf' into stream.

Returns true on success.

Implements Arc::PayloadStreamInterface.

Definition at line 73 of file PayloadStream.h.

{ return Put(buf.c_str(),buf.length()); };

Here is the call graph for this function:

Here is the caller graph for this function:

virtual bool Arc::PayloadStream::Put ( const char *  buf) [inline, virtual, inherited]

Push null terminated information from 'buf' into stream.

Returns true on success.

Implements Arc::PayloadStreamInterface.

Definition at line 74 of file PayloadStream.h.

{ return Put(buf,buf?strlen(buf):0); };

Here is the call graph for this function:

Here is the caller graph for this function:

Returns size of underlying object if supported.

Reimplemented from Arc::PayloadStream.

Definition at line 140 of file PayloadFile.cpp.

                                                      {
  if(handle_ == -1) return 0;
  struct stat st;
  if(fstat(handle_,&st) != 0) return 0;
  return st.st_size;
}

Here is the caller graph for this function:

static Size_t Hopi::PayloadBigFile::Threshold ( void  ) [inline, static]

Definition at line 61 of file PayloadFile.h.

{ return threshold_; };

Here is the caller graph for this function:

static void Hopi::PayloadBigFile::Threshold ( Size_t  t) [inline, static]

Definition at line 62 of file PayloadFile.h.

{ if(t > 0) threshold_=t; };
virtual int Arc::PayloadStream::Timeout ( void  ) const [inline, virtual, inherited]

Query current timeout for Get() and Put() operations.

Implements Arc::PayloadStreamInterface.

Definition at line 77 of file PayloadStream.h.

{ return timeout_; };
virtual void Arc::PayloadStream::Timeout ( int  to) [inline, virtual, inherited]

Set current timeout for Get() and Put() operations.

Implements Arc::PayloadStreamInterface.

Definition at line 78 of file PayloadStream.h.

{ timeout_=to; };

Member Data Documentation

int Arc::PayloadStream::handle_ [protected, inherited]

Timeout for read/write operations.

Definition at line 61 of file PayloadStream.h.

size_t Hopi::PayloadBigFile::limit_ [private]

Definition at line 46 of file PayloadFile.h.

bool Arc::PayloadStream::seekable_ [protected, inherited]

Handle for operations.

Definition at line 62 of file PayloadStream.h.

PayloadBigFile::Size_t Hopi::PayloadBigFile::threshold_ = 1024*1024*10 [static, private]

Definition at line 45 of file PayloadFile.h.

int Arc::PayloadStream::timeout_ [protected, inherited]

Definition at line 60 of file PayloadStream.h.


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